Jump to content
  • Advertisement
Sign in to follow this  
rnodal

Help with glDrawArrays.

This topic is 3837 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'm having a hard time rendering the right amount of quads. I'm using an array for color, texture coordinates and finally an array for the vertex. All of them are one dimension. The problem is that no mater how I modify the glDrawArrays I seem to reach a maximum of quads that appear on the screen. For example if I call:
glDrawArrays(GL_QUADS, 0, 4);
I get one quad and if I increase the last parameter by four I increase the number of quads. The problem is that If I pass let's say 400 I don't get 100 quads I get only 25. Here is my rendering code:
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, 0, this->colorList);
glTexCoordPointer(2, GL_FLOAT, 0, this>extureCoordinatesList);
glVertexPointer(3, GL_FLOAT, 0, this>verticesList);
glDrawArrays(GL_QUADS, 0, this>numberOfVertices);
// Disable arrays.
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
Is there anything that I have misunderstood? Am I misusing glDrawArrays? Any suggestions to what could be the source of the problem? Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
I don't see anything wrong with the code. Perhaps the other quads are out of the window.

Share this post


Link to post
Share on other sites
What's the difference between glDrawArrays and glDrawElements? I have a feeling that glDrawArrays is drawing a bunch of quads behind other quads and that's why I'm only getting 25 and with a flickering in the border.

-R

Share this post


Link to post
Share on other sites
OK, if I disable the color array then I do see the right amount of images but they are all green. I can do a call to glColor4f right before glDrawArrays but I don't want to loose the ability to render quads with different colors.


-r

Share this post


Link to post
Share on other sites
I don’t see anything wrong with your code. Maybe it’s a device bug. Have you tried on other computers? Does similar codes work on other programs (for example from tutorials)?

Share this post


Link to post
Share on other sites
I'm pretty sure that it 3 graphics cards can not be bad. Here is how I set my color array maybe there is something wrong with that.


this->colorList[this->colorIndex] = red;
this->colorIndex++;
this->colorList[this->colorIndex] = green;
this->colorIndex++;
this->colorList[this->colorIndex] = blue;
this->colorIndex++;
this->colorList[this->colorIndex] = alpha;
this->colorIndex++;


So if I'm rendering two images I get something like:
1.0, 0.4, 0.2 1.0, 0.3, 1.0, 0.3, 1.0 and that would represent two colors.

How do I tell opengl when to stop? Also maybe my stride may be wrong?

Thanks!

[Edited by - rnodal on June 8, 2008 1:00:50 PM]

Share this post


Link to post
Share on other sites
OK I found what the problem was. I need to define a color per each vertex of the quad and I was only doing it once. This is the correct code:

for(int i = 0; i < 4; i++)
{
this->colorList[this->colorIndex] = red;

this->colorIndex++;

this->colorList[this->colorIndex] = green;

this->colorIndex++;

this->colorList[this->colorIndex] = blue;

this->colorIndex++;

this->colorList[this->colorIndex] = alpha;

this->colorIndex++;
}

The only problem that I have know is that the edges of the quads flicker.

-r

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!