Orthographic coordinates and textures in opengl
I am writing a 2D game in Opengl. I've already set up orthographic projection, so I can easily find out where the square will end up on the screen. The problem is that I also want to be able to map pixels directly to texture coordinates, so I also applied an orthogonal transform (using gluOrtho2d) to the texture. Now I can map pixels directly using integers and glTexCoord2i. The thing is, after googling / reading / ask, I found out that no one knows (apparently) the behavior of glTexCoord2i, but it works fine as I use. Below is an example of the test code I wrote:
glBegin(GL_QUADS); glTexCoord2i(16,0); glVertex2f(X, Y); glTexCoord2i(16,16); glVertex2f(X, Y+32); glTexCoord2i(32, 16); glVertex2f(X+32, Y+32); glTexCoord2i(32, 0); glVertex2f(X+32, Y); glEnd();
So, is there any problem with what I am doing, or what am I doing right?
a source to share
There is nothing special about glTexCoord*i
this, this is just one option glTexCoord
, which takes integer arguments for convenience, the values will be transformed by transforming the texture in the same way as all other tex coordinates.
If you want to express your texture coordinates in pixels, your code looks complete.
EDIT: If you want to take your OpenGL encoding to the "next level" you should give up on immediate mode rendering ( glBegin
/ glEnd
) and instead create vertex buffers and draw them with glDrawArrays
, it will be faster.
a source to share