Results 1 to 2 of 2

Thread: how does glClearColor function works?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    4

    how does glClearColor function works?

    Hi,
    I am newbie to the OpenGL programming,
    actually i have written a code for displaying a polygon,

    and i want to clear the background color from black to red,(using glClearColor and glClear functions) but it is not happening

    I am unable to figure out where i have gone wrong,

    and also please explain me how the glClearColor function works

    here is my code

    Code :
    #include <GL/glut.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    void display(void)
    {
    	int i;
     
    	glClear(GL_COLOR_BUFFER_BIT);
    	glColor3f(0.0, 0.0, 1.0);
     
    	glBegin(GL_POLYGON);
    	glVertex3f(1.1, 1.1, 0.1);
    	glVertex3f(2.7, 2.1, 0.5);
    	glVertex3f(2.7, 2.7, 0.1);
    	glVertex3f(1.1, 2.7, 0.5);
    	glEnd();
     
    	glFlush();
    }
    void init(void)
    {
    	glClearColor(1.0,0.0,0.0,0.0);
     
     
    	//glMatrixMode(GL_PROJECTION);
    	//glLoadIdentity();
    	glOrtho(0.0, 3.0, 0.0, 3.0, -1.0, 1.0);
     
    }
     
    int main(int argc,char **argv)
    {
    	glutInit(&amp;argc,argv);
    	glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE);
    	//glutInitWindowSize(1600, 1600);
    	//glutInitWindowPosition(100, 100);
     
     
    	glutCreateWindow("hello");
    	glClearColor(1.0f,0.0f,0.0f,0.0f);
    	glClear(GL_COLOR_BUFFER_BIT);
    	init();
    	glutDisplayFunc(display);
    	//glClear(GL_COLOR_BUFFER_BIT);
    	//glutReshapeFunc(resize(100,200));
    	glutMainLoop();
    	return 0;
     
    }



    Thanks in advance
    gl_siddarth

  2. #2
    V-man
    Guest

    Re: how does glClearColor function works?

    I tested it and i got a red background with a blue polygon on it.

    How glClearColor works? It just sets the current clear color but you have to call glClear(GL_COLOR_BUFFER_BIT) for something to happen.

Similar Threads

  1. glClearColor and ARR[]
    By Olexandr in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-18-2013, 01:15 AM
  2. glClearColor
    By darren in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-27-2003, 01:25 PM
  3. glClearcolor() problem : I am not sure ??
    By Axiz in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-09-2002, 03:28 AM
  4. glClearColor
    By guju in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-20-2002, 12:22 PM
  5. glClearColor with Gradient
    By rks in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 01-02-2002, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean