Hi, i need to know how to create more than 1 teapot in Borland C
Regards,
Orange_82
Hi, i need to know how to create more than 1 teapot in Borland C
Regards,
Orange_82
This is not advanced or about opengl.
for( int i = 0; i < numTeapots; ++i )
teapot_array[i] = CreateTeapot();
-SirKnight
Originally posted by SirKnight:
[b]This is not advanced or about opengl.
for( int i = 0; i < numTeapots; ++i ) teapot_array[i] = CreateTeapot();
-SirKnight[/b]
Ya, I know sorry, i didn’t put in the whole question. What I meant is creating 16 teapots and perform translation on them.
What function are you using to draw the teapot?
This example will work under any C/C++ compiler:
glPushMatrix();
glTranslatef( 0,0,0); // location of first teapot
glutSolidTeapot(1); // Draw teapot
glPopMatrix();
glPushMatrix();
glTranslatef( 1,0,0); //location of second teapot
glutSolidTeapot(1);
glPopMatrix();
// repeat above with a new location for each teapot.
Originally posted by Orange_82:
[b]Hi, i need to know how to create more than 1 teapot in Borland C
Regards,
Orange_82[/b]
Originally posted by nexusone:
[b]What function are you using to draw the teapot?
This example will work under any C/C++ compiler:
glPushMatrix();
glTranslatef( 0,0,0); // location of first teapot
glutSolidTeapot(1); // Draw teapot
glPopMatrix();
glPushMatrix();
glTranslatef( 1,0,0); //location of second teapot
glutSolidTeapot(1);
glPopMatrix();
// repeat above with a new location for each teapot.
[quote]Originally posted by Orange_82:
[b]Hi, i need to know how to create more than 1 teapot in Borland C
Regards,
Orange_82[/b]
[/b][/QUOTE]Ermm, i am creating 16 teapots. And I am thinking of using arrays for the glTranslatef but I am not good @ arrays, do you think you can tell me how 2 do it?
try to familiarize yourself with arrays as soon as possible, its absolutely crucial to programming !
anyway how do you want to arrange your teapots ?
like a 4x4 square, or how ?
4x4 square would be easiest with
for (x = 0; x < 4; x++){
for (y = 0; y < 4; y++){
glPushMatrix();
glTranslatef( x*2,y*2,0); // location with gaps of 2
glutSolidTeapot(1); // Draw teapot
glPopMatrix();
}
}
if you use a single array to store the teapots positions like 16 * 3 floats
e.g.
GLfloat teaPos = {0,0,1, 0,0,2 ,0,0,3 …};
you could do
for (i = 0; i < 16; i++){
glPushMatrix();
glTranslatef(teaPos[i*3],teaPos[i*3+1],teaPos[i*3+2]); // location
glutSolidTeapot(1); // Draw teapot
glPopMatrix();
}