Advertisement

OpenGL Help

Started by October 28, 2003 04:08 PM
1 comment, last by reddemon 21 years, 4 months ago
Hi, I am a beginner to OpenGL and am trying to do some very basic stuff, but am very new to it. Basically I am trying to produce a 2 across by 3 down square cell pattern in portrait layout. However I am unsure of how to do this, I have drawn the outline so far using the code below: ---------- void Draw_Wireframe_Cube (void) { glColor3f(0.0,0.0,0.0) ; glutWireCube(1.5) ; } ---------- How can I divide this workspace into the 6 cells I require. Any help would be much appreciated. Mike.
If you are trying to create 6 of those wire wire cubes... you need to translate over &/or down before each new cube, otherwise all 6 will be drawn on top of each other.

so in your draw function, something like this:

float X = 1.5f;
float Y = 1.5f;
//starting at top left cube
Draw_Wireframe_Cube();
glTranslatef(X, 0.0f, 0.0f);
Draw_Wireframe_Cube();
glTranslatef(-X, -Y, 0.0f);
Draw_Wireframe_Cube();
glTranslatef(X, 0.0f, 0.0f);
Draw_Wireframe_Cube();
glTranslatef(-X, -Y, 0.0f);
Draw_Wireframe_Cube();
glTranslatef(X, 0.0f, 0.0f);
Draw_Wireframe_Cube();
//just drew the bottom right cube

Advertisement
You could do a horizontal loop with a vertical loop inside it and apply translations there.

for (int horizontal=0; horizontal<2; horizontal++)
{
for (int vertical=0; vertical<3; vertical++)
{
//Each box is 1.5 in size right?
glPushMatrix(); //Save origin point
glTranslatef(horizontal*1.5, vertical*1.5, 0.0);
Draw_Wireframe_Cube();
glPopMatrix(); //Return to origin point
}
}

Hope this is what you need.
if (!understand) ask;

This topic is closed to new replies.

Advertisement