Skip to main content
gamedev.net
🔒 Locked

Array Pointers

Started by Hairu Jul 31, 2001 at 12:57 PM 2 replies 600+ views
Original Post
Hairu
Hairu
Has anyone successfully got "index" vertex arrays to work with texture arrays? If so, does the index pointer work for both the texture array and the vertex array, or just the vertex array? What i''m saying is, should the texture coords also be index in accordance with the vertex array?
Hairu
Hairu
No, i mean like using the index for the actual vertices of the triangles that I am drawing. Here''s a code sample for a routine in my game library....




void DH_Model::show()
{
// if we dont have a model, we cant show anything
if(!model_loaded){ DH_Error.push("Model Not Loaded"); return; }



// if a texture box is set, use it to set the texture
if(texture_box_set)
TextureBox->setTexture(header.TextureName);



// set the texture coordinate arrays
glTexCoordPointer(2, GL_FLOAT, 0, TexCoords);

// set the normal arrays
glNormalPointer(GL_FLOAT, 0, Normals);

// set the vertex pointer
glVertexPointer(3, GL_FLOAT, 0, Vert_public);

// show the model
glDrawElements(GL_TRIANGLES, header.numFaces*3, GL_UNSIGNED_INT, index);

};


The problem is, i''m not sure how i should setup my texture array "TexCoords". The results i''m getting, are different than I expected. I''m building the array as if it wasn''t indexed. Is this correct?




zedzeek
zedzeek


u should have exactlly the same number of vertices as texcoords as normals

eg for a square u have

B-----C
| |
| |
A-----D 4 verts, 4 texcoords, 4 normals
A B C D
verts[] = { {0,0,0}, {0,1,0}, {1,1,0}, {1,0,0} };
texcoords[] { { 0,0 }, { 0,1 }, { 1,1 }, { 1,0 } };
normals[] = { {0,0,1}, {0,0,1}, {0,0,1}, {0,0,1} };

GLuint index[] = {0,1,2,3};
glDrawElements( GL_QUADS, 4, GL_UNSIGNED_INT, index );

or in this case better(faster) yet

glDrawArrays( GL_QUADS, 0, 4 );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.