# Best way to Draw a cube for 3D Picking on a specific face

Currently I am drawing a cube for a game that I am making and the cube draw method is below. My question is, what is the best way to draw a cube and to be able to easily find the face that the cursor is over? My draw method works just fine, but I am getting ready to start to add picking (this will be used to mold the cubes into other shaps), and would like to know the best way to find a face of the cube.

public void  Draw() {
// center point posX, posY, posZ
float radius = size / 2;

//top
glPushMatrix();
{
glColor3f(1.0f,0.0f,0.0f); // red
}
glEnd();
glPopMatrix();

//bottom
glPushMatrix();
{
glColor3f(1.0f,1.0f,0.0f); // ?? color
}
glEnd();
glPopMatrix();

//right side
glPushMatrix();
{
glColor3f(1.0f,0.0f,1.0f); // ?? color
}
glEnd();
glPopMatrix();

//left side
glPushMatrix();
{
glColor3f(0.0f,1.0f,1.0f); // ?? color
}
glEnd();
glPopMatrix();

//front side
glPushMatrix();
{
glColor3f(0.0f,0.0f,1.0f); // blue
}
glEnd();
glPopMatrix();

//back side
glPushMatrix();
{
glColor3f(0.0f,1.0f,0.0f); // green
}
glEnd();
glPopMatrix();
}

• Your title doesn't match your question. I suggest changing it so it does. – Sidar Oct 22 '12 at 19:37
• made your recommended change to the title – user22020 Oct 23 '12 at 3:31

• You can at least update your drawing code so that all the vertices are surrounded by a single glBegin() and glEnd(). Same goes for popping and pushing matrices. OpenGL knows that 4 vertices makes a quad, you don't have to break them all apart like that. – MichaelHouse Oct 22 '12 at 19:51