🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

What the hell

Started by
5 comments, last by Brother Bob 17 years, 10 months ago
Hi, I am very new to OpenGl. But I have to learn it. So I have a question: Why does the following Code show nothing? #include <stdlib.h> #include <GL/glut.h> #include <cmath> using namespace std; #define KOORDINATENACHSE 1 void init(); void renderScene(); void reshapeWindow(int,int); int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE| GLUT_RGBA); glutInitWindowPosition(100,100); glutInitWindowSize(800,600); glutCreateWindow("OpenGL"); init(); glutDisplayFunc(renderScene); glutReshapeFunc(reshapeWindow); glutMainLoop(); return 0; } void init() { glClearColor(1.0F,1.0F,1.0F,1.0F); glEnable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(80,1.0,0.1,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void renderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(3,2,5,0,0,0,0,0,1); glNewList(KOORDINATENACHSE,GL_COMPILE_AND_EXECUTE); glBegin(GL_LINES); //X-Achse: rot glColor3f(1.0,0.0,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(10.0,0.0,0.0); //Y-Achsr: gruen glColor3f(0.0,1.0,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,10.0,0.0); //Z-Achse: blau glColor3f(0.0,0.0,1.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,0.0,10.0); glEnd(); glEndList(); glBegin(GL_QUADS); glColor3f(0.5,0.3,0.9); glVertex3d(-100,-100,0); glVertex3d(100,-100,0); glVertex3d(100,100,0); glVertex3d(-100,100,0); glEnd(); glFlush(); } void reshapeWindow(int w,int h) { if(h == 0) h = 1; float ratio = 1.0* w / h; // Reset the coordinate system before modifying glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set the viewport to be the entire window glViewport(0, 0, w, h); cout<<"reshape"<<endl; }
Advertisement
try putting some sort of loop around the glutdisplayfunc().

because currently all your program is doing is running through everything once.

aside from that it looks like it may work. if not well go from there :).

edit: another note, you may be more likely to get a reply with a better title ;)
It could be because it runs to fast and because you are using single buffereing when you should be using double buffering.

Change glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE| GLUT_RGBA); to
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);

and add glutSwapBuffers(); at the end of the render function.

There could also be a problem with gluLookAt
Thanks. The problem was solved. I played a little bit with the camera and uses now Double Buffering. But since Qt works fine on my computer, I won't use Glut anymore (perhaps :))

bye
One other thing, you appear to be compiling and executing a new display list every frame. I think what you wanted was to compile the display list in main() then execute it every frame?
Quote: Original post by escudo825
try putting some sort of loop around the glutdisplayfunc().

because currently all your program is doing is running through everything once.

aside from that it looks like it may work. if not well go from there :).

edit: another note, you may be more likely to get a reply with a better title ;)


glutMainLoop() will repeatedly call his drawing function.
Quote: Original post by Ezbez
Quote: Original post by escudo825
try putting some sort of loop around the glutdisplayfunc().

because currently all your program is doing is running through everything once.

aside from that it looks like it may work. if not well go from there :).

edit: another note, you may be more likely to get a reply with a better title ;)


glutMainLoop() will repeatedly call his drawing function.

Only if there is a reason to do so. If the window doesn't need a redraw, the mainloop won't call the display function. Only things like a window reshape/reposition, revealing previously hidden parts of the window, and so will trigger a redraw. If you need repeated callbacks, you need to so by calling glutPostRedisplay, preferably in the idle callback.

This topic is closed to new replies.

Advertisement