tags:

views:

406

answers:

2

Just what it says: I have some code that's drawing GLUT cubes, but they're all grey. How do I make them different colors?

Everything I've tried so far has failed. I think my problem is that I'm trying to use OpenGL functions to change their colors, but GLUT is maintaining it's own internal color or material data and I don't know how to make it change that data.

This is just filler graphics for a test-client for an online game, so they don't have to look good, I just need to be able to tell things apart. I know GLUT isn't considered great, so if anyone wants to post an example of drawing a cube with plain OpenGL instead of glutCube I'm all ears. I don't really care how I get the cubes on the screen, and it's not a part of the code I want to spend a lot of time on. I have a partner who's doing the real graphics; I just need to get something showing so that I can visualize what my code is doing.

The language I'm using OpenGL/GLUT from is called Io, but the API it exposes should be the same as if I were calling it from C.

+2  A: 

Just set the color beforehand with glColor(). If you're using lighting (i.e. GL_LIGHTING is enabled), though, then you'll instead have to use glMaterial() to set the cube's color.

Adam Rosenfield
You might also have a look at the NeHe OpenGL lessons: http://nehe.gamedev.net/lesson.asp?index=01 - They have some basic code for many languages there you could use.
schnaader
Could you add an example of some args to give to glMaterial? Looking at the hyperlink for glMaterial it seems like it's talking about shininess; it's not obvious to me how that relates to color.I am indeed using GL_LIGHTING, because I found that with lighting turned off it became impossible to distinguish the edges of my shapes.
Dennis
A: 

It turns out that if I just do:

            glEnable(GL_COLOR_MATERIAL)

then it makes the material track whatever color I set with glColor, even when lighting is enabled.

Dennis