views:

330

answers:

1

I'm writing a 2D game in Opengl. I already set up the orthogonal projection so I can easily know where a quad will end up on screen. The problem is, I also want to be able to map pixels directly to texture coords, so I also applied an orthogonal transformation (using gluOrtho2d) to the texture. Now I can map pixels directly using integers and glTexCoord2i. The thing is, after googling/reading/asking, I found out no one really knows (apparently) the behavior of glTexCoord2i, but it works just fine the way I'm using. Some sample test code I wrote follows:

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'm doing, or is what I'm doing correct?

+3  A: 

There's nothing special about glTexCoord*i, it's just one variant of glTexCoord that takes integer arguments for convenience, the values will be transformed by the texture transform in the same way as all other tex coords.

If you want to express your texture coordinates in pixels your code looks totally ok.

EDIT: If you want to take your OpenGL coding to the "next level", you should consider dropping the immediate mode rendering (glBegin/glEnd) and instead build vertex buffers and draw them with glDrawArrays, this is way faster.

Andreas Brinck
Oh thanks! I know about vertex buffers, but at this early stage of the code I'm using this just for testing. =)
knuck