Lowering Number of Elements in Arrays???

Started by
4 comments, last by Kalidor 18 years, 8 months ago
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.
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
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.
it is actually four values combined into a HEX value...

RRGGBBAA or if its BBGGRRAA ... i dont remember. :D

peace.
"Game Maker For Life, probably never professional thou." =)
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.


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.

This topic is closed to new replies.

Advertisement