OpenGL矩阵在iPh​​one和模拟器上的工作方式不同吗?

发布于 2024-10-31 10:57:05 字数 1737 浏览 9 评论 0原文

我正在做一个简单的 2d 游戏,使用 opengl 正交视图,以三角形作为精灵。

问题是,完全相同的游戏代码在我的 Mac 模拟器上运行得很好,但是当我在手机上启动游戏时,事情就出了问题。 当我追查问题时,我发现我不明白。

我已经简化了代码以对不同行为进行硬证明,代码如下所示:

// Setup projection matrix as identity
GLfixed projectionMatrix[16];
projectionMatrix[0] = 65536;//1.0f;
projectionMatrix[1] = 0;
projectionMatrix[2] = 0;
projectionMatrix[3] = 0;

projectionMatrix[4] = 0;
projectionMatrix[5] = 65536;//1.0f;
projectionMatrix[6] = 0;
projectionMatrix[7] = 0;

projectionMatrix[8] = 0;
projectionMatrix[9] = 0;
projectionMatrix[10] = 65536;//1.0f;
projectionMatrix[11] = 0;

projectionMatrix[12] = 0;
projectionMatrix[13] = 0;
projectionMatrix[14] = 0;
projectionMatrix[15] = 65536;//1.0f;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glLoadMatrixx( projectionMatrix );


// Setup modelview matrix
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();

// And here I printout the content of the matricies
GLfixed m[4][4];
glGetFixedv(GL_MODELVIEW, &(m[0][0]));
// … Print matrix
glGetFixedv(GL_PROJECTION, &(m[0][0]));
// … Print matrix

The printed values on my mac using simulator (feels right):
 ==== MODEL
 [65536][0][0][0]
 [0][65536][0][0]
 [0][0][65536][0]
 [0][0][0][65536]
 ==== PROJECTION
 [65536][0][0][0]
 [0][65536][0][0]
 [0][0][65536][0]
 [0][0][0][65536]

And printed values on my ipod (wtf?):
 ==== MODEL
 [-1490935922][1236752][20995][803202364]
 [1][1032192][1245312][803202404]
 [879947476][3][92][803202728]
 [1][10558464][803202404][808970200]
 ==== PROJECTION
 [-1490935922][1236752][20995][803202364]
 [1][1032192][1245312][803202404]
 [879947476][3][92][803202728]
 [1][10558464][803202404][808970200]

我猜也许 smth 在 gl 中的初始化不同?但如何弄清楚什么? 也许有人知道在哪里寻找答案? 与固定与浮动有关吗?

I'm doing a simple 2d game, with using opengl ortho view, with triangles as a sprites.

The problem is, that absolutely the same game code works perfect on my mac simulator, but when I launch the game on the phone things goes wrong.
When I trace the problem, I found smth that I don't understand.

I have simplified the code to have a hard proof of different behaviour, and the code looks like:

// Setup projection matrix as identity
GLfixed projectionMatrix[16];
projectionMatrix[0] = 65536;//1.0f;
projectionMatrix[1] = 0;
projectionMatrix[2] = 0;
projectionMatrix[3] = 0;

projectionMatrix[4] = 0;
projectionMatrix[5] = 65536;//1.0f;
projectionMatrix[6] = 0;
projectionMatrix[7] = 0;

projectionMatrix[8] = 0;
projectionMatrix[9] = 0;
projectionMatrix[10] = 65536;//1.0f;
projectionMatrix[11] = 0;

projectionMatrix[12] = 0;
projectionMatrix[13] = 0;
projectionMatrix[14] = 0;
projectionMatrix[15] = 65536;//1.0f;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glLoadMatrixx( projectionMatrix );


// Setup modelview matrix
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();

// And here I printout the content of the matricies
GLfixed m[4][4];
glGetFixedv(GL_MODELVIEW, &(m[0][0]));
// … Print matrix
glGetFixedv(GL_PROJECTION, &(m[0][0]));
// … Print matrix

The printed values on my mac using simulator (feels right):
 ==== MODEL
 [65536][0][0][0]
 [0][65536][0][0]
 [0][0][65536][0]
 [0][0][0][65536]
 ==== PROJECTION
 [65536][0][0][0]
 [0][65536][0][0]
 [0][0][65536][0]
 [0][0][0][65536]

And printed values on my ipod (wtf?):
 ==== MODEL
 [-1490935922][1236752][20995][803202364]
 [1][1032192][1245312][803202404]
 [879947476][3][92][803202728]
 [1][10558464][803202404][808970200]
 ==== PROJECTION
 [-1490935922][1236752][20995][803202364]
 [1][1032192][1245312][803202404]
 [879947476][3][92][803202728]
 [1][10558464][803202404][808970200]

I guess maybe smth is differently initialized in gl? But how to figure out what?
Maybe someone has any clue where to search for an answer?
Is something related to fixed vs float ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2024-11-07 10:57:05

呜呜……我发帖后,我自己找到了答案……
抱歉打扰...原因是关键字:
GL_MODELVIEW 和 GL_MODELVIEW_MATRIX
我应该使用:
glMatrixMode( GL_MODELVIEW );

glGetFixedv( GL_MODELVIEW_MATRIX, &(m[0][0]) );

o(^_^)o

Wooohoo... Right after I posted, I found the answer myself...
Sorry for bothering... The reason was in keywords:
GL_MODELVIEW and GL_MODELVIEW_MATRIX
I should use:
glMatrixMode( GL_MODELVIEW );
and
glGetFixedv( GL_MODELVIEW_MATRIX, &(m[0][0]) );

o(^_^)o

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文