To get the perfect coordinate system with pixels, you can set up your matrices as follows:
glViewport(0, window_width, 0, window_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, window_width, 0, window_height, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
OpenGL 1:1 .
, , -, . , OpenGL ES , ( ), , Android , 512 x 128, .
, OpenGL 0 1, . , 48 , 64 x 64, x 0 0,75:
1 +--------+
| |
| |
+-----+ |
|\_O_/| |
| O | |
| / \ | |
0 +-----+--+
0 0.75 1 <- texture coordinates
0 48 64 <- pixels
, . , 48 .
, x, y ( ), - :
float texcoord_x = (float)sprite_width / texture_width;
float texcoord_y = (float)sprite_height / texture_height;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture_id);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(x, y);
glTexCoord2f(texcoord_x, 0);
glVertex2i(x + sprite_width, y);
glTexCoord2f(texcoord_x, texcoord_y);
glVertex2i(x + sprite_width, y + sprite_height);
glTexCoord2f(0, texcoord_y);
glVertex2i(x, y + sprite_height);
glEnd();
, OpenGL ES glVertex2i .., . , . .