Here's how I usually set up my quads:
Coordinates
D C
A B
Vertices
A B
D C
Here's are the coordinates:
vertices = {-1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1};
coords = {TEX(0, 0), TEX(255, 0), TEX(255, 255), TEX(0, 255)}; // assumes 256x256 texture image
normal = {0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1};
triangles = {1, 0, 3, 1, 3, 2};
Where TEX(u,v) is defined as (GLbyte)( (u) - 128 ) , (GLbyte)( (v) - 128 )
Draw code
glMatrixMode(GL_MODELVIEW);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_BYTE, 0, vertices);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_BYTE, 0, coordinates);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_BYTE, 0, normals);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, triangles);
No comments:
Post a Comment