need help in rotating cube.
can anyone help me to fix this code coz this cube wont rotate. please help this is for uni''s project.
#include <GL/glut.h>
GLint width = 640;
GLint height = 480;
GLfloat rquad;
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glRotatef(rquad,0.0f,1.0f,0.0f);
glBegin(GL_QUADS); //front
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 200.0f, 200.0f, 1.0f);
glVertex3f( 100.0f, 200.0f, 1.0f);
glVertex3f( 100.0f, 100.0f, 1.0f);
glVertex3f( 200.0f, 100.0f, 1.0f);
glEnd();
glBegin(GL_QUADS); //back
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 200.0f, 100.0f, -1.0f);
glVertex3f( 100.0f, 100.0f, -1.0f);
glVertex3f( 100.0f, 200.0f, -1.0f);
glVertex3f( 200.0f, 200.0f, -1.0f);
glEnd();
glBegin(GL_QUADS); //left
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 100.0f, 200.0f, 1.0f);
glVertex3f( 100.0f, 200.0f, -1.0f);
glVertex3f( 100.0f, 100.0f, -1.0f);
glVertex3f( 100.0f, 100.0f, 1.0f);
glEnd();
glBegin(GL_QUADS); //right
glColor3f(1.0f,0.0f,1.0f);
glVertex3f( 200.0f, 200.0f, -1.0f);
glVertex3f( 200.0f, 200.0f, 1.0f);
glVertex3f( 200.0f, 100.0f, 1.0f);
glVertex3f( 200.0f, 100.0f, -1.0f);
glEnd();
glBegin(GL_QUADS);//top
glColor3f(1.0f,1.0f,0.0f);
glVertex3f( 200.0f, 200.0f, -1.0f);
glVertex3f( 100.0f, 200.0f, -1.0f);
glVertex3f( 100.0f, 200.0f, 1.0f);
glVertex3f( 200.0f, 200.0f, 1.0f);
glEnd();
glBegin(GL_QUADS);//bottom
glColor3f(0.0f,1.0f,1.0f);
glVertex3f( 200.0f, 100.0f, 1.0f);
glVertex3f( 100.0f, 100.0f, 1.0f);
glVertex3f( 100.0f, 100.0f, -1.0f);
glVertex3f( 200.0f, 100.0f, -1.0f);
glEnd();
rquad+=0.2f;
glFlush();
}
void main( int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
glutInitWindowSize(width,height);
glutInitWindowPosition(100,100);
glutCreateWindow("My OpenGL Program");
glutDisplayFunc(myDisplay);
myInit();
glutMainLoop();
}
use glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); insted of glClear(GL_COLOR_BUFFER_BIT); and try increasing angle a bit more (since rotations are in degrees 0.2 is not much. try rquad+=2.0f
You can also draw all quads in one glBegin/glEnd.
You should never let your fears become the boundaries of your dreams.

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
i did try that b4 but the cube still refuses to rotate. it just shows the front portion of it n wont rotate. btw..thanx for the info. i'm using win32 console application while the tutorials in this nehe's webpage is in win32 application. does it have any effects on the cubes?
[edited by - harsher on October 14, 2002 5:20:07 AM]
[edited by - harsher on October 14, 2002 5:20:07 AM]
/*
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
*/
This is where u made the mistake...., u SIMPLY forgot to set the matrix mode back to GL_MODELVIEW;
add these lines
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
to get things back in action.
btw, u r setting things up for 2D view and drawing 3D on it ! duh ! what r u actually trying to do ?
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,640.0,0.0,480.0);
*/
This is where u made the mistake...., u SIMPLY forgot to set the matrix mode back to GL_MODELVIEW;
add these lines
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
to get things back in action.
btw, u r setting things up for 2D view and drawing 3D on it ! duh ! what r u actually trying to do ?
Z
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement