PDA

View Full Version : coloring different faces of a solid cube



prashantgp
12-18-2002, 08:50 PM
Hi all,
i am drawing a solid cube using glutSolidCube(0.15);
and i am rotating it 15 degrees on x & y so that it looks like a 3d box.
i want to color the different faces with different colors so that it gives real effect.
pls let me know what should i do.
regards,
Prashant G.P

mdog1234
12-19-2002, 12:39 AM
first of all you should not just glutSolidCube, there is no way to color individual faces. I would just specify individual coorordinates.
Since some people have trouble viewing things in 3d in their mind here are some coordinates for a simple cube:

glBegin(GL_POLYGON);
glVertex3f(-0.500000, -0.500000, 0.500000);
glVertex3f(0.500000, -0.500000, 0.500000);
glVertex3f(0.500000, 0.500000, 0.500000);
glVertex3f(-0.500000, 0.500000, 0.500000);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-0.500000, 0.500000, 0.500000);
glVertex3f(0.500000, 0.500000, 0.500000);
glVertex3f(0.500000, 0.500000, -0.500000);
glVertex3f(-0.500000, -0.500000, -0.500000);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-0.500000, 0.500000, -0.500000);
glVertex3f(0.500000, 0.500000, -0.500000);
glVertex3f(0.500000, -0.500000, -0.500000);
glVertex3f(-0.500000, -0.500000, -0.500000);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-0.500000, -0.500000, -0.500000);
glVertex3f(0.500000, -0.500000, -0.500000);
glVertex3f(0.500000, -0.500000, 0.500000);
glVertex3f(-0.500000, -0.500000, 0.500000);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(0.500000, -0.500000, 0.500000);
glVertex3f(0.500000, -0.500000, -0.500000);
glVertex3f(0.500000, 0.500000, -0.500000);
glVertex3f(0.500000, 0.500000, 0.500000);
glEnd();

glBegin(GL_POLYGON);
glVertex3f(-0.500000, -0.500000,-0.500000);
glVertex3f(-0.500000, -0.500000, 0.500000);
glVertex3f(-0.500000, 0.500000, 0.500000);
glVertex3f(-0.500000, 0.500000, -0.500000);
glEnd();

fringe
12-19-2002, 12:44 AM
Hi I am just a newbie but my guess is that glu won't let you colour the faces different colours. Instead why not draw the cube yourself with verticies in quads and change the colour before each quad. Something like

glColor3f(1,0,0); //red
glBegin(GL_QUADS); //draw the front face dimensions 2l by 2l
glVertex3f(l,l,l); //top right nearest corner
glVertex3f(l,-l,l); // bottom right nearest corner
glVertex3f(-l,-l,l); // bottom left nearest
glVertex3f(l,-l,l); //top left nearest
glEnd();
glColor3f(0,1,0); //green
glBegin(GL_QUADS); //top face
glVertex3f(l,l,l);
glVertex3f(l,l,-l);
glVertex3f(-l,l,-l);
glVertex3f(-l,l,l)
glEnd();

OK hope that has started you off. Now you have another fourr faces to draw.

Hope that helps,
Fringe

P.S. I am coding at work so this is all from memory I am sorry if it doesn't work.

EDIT: Looks like someone beat me to it http://www.opengl.org/discussion_boards/ubb/smile.gif)

[This message has been edited by fringe (edited 12-19-2002).]

siddu78
12-19-2002, 05:05 AM
hi,
are u from davangere?

prashantgp
12-19-2002, 05:25 AM
Originally posted by siddu78:
hi,
are u from davangere?

Hi Sidhu,
u could have used my mail id to ask this.This forum is not for such discussions.
since u've not specified ur mail id in ur profile i am replying to u on the forum.
for further details contact me using mail with ur details.