Thanks for the reponses
Jide: Every tutorial I’ve seen uses IdleFunc to draw the scene. The only reason I used the timercallback was to reduce the amount of drawing occuring to let the computer catch it’s breath.
MMMovania: I am using double buffering and I am swapping the buffers, if you don’t, it doesn’t render pretty much at all … lol
I was trying to avoid you guys having to pour through poor code, but I guess it’s sort of unavoidable
I stripped everything down so here’s the nutshell of the code I’m trying to implement. It may not compile correctly, as I’m just cutting and pasting the important code, but this is pretty much what I’m doing:
---------------- Code
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
float cubeAngleX = 0;
float cubeAngleY = 0;
void render(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(cubeAngleX, 1.0, 0.0, 0.0);
glRotatef(cubeAngleY, 0.0, 1.0, 0.0);
glBegin(GL_QUADS);
/* Front Face */
glNormal3f(0.0, 0.0, 1.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);
/* Back Face */
glNormal3f(0.0, 0.0,-1.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);
/* Bottom Face */
glNormal3f(0.0,-1.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);
/* Top Face */
glNormal3f(0.0, 1.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);
/* Right Face */
glNormal3f(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);
/* Left Face */
glNormal3f(-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);
glEnd();
cubeAngleX++;
cubeAngleY++;
glutSwapBuffers();
}
int init(int w, int h){
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window
glMatrixMode(GL_MODELVIEW);
return 1;
}
void timerCallback(int value){
render();
glutTimerFunc(4, timerCallback, 1);
}
void resizeCallback(int w, int h){
if(!h){ h = 1; }
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(250, 250);
glutCreateWindow(“3d Cube with Texture”);
/ glutDisplayFunc(render); I tried turning this off to see if it would effect the crash, but it doesn’t seem to /
/ glutIdleFunc(render); This causes the machine to halt after a few seconds if you put your mouse over the window border and cause a Window Event/
glutTimerFunc(1, timerCallback, 1); /* Start the timer */
glutReshapeFunc(resizeCallback);
if(!init(250, 250)){ exit(1); }
glutMainLoop();
return 0;
}