gl_siddarth
01-12-2012, 08:55 AM
I am new to openGL
I have written the code to display a polygon on the window
after that i have tried to clear the screen using glClearColor and glClear functions
The code i have written is
#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(&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);
glClearColor(0.0,1.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glutReshapeFunc(resize(100,200));
glutMainLoop();
return 0;
}
I am able to change the background color but i am unable to remove the polygon which i drew.
please help
Thanks in advance
gl_siddarth
I have written the code to display a polygon on the window
after that i have tried to clear the screen using glClearColor and glClear functions
The code i have written is
#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(&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);
glClearColor(0.0,1.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glutReshapeFunc(resize(100,200));
glutMainLoop();
return 0;
}
I am able to change the background color but i am unable to remove the polygon which i drew.
please help
Thanks in advance
gl_siddarth