PDA

View Full Version : Texture Binding with gldrawarrays



P4r4digm
02-17-2009, 09:56 AM
I'm having a bit of trouble and can't seem to find the issue.
I've been going off of NeHe's tutorials mostly (minus using glaux of course) but i wanted to switch from glbegin/end to gldrawarrays but I cant seem to get it right

here's my draw function


int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WinData.Size.x(), WinData.Size.y(), 0,-1.0f, 1.0f);

glTranslatef(pos.x(),pos.y(), 0.0f);

GLfloat vertices[] = {0,0,spriteSize.x(),0,spriteSize.x(),spriteSize.y( ),0,spriteSize.y()};
GLfloat texVertices[] = {0,0, 1,0, 1,1, 0, 1};

glEnableClientState(GL_VERTEX_ARRAY);

glBindTexture(GL_TEXTURE_2D, texture[0]);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texVertices);
glDrawArrays(GL_QUADS, 0, 4);

glDisableClientState(GL_VERTEX_ARRAY);



All i get is a black, blank texture...On the other hand...this code works:


glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( spriteSize.x(),0.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(spriteSize.x(),spriteSize.y(), 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0, spriteSize.y(), 1.0f);
glEnd();


Any help would be awesome, thanks

-Ekh-
02-17-2009, 10:37 AM
Add it too:

glEnableClientState (GL_TEXTURE_COORD_ARRAY_EXT);

P4r4digm
02-17-2009, 10:43 AM
thanks that worked =D
what does array_ext do exactly?

James A.
02-17-2009, 08:10 PM
GL_TEXTURE_COORD_ARRAY:

If enabled, the texture coordinate array is enabled for writing and used for rendering when glDrawArrays or glDrawElements is called. See glTexCoordPointer.

from:
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/enableclientstate.html