Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: My window just shows a white backround

  1. #1
    Newbie Newbie
    Join Date
    Jun 2014
    Posts
    1

    My window just shows a white backround

    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

    Code :
    #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;
    }

    Click image for larger version. 

Name:	Untitled.jpg 
Views:	22 
Size:	7.6 KB 
ID:	1339
    Click image for larger version. 

Name:	Untitledj.jpg 
Views:	21 
Size:	13.7 KB 
ID:	1340

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2011
    Location
    USA
    Posts
    23
    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/

  3. #3
    Intern Contributor
    Join Date
    Mar 2014
    Location
    San Jose, CA
    Posts
    58
    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:

    Code :
    	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);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •