draw quad with VAs-duh !

Started by
25 comments, last by Toji 18 years, 12 months ago
ah yes, good point, the inital code posted and the code which used glVertex() dont do the same thing!.
The later just draw a quad with no texturing nor normal infomation applied, the former however applies normals and if you've switched lighting on (or havent infact) this could cause your object to appear black.

So, chances are your code does work but something in the lighting is broken and thus it appears as though you dont draw anything.
Advertisement
ok, I checked and the light is definitely on, it's never disabled, I can check this because if I revert to drawing the quads not using DrawElements but with normals then I can see the shading etc.
I also tried removing the second push/pop to no avail.


So I now tried this:


glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, Vertices);
glNormalPointer(GL_FLOAT, 0, m_normalArray);
glColorPointer(3, GL_FLOAT, 0, m_colorArray);


glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, m_indexArray);



still nothing.


BTW the color array is set up like this:

for (int i=0; i<4; i++)
{
m_colorArray[0]=m_colorArray[1]=m_colorArray[2] = 0.7f;
}


the normals are set up like (although I think I only need one normal for one quad but this won't hurt.:

for (int i=0; i<4; i++)
{
m_normalArray[0]=0.0f;m_normalArray[1]=0.0f;m_normalArray[2]=1.0f;
}


Quote:Original post by ade-the-heat
the normals are set up like (although I think I only need one normal for one quad but this won't hurt.


No, you need one normal for each vertex in the vertex array, doing anything else will definately break things.

And you arent using the code tags, even after I asked nicely *stern look*
even with a normal for each vertex it still didn't work.
sigh....

is there anything else I can do ?... getting depressed...


BTW what's a code tag (not being sarcastic - i don't remember you mentioning it).



cheers


Quote:Original post by ade-the-heat
BTW what's a code tag (not being sarcastic - i don't remember you mentioning it).


I assume you didnt notice your first post in this thread was edited then...

Did you say tha you did have lighting turned on? Have you tried switching it off and rendering? If the light or normals are configured wierd it could easily be drawing a black poly on the screen, which would make it effectively invisible.

On a similar note, based on some really horrid lighting bugs in the past I always always ALWAYS clear the screen to a non-black color when I'm doing my testing/developing. This helps immensly, as black or really dark polys are visible. Favorite "debug" setting is: glClearColor(0.1f, 0.1f, 0.2f, 1.0f);

Gives you a nice bluish-grey background that's not very distracting but helps the details show up.
// Tojiart
thanks, the light is defitely on as I have cleared the screen to light blue each frame, in addition if I create the quad using the glVertex3fv way with normals then I can see lots of these quads (each frame I write about 30 quads to the screen).



Phantom- thanks I'll re-start on the faqs,

cheers
ok, you mentioned lights, so here is what i tried and it still didn't work !
Nothing on the screen at all:
(look previously msgs in this thread to see how I set up the arrays - which work when i use them when I did the working version with glVertext3f)

float lightpos[4]={0.0f, 700.0f, 1.0f, 0.0f};float ambientlight[4]={145.0f/255.0f, 145.0f/255.0f, 145.0f/255.0f, 0.0f};float diffuselight[4]={145.0f/255.0f, 145.0f/255.0f, 145.0f/255.0f, 0.0f};	glEnable(GL_LIGHTING);	glLightfv(GL_LIGHT0, GL_AMBIENT, ambientlight); 	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuselight); 	glLightfv(GL_LIGHT0, GL_POSITION, lightpos); 	//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientlight);	glEnable(GL_LIGHT0);	//now draw relevant quad in our vertices	glEnableClientState(GL_VERTEX_ARRAY);	glEnableClientState(GL_NORMAL_ARRAY);	glEnableClientState(GL_COLOR_ARRAY);	glVertexPointer(3, GL_FLOAT, 0, bldgVertices);		glNormalPointer(GL_FLOAT, 0, m_normalArray);	glColorPointer(3, GL_FLOAT, 0, m_colorArray);	//glColor3f(0.8f, 0.8f, 0.8f);	glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, m_indexArray);

First off: Thanks for the source tags! Makes things easier to read.

Second: When I mentioned the lights, I asked if they were on, and if so to turn them OFF. Only for a moment, and simply for debug purposes. All you would really have to do is call glDisable(GL_LIGHTING) right before your draw call. I would recommend doing this until you have the quad showing up, THEN enabling lighting again and working from there. Always start with the minimal possible settings and work your way up. The less that's enabled the less that can go wrong.

Also, once again just for debugging purpouses, try commenting out the following two lines:

glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, m_normalArray);

Then run the code and see if it makes a difference. Again, this is just starting with a minimal amount of information (Position and TexCoords) and then working your way up after you get it working.

Sorry if you've already tried those, but it's not clear that you have.
// Tojiart
Why are you enabling these on the client side?

use glEnable(GL_VERTEX_ARRAY).

see if that fixes it.

This topic is closed to new replies.

Advertisement