Jump to content
  • Advertisement
Sign in to follow this  
ade-the-heat

draw quad with VAs-duh !

This topic is 4954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can't do it ! How hard can it be - this has got to be the simplest draw command EVER and I can't do it ! Duh ! Feel free to laugh at me ! I'll cut it down and make it as simple as possible:
//the vertices ! ie a quad facing in +ve z direction
Vertices[0][0] = 0.0f; Vertices[0][1]=0.0f; Vertices[0][2]= 0.0f;
Vertices[1][0] = 1.0f; Vertices[1][1]=0.0f; Vertices[1][2]= 0.0f;
Vertices[2][0] = 1.0f; Vertices[2][1]=1.0f; Vertices[2][2]= 0.0f;
Vertices[3][0] = 0.0f; Vertices[3][1]=1.0f; Vertices[3][2]= 0.0f;

//the normal for this face
m_normalArray[0][0]=0.0f;m_normalArray[0][1]=0.0f;m_normalArray[0][2]=1.0f;

//the text coord for this
m_texcoordArray[0][0]=0.0f;	m_texcoordArray[0][1]=0.0f;
m_texcoordArray[1][0]=1.0f;	m_texcoordArray[1][1]=0.0f;
m_texcoordArray[2][0]=1.0f;	m_texcoordArray[2][1]=1.0f;
m_texcoordArray[3][0]=0.0f;	m_texcoordArray[3][1]=1.0f;

//the index pointer for this ie draw vertices 0,1,2,3 !! 
m_indexArray[0]=0; m_indexArray[1]=1;m_indexArray[2]=2;	m_indexArray[3]=3;


//enable client state
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_INDEX_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, Vertices);	
glNormalPointer(GL_FLOAT, 0, m_normalArray);
glTexCoordPointer(2, GL_FLOAT, 0, m_texcoordArray);
glIndexPointer(GL_UNSIGNED_BYTE, 0, m_indexArray);




//DRAW !!!! 
glPushMatrix();
	glTranslatef(position.x, position.y, position.z);
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, frontText[0]);
	glPushMatrix();
		glScalef((GLfloat)width, (GLfloat)SHOP_HEIGHT, 0.0f);
                glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_BYTE, m_indexArray);
	glPopMatrix();
glPopMatrix();

nothing on the screen at all ! I do about 50 of these calls. It works fine if I don't use VAs Humour me - is the above dumbo code correct ?! cheers Ade edited by _the_phantom
Added source tags, please use them in future and check the forum FAQ for details on the tags to use

Share this post


Link to post
Share on other sites
Advertisement
hmmm I need a normal for each face,
anyhow I did a normal for each vertex just now and still have nothing on the screen.

This is so annoying, this is the simplest thing ever and I can't do it.


in reply to the other person here's the defs of the arrays:

GLfloat bldgVertices[8][3];
GLubyte m_indexArray[24];
GLfloat m_normalArray[24][3]; //was [6][3]
GLfloat m_colorArray[6][3];
GLfloat m_texcoordArray[24][2];

Share this post


Link to post
Share on other sites
well to make sure I wasn't going mad I did the following instead of DrawElements:

glColor3f(0.8f, 0.8f, 0.8f);
glBegin(GL_QUADS);
glVertex3fv(Vertices[0]);
glVertex3fv(Vertices[1]);
glVertex3fv(Vertices[2]);
glVertex3fv(Vertices[3]);
glEnd();


and it worked FINE !!!

So the Vertices are correct but I can't get the DrawElements to work at all.

Any ideas ?

Share this post


Link to post
Share on other sites
ok, refresher:
What I'm tryign to do is (firstly) draw a quad using VAs:

glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, m_indexArray);

That call does not work.

So, in the very same place of the above call I've explicitly created the quad - this time using the indexArray and Vertices array like this:

glBegin(GL_QUADS);
glVertex3fv(Vertices[m_indexArray[quad*4]]);
glVertex3fv(Vertices[m_indexArray[quad*4]+1]);
glVertex3fv(Vertices[m_indexArray[quad*4]+2]);
glVertex3fv(Vertices[m_indexArray[quad*4]+3]);
glEnd();

THIS WORKS !!!

This means that 1)m_indexArray has the correct data 2) Vertices has the correct data !!


So why won't my DrawElements call work at all when it uses precisely the same data as the explicit call.

ppplllllleeeeeaaasee ... anyone ?!

cheers




Share this post


Link to post
Share on other sites
Well, get rid of the inner 'push/popmatrix()' commands...that might be resetting your matrix, give it a try anyway.

Also, try using standard VA's ( "glDrawArrays()" ) and see what happends.

-Twixn-

Share this post


Link to post
Share on other sites
This works for me:


//Init stuff
GLfloat Vertices[4][3];
GLfloat m_texcoordArray[4][2];
GLubyte m_indexArray[4];

Vertices[0][0] = 0.0f; Vertices[0][1]=0.0f; Vertices[0][2]= 0.0f;
Vertices[1][0] = 1.0f; Vertices[1][1]=0.0f; Vertices[1][2]= 0.0f;
Vertices[2][0] = 1.0f; Vertices[2][1]=1.0f; Vertices[2][2]= 0.0f;
Vertices[3][0] = 0.0f; Vertices[3][1]=1.0f; Vertices[3][2]= 0.0f;

m_texcoordArray[0][0]=0.0f; m_texcoordArray[0][1]=0.0f;
m_texcoordArray[1][0]=1.0f; m_texcoordArray[1][1]=0.0f;
m_texcoordArray[2][0]=1.0f; m_texcoordArray[2][1]=1.0f;
m_texcoordArray[3][0]=0.0f; m_texcoordArray[3][1]=1.0f;

m_indexArray[0]=0; m_indexArray[1]=1;m_indexArray[2]=2; m_indexArray[3]=3;

//Later on, (in draw loop)

//Set camera, bind texture, blah blah blah, then....
glVertexPointer(3, GL_FLOAT, 0, Vertices);
glTexCoordPointer(2, GL_FLOAT, 0, m_texcoordArray);

glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, m_indexArray);




This drew a small quad in the center of my screen with the current texture mapped to it. Note that I didn't even have to call glEnableClientState() on anything, but that may have just been me. I recommend trying it out with minimal data like this (no normals or anything) first, getting that to work, then building on it from there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!