PDA

View Full Version : question about glDrawElements



Elefagente Secreto
01-30-2006, 08:34 AM
Hello everybody,
I have a question about glDrawElements... I have an array of objects that I'm currently rendering using vertex arrays (one vertex array for each obj), but I want to set a different color for each object. glColor3f doesn't seem to affect the current color and I think it has something to do with vertex arrays being on the client side... my question is, how can I change the color for each object?? do I need to enable GL_COLOR_ARRAY on the client side? and if so... do I need to specify a color (3 floats, ints...) for each vertex? or a color for each triangle in the indices list??

Hope my question makes sense :)
Thanks in Advance!

songho
01-30-2006, 09:07 AM
Elefagente Secreto,
If you want to apply a single colour to an object, glColor*() should be enough, and you do not need colour array at all.

Colour in vertex array implementation is for vertex, not face(polygon). Please look at the following link about a simple usage of vertex array.
Vertex Array (http://www.songho.ca/opengl/gl_vertexarray.html)

Elefagente Secreto
01-30-2006, 09:47 AM
Originally posted by songho:
Elefagente Secreto,
If you want to apply a single colour to an object, glColor*() should be enough, and you do not need colour array at all.

Colour in vertex array implementation is for vertex, not face(polygon). Please look at the following link about a simple usage of vertex array.
Vertex Array (http://www.songho.ca/opengl/gl_vertexarray.html) Songho,
Many thanks for your reply :) . I'm looking at the code right now, however, there must be something wrong with the app because whenever I run the .exe in the vertexArray.zip I get a "the instruction at 0x00000000 referenced memory....." error.

Edit: or it just may be that I'm using a very old computer at work hehe

songho
01-30-2006, 11:58 AM
Elefagente Secreto,
The error may result from glDrawRangeElements(). It is available from OpenGL v1.2 or greater.

If you think your system is too old, please disable this function and try to re-compile yourself.

In order to make sure the capabilities of your video card, run glinfo (http://www.songho.ca/opengl/files/glinfo.zip) . It will print out useful info into a file, glinfo.txt, such as version, supported extensions, available visual modes, etc.

Elefagente Secreto
01-31-2006, 06:32 AM
Originally posted by songho:
Elefagente Secreto,
The error may result from glDrawRangeElements(). It is available from OpenGL v1.2 or greater.

If you think your system is too old, please disable this function and try to re-compile yourself.

In order to make sure the capabilities of your video card, run glinfo (http://www.songho.ca/opengl/files/glinfo.zip) . It will print out useful info into a file, glinfo.txt, such as version, supported extensions, available visual modes, etc.Thanks songho, comparing your code to mine, I found out the call to glColorMaterial was missing, so even if I specified any color, it wouldn't work :) now it works, thx for the help.