Skip to main content
gamedev.net
🔒 Locked

Rotation...!?

Started by nirvanalebt Jan 16, 2002 at 4:22 PM 1 replies 200+ views
Original Post
nirvanalebt
nirvanalebt
I want this object I created to rotate. Why doesn´t it work? Can anybody help please??? #include <windows.h> //includes windows.h #include <GL/glut.h> //includes glut.h which includes all others header-files needed for OpenGL #include <stdlib.h> //includes standard-c lib stdlib.h #include <iostream.h> //includes i/o streams-lib iostream.h GLfloat rot; void init() { glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-5.0, 5.0, -5.0, 5.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(rot, 1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glColor3f(0.0, 1.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glVertex3f(1.0, 1.0, 0.0); glVertex3f(-1.0, 1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(1.0, 0.0, 0.0); glVertex3f(1.0, -1.0, -1.0); glVertex3f(1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, -1.0); glVertex3f(-1.0, -1.0, -1.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(1.0, -1.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glVertex3f(-1.0, -1.0, -1.0); glVertex3f(1.0, -1.0, -1.0); glColor3f(0.0, 0.0, 1.0); glVertex3f(-1.0, 1.0, 0.0); glVertex3f(1.0, 1.0, 0.0); glVertex3f(1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, -1.0); glColor3f(1.0, 0.0, 1.0); glVertex3f(-1.0, -1.0, 0.0); glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, 0.0); glColor3f(0.0, 1.0, 1.0); glVertex3f(1.0, -1.0, 0.0); glVertex3f(1.0, -1.0, -1.0); glVertex3f(1.0, 1.0, -1.0); glVertex3f(1.0, 1.0, 0.0); glEnd(); glutSwapBuffers(); rot += 2.0; } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(640, 480); glutInitWindowPosition(100, 100); glutCreateWindow("Test"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; } Edited by - nirvanalebt on January 16, 2002 5:24:16 PM Edited by - nirvanalebt on January 16, 2002 5:42:06 PM Edited by - nirvanalebt on January 16, 2002 5:42:22 PM
-> sorry for my bad english ;) <-
Fruny
Fruny
Up front:

- rot is uninitialized
- you are glPushMatrix()ing without ever glPopMatrix()ing

But more importantly

- you are never refreshing your display with glutPostRedisplay() (e.g. in an idle callback).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
nirvanalebt
nirvanalebt
oh thx ... i think int would help

-> sorry for my bad english <-
-> sorry for my bad english ;) <-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.