PDA

View Full Version : My window just shows a white backround



Scarnet
06-11-2014, 03:22 AM
Hello,
I'm an ultra beginner in openGL I'm doing a program that is supposed to show a square using GL_QUADS but it only shows a white background and whenever I try to resize the window this white background doesn't fill the window
I tried not using vertex2f instead of vertex3f, trying to draw another preemptive with another argument in glbegin and even commenting all the code in drawScene but still they all gave me the same result



#include <stdlib.h>
#include <stdio.h>
#include <gl\glut.h>


void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f( 1.0, 1.0, 1.0 );
glClearColor(0.0, 0.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex3f(1.5, 2.0, 2.0);
glVertex3f(1.5, 1.0, 2.0);
glVertex3f(2.0, 1.0, 2.0);
glVertex3f(2.0, 2.0, 2.0);
glEnd();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(20, 60);
glutInitWindowSize(360, 360);
glutCreateWindow("Open GL");
glutReshapeFunc(resizeWindow);
glutDisplayFunc(drawScene);
glutMainLoop();
return 0;
}


1339
1340

Jesse
06-11-2014, 09:24 AM
Your code is calling resizeWindow() on the resize event yet the function is not implemented. Resetting the projection matrix on the resize will give you what you want. You might also want to be learning modern OpenGL instead of this old deprecated OpenGL. A good resource is http://www.arcsynthesis.org/gltut/

reto.koradi
06-11-2014, 05:32 PM
If you use single buffering, you might need a glFlush() call at the end of the drawScene() function. But I would really avoid using single buffering. Use GLUT_DOUBLE instead of GLUT_SINGLE in the flags you pass to glutInitDisplayMode(), and then call glutSwapBuffers() at the end of drawScene(). That should at least show you the background color.

The bigger problem is that your entire square is outside the view volume. If you don't apply any transformations, everything outside the range of (-1, 1) for each coordinate is outside the visible range, and gets clipped away. To get a visible quad, start with coordinates that look something like this:



glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(-0.5f, 0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, 0.5f, 0.0f);