OpenGL矩阵在iPhone和模拟器上的工作方式不同吗?
我正在做一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
呜呜……我发帖后,我自己找到了答案……
抱歉打扰...原因是关键字:
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