PDA

View Full Version : glut functions



10-09-2002, 12:52 PM
For the glut functions that draw the geometric figures, like the shpere, and cone: does OpenGL always draw them in the center of the window? It seems that way.
For example:
void pyramid();
void display();
void init();

int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1000, 1000);
glutInitWindowPosition(20, 20);
glutCreateWindow("Homework 2");
init();
glutDisplayFunc(display);
glutMainLoop();

return 0;
}


void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(0.50, 0.60, 0.70);
glTranslatef(80.0, 150.0, 0.0);
glRotatef(120.0, 1.0, 0.0, 0.0);
glRotatef(30.0, 0.0, 1.0, 0.0);
glutWireCone(200.0, 300.0, 4, 0);
glLoadIdentity();

//glTranslatef(0.0, 0.0, 100.0);
//glRotatef(120.0, 1.0, 0.0, 0.0);
glutWireCone(200.0, 300.0, 4, 0);

glutSwapBuffers();
}

void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);

glOrtho(-500.0, 500.0, -500.0, 500.0, -500.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
}

nexusone
10-09-2002, 02:08 PM
I think the anwser is yes, the origin of each glut object is their center.
But it is a good habbit to do that with any object you create, makes posistioning and rotating easier.


Originally posted by Always need help:
For the glut functions that draw the geometric figures, like the shpere, and cone: does OpenGL always draw them in the center of the window? It seems that way.
For example:
void pyramid();
void display();
void init();

int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1000, 1000);
glutInitWindowPosition(20, 20);
glutCreateWindow("Homework 2");
init();
glutDisplayFunc(display);
glutMainLoop();

return 0;
}


void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(0.50, 0.60, 0.70);
glTranslatef(80.0, 150.0, 0.0);
glRotatef(120.0, 1.0, 0.0, 0.0);
glRotatef(30.0, 0.0, 1.0, 0.0);
glutWireCone(200.0, 300.0, 4, 0);
glLoadIdentity();

//glTranslatef(0.0, 0.0, 100.0);
//glRotatef(120.0, 1.0, 0.0, 0.0);
glutWireCone(200.0, 300.0, 4, 0);

glutSwapBuffers();
}

void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);

glOrtho(-500.0, 500.0, -500.0, 500.0, -500.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
}

jmg
10-09-2002, 05:48 PM
Try this instead:

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glLoadIdentity();
glColor3f(0.50, 0.60, 0.70);

glPushMatrix();
glTranslatef(80.0, 150.0, 0.0);
glRotatef(120.0, 1.0, 0.0, 0.0);
glRotatef(30.0, 0.0, 1.0, 0.0);
glutWireCone(200.0, 300.0, 4, 0);
//glLoadIdentity();
glPopMatrix();

//glTranslatef(0.0, 0.0, 100.0);
//glRotatef(120.0, 1.0, 0.0, 0.0);
glutWireCone(200.0, 300.0, 4, 0);

glutSwapBuffers();
}

//--------------------------------
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);

glOrtho(-500.0, 500.0, -500.0, 500.0, -500.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}