2

I'm drawing my points like that :

TAB_PAS = 2;

glVertexPointer(TAB_PAS,GL_FLOAT,0,test[0].send_terrain());
glDrawElements( GL_LINES, indice_degra_de.size(), GL_UNSIGNED_INT, indice_degra_de.constData());
glVertexPointer(TAB_PAS,GL_FLOAT,0,test[1].send_terrain());
glDrawElements( GL_LINES, indice_degra.size(), GL_UNSIGNED_INT, indice_degra.constData());
glVertexPointer(TAB_PAS,GL_FLOAT,0,test[2].send_terrain());
glDrawElements( GL_LINES, indice_degra_de.size(), GL_UNSIGNED_INT, indice_degra_de.constData());
glVertexPointer(TAB_PAS,GL_FLOAT,0,test[3].send_terrain());

It draws a big terrain.

So now, I want for exemple applique a floor texture. I saw a function glTexCoordPointer but I don't know how to use it:

glTexCoordPointer(2, GL_FLOAT, 0, test[0].send_terrain()); 
// Something like that ?

I already uploaded my picture.tga, so now the problem is to applique it.

1 Answers1

0

You use glTextCoordPointer in the same way as glVertexPointer :

glVertexPointer(TAB_PAS, GL_FLOAT, 0, test[0].send_terrain());
glTexCoordPointer(2, GL_FLOAT, 0, test[0].send_texCoords());
glDrawElements(GL_LINES, indice_degra_de.size(), GL_UNSIGNED_INT, indice_degra_de.constData());

You need to specify the texture coordinates in another array, where every pair of texture coordinates correspond to one vertex in your terrain data.

To have OpenGL actually use your Texture Coordinates:

glEnableClientState(GL_TEXTURE_COORD_ARRAY); // Before calling DrawElements

And of course you must have the texture bound and enabled. Complete example, assuming you generate texture coordinates and have your .tga texture uploaded to OpenGL:

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureHandle);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(TAB_PAS,GL_FLOAT,0,test[0].send_terrain());
glTexCoordPointer(2, GL_FLOAT, 0, text[0].send_texCoord());
glDrawElements( GL_LINES, indice_degra_de.size(), GL_UNSIGNED_INT, indice_degra_de.constData());

glVertexPointer(TAB_PAS,GL_FLOAT,0,test[1].send_terrain());
glTexCoordPointer(2, GL_FLOAT, 0, text[1].send_texCoord());
glDrawElements( GL_LINES, indice_degra.size(), GL_UNSIGNED_INT, indice_degra.constData());

glVertexPointer(TAB_PAS,GL_FLOAT,0,test[2].send_terrain());
glTexCoordPointer(2, GL_FLOAT, 0, text[2].send_texCoord());
glDrawElements( GL_LINES, indice_degra_de.size(), GL_UNSIGNED_INT, indice_degra_de.constData());

glVertexPointer(TAB_PAS,GL_FLOAT,0,test[3].send_terrain());
glTexCoordPointer(2, GL_FLOAT, 0, text[3].send_texCoord());
// and so on...

I hope this is what you need

user1781290
  • 2,674
  • 22
  • 26
  • Thanks you. And how you calculate the tex Coord ? – user3243742 Jan 29 '14 at 13:45
  • Here is a short tutorial about textures. It ends with an example of texture coordinates: http://www.gamedev.net/page/resources/_/technical/opengl/opengl-texture-mapping-an-introduction-r947 – user1781290 Jan 29 '14 at 16:40