Hi guys, I asked this question in the beginner forum some days ago, but I did’nt get any answer, and I’m a bit puzzled. Hope you can help me.
I’m trying to learn how to use vertex arrays, but I must have some error, or there must be something I’m not understanding, because for some reason my little test app is not working as expected.
Just trying to draw one textured triangle using vertex arrays. If I call glBindTexture() before calling glDrawArrays() or glDrawElements() no texture is shown, but if I omit the texture binding everything works ‘right’. Tell me if you see the problem in this implementation:
float vertices = { -10.0f, -10.0f, 0.0f, -10.0f, 10.0f, 0.0f, 10.0f, 10.0f, 0.0f };
float colors = { 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
float texcoords = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f };
int indices = { 0, 1, 2 };
in my init function:
textureID = LoadJPG( “cool.JPG” );
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glColorPointer(3, GL_FLOAT, 0, colors);
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
then in my Draw function:
//glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices);
glBindTexture(GL_TEXTURE_2D, textureID);
glDrawArrays (GL_TRIANGLES, 0, 3);
…and the polygon renders non textured. I’ve tried alternative methods with Vertex arrays but they always fail, so I think I’m not understanding how this really works.
Thank you.
[This message has been edited by Anonymous Coward (edited 05-06-2003).]
[This message has been edited by Anonymous Coward (edited 05-06-2003).]