Archived

This topic is now archived and is closed to further replies.

Jappie

Vertex arrays & texturing

Recommended Posts

Jappie    122
Hey people, perhaps someone can help me with this little problem: I have created a terrain mesh using vertex arrays, it''s just when I add a texture coordinate array, the tris are just drawn in a shade of grey rather than textured. Here''s what I do:
  
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glTexCoordPointer(2, GL_FLOAT, 0, g_TexCoords);
glVertexPointer(3, GL_DOUBLE, 0, g_Vertices);

glDrawArrays(GL_TRIANGLES, 0, g_NumIndices / 3);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
  
Now, g_TexCoords is an array of float, containing the UV coords for every vertex. g_Vertices contains the XYZ coords for all vertices, and g_NumIndices is the amount of indices in the g_Vertices array. Does anyone know why my textures aren''t showing? ----------------------------- Jappie BabJap Productions "There''s no such things as bugs; they''re just unintentional extra features"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Are you forgetting to glEnable(TEXTURE_2D);?

Billy - BillyB@mrsnj.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Are you positive that the texture is loaded properly, and that you are binding the texture?

Try this function:

//This will draw the array with texture using basics.
void TestDrawArray(float *vList, float *tList, unsigned short Faces, int tNum)
{
int ctr;
glBindTexture(GL_TEXTURE_2D, tNum);
glBegin(GL_TRIANGLES);
for (ctr=0;ctr!=Faces;++ctr)
{
glTexCoord2f(*(tList++(,*(tList++));
glVertex3f(*(vList++),*(vList++),*(vList++));
}
glEnd();
}


Billy - BillyB@mrsnj.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You can further speed that function up if you''re really going to be using it like so:
  
//This will draw the array with texture using basics.

void TestDrawArray(float *vList, float *tList, unsigned short Faces, int tNum)
{
int ctr;
glBindTexture(GL_TEXTURE_2D, tNum);
glBegin(GL_TRIANGLES);
for (ctr=0;ctr!=Faces;++ctr)
{
glTexCoord2fv(tList);
glVertex3fv(vList);
tList+=2;
vList+=3;
}
glEnd();
}

Share this post


Link to post
Share on other sites