Jump to content
  • Advertisement
Sign in to follow this  
fathom88

Lowering Number of Elements in Arrays???

This topic is 4836 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 using the glColorPointer and glVertexPointer to draw a colored mesh. I use glDrawElements with the GL_QUADS flag and feed it a dummy array of indicies. Each indicy has a x,y defined in a Vertex array. The problem is I also have an RGB value defined for each indicy. In essence, I have an RGB value for each x,y coordinate. However, I really only need 1 RGB color value for each quad I draw. Currently, I end up repeating the same color array values to keep the the vertex and color array one-to-one. I've only been able to find simple examples where this one-to-one relationship exists. Is there a way around this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Put the color in the vertex list instead of the index list. As the color is a property of vertices and not of indices it is a better place and requires no duplicates.

Example:

indices = { 0, 1, 2 }
vertices = {
{ {0.0,0.0,0.0, 0xFF00FF00} },
{ {0.0,1.0,0.0, 0xFF00FFFF} },
{ {1.0,0.0,0.0, 0xFFFFFF00} },
}


Greetz,

Illco

Share this post


Link to post
Share on other sites
Thanks for the help. I noticed in your example that you use a single value for color. I thought OpenGL always required colors to be defined in triplets. At any rate, thanks. I'll give it a try.

Share this post


Link to post
Share on other sites
I think I'm not understanding your example.

indices = { 0, 1, 2 } //vertex 1, 2, 3 Yes?


vertices = {
{ {0.0,0.0,0.0, 0xFF00FF00} }, //vertex 1 x,y,z then color
{ {0.0,1.0,0.0, 0xFF00FFFF} }, //vertex 2 x,y,z then color
{ {1.0,0.0,0.0, 0xFFFFFF00} }, //vertex 3 x,y,z then color
}

Doesn't each vertex have a color associated with it? I was hoping for something like

indices = {0, 1, 2, 3, 4, 5}

vertices = {
0.0,0.0,0.0, //vertex 1 x,y,z of triangle 1
0.0,1.0,0.0, //vertex 2 x,y,z of triangle 1
1.0,0.0,0.0, //vertex 3 x,y,z of triangle 1
0xFFFFFF00} }, then color of triangle 1

0.0,0.0,0.0, //vertex 1 x,y,z of triangle 2
0.0,1.0,0.0, //vertex 2 x,y,z of triangle 2
1.0,0.0,0.0, //vertex 3 x,y,z of triangle 2
0xFFFFFF00} }, then color of triangle 2

}

Then use draw elements to do a triangle. I'm fairly new to OpenGL and I'm not sure if this is even close to correct. Thanks again.


Share this post


Link to post
Share on other sites
Quote:
Original post by fathom88
Currently, I end up repeating the same color array values to keep the the vertex and color array one-to-one. I've only been able to find simple examples where this one-to-one relationship exists. Is there a way around this? Thanks.
No, there is no way around it. Vertex arrays send per-vertex data, so you need all data for each vertex.

You could set the color with glColor* before sending the data (minus the color array) over to the card, but that will set the color for everything you draw until the color is changed again and you can't change the color in the middle of rendering a vertex array. So for that to work you would need to split up your vertex array into smaller vertex arrays, and depending on how many vertices you want with different colors, you will end up sending less and less vertices per draw call, which is what vertex arrays are meant to avoid.

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!