I just started programming OpenGL for a couple of weeks now, and I’m starting to understand the concepts behind clipping volume, viewports, and vertex. I started on a simple exercise today which consisted of printing out a simple 2D circle on a window. The program compiled with no errors, but the window contained no drawing contents. Instead a transparent image of what is behind the window is drawn into the window itself. I’m confused as to why this happened? Can anybody give me an explanation? I posted the code below. Thanx.
#include<windows.h>
#include<gl/glut.h>
#include<math.h>
void RenderScene();
void ChangeSize(GLsizei w, GLsizei h);
void SetupRC();
void main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow(“Circle”);
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
SetupRC();
glutMainLoop();
}
void RenderScene()
{
GLfloat x, y, angle;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
for(angle = 0.0f; angle <= 6.2832f; angle += 0.1f)
{
x = 50.0f * sin(angle);
y = 50.0f * cos(angle);
glVertex3f(x, y, 0.0f);
}
glEnd();
glFlush();
}
void ChangeSize(GLsizei w, GLsizei h)
{
GLfloat range = 100.0f;
if (h == 0)
h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w <= h)
glOrtho(-range, range, -range * h/w, range * h/w, -range, range);
else
glOrtho(-range * w/h, range * w/h, -range, range, -range, range);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glColor3f(0.0f, 0.0f, 1.0f);
}