Hello, 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:
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.
Thank you.