开发者

OpenGL matrix works differently on iphone and on simulator?

开发者 https://www.devze.com 2023-02-23 09:00 出处:网络
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 gam

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;
projectionMat开发者_Go百科rix[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 ?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消