How do I get GLUT cubes in different colors?

Just what it says: I have code that draws GLUT cubes, but they are all gray. How do I make them different colors?

Everything I've tried so far has failed. I think my problem is that I am trying to use OpenGL functions to change their colors, but GLUT supports its own internal color or material data and I have no idea how to make it change that data.

This is just a graphic sticker for a test client for an online game, so they don't need to look good, I just need to be able to talk about everything. I know GLUT is not considered great, so if anyone wants to post an example of drawing a cube with open OpenGL instead of glutCube, I'm all ears. I don't care how I get the cubes on the screen and this is not a piece of code that I want to spend a lot of time on. I have a partner who makes real graphics; I just need to show something so that I can visualize what my code is doing.

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

+2


source to share


2 answers


It turns out if I just do:

            glEnable(GL_COLOR_MATERIAL)

      



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

+2


source


Just set the color in advance glColor()

. If you are using lighting (i.e. GL_LIGHTING

on), then instead you will have to use glMaterial()

to set the color of the cube.



+2


source







All Articles