PDA

View Full Version : having problems



weepel
10-29-2001, 03:33 PM
I just started with opengl and tried making a basic program with it.. open full screen window then draw something on it.. the program loads with out errors and opens the window.. yet nothing gets drawn.. why is this? heres the code..



#include <GL/glut.h>
#include <GL/GL.h>

void draw(void);

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutGameModeString("640x480:16@60");
glutEnterGameMode();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT);
draw();
return 0;
}

void draw(void) {
glColor3f (1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
}


what am i missing? (or doing wrong)

iNsaNEiVaN
10-29-2001, 03:47 PM
along with GL_COLOR_BUFFER_BIT try calling
GL_DEPTH_BUFFER_BIT

write it like this:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

weepel
10-29-2001, 04:00 PM
It still doesn't work.. I dont see the thing I have drawn..... just a full screen thing blinking..

can you try running it?

10-29-2001, 04:03 PM
You have several problems

try this code

#include <glut.h>
#include <GL/GL.h>

void draw(void);


int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutGameModeString("640x480:16@60");
glutEnterGameMode();
glutDisplayFunc(draw);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glutMainLoop();
return 0;
}

void draw(void)
{
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glutSwapBuffers();
}

The most important ones are you did not setup a display function note the

glutDisplayFunc

you did not enter the message loop

glutMainLoop

//NOTHING in glut is done before this is called.

you did not swap the buffers, you have a double buffered window GLUT_DOUBLE

at the end of the drawing func you call

glutSwapBuffers

weepel
10-29-2001, 04:13 PM
It works.

Thanks guys, really appreciate it!

[This message has been edited by weepel (edited 10-29-2001).]