PDA

View Full Version : Where's the drawing contents



danny1238
04-17-2001, 02:47 AM
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);
}

vrempire
04-17-2001, 03:25 AM
hi danny..
well,ermm..
in the void RenderScene() ,
I can't see any functions to do modelview, set projection etc..
try to put the glMatrixMode(GL_MODELVIEW), glMatrixMode(GL_PROJECTION) etc, like you put in the reshape function inside the display function.well, just try the luck.
hope that it will work...

SurGL
04-17-2001, 03:36 AM
Since you are using Double buffer , you need to call glutSwapBuffers();at the end of RenderScene() function.

FoxDie
04-17-2001, 04:49 AM
Why you using glut?
Use GLAUX.
The glut is *****. http://www.opengl.org/discussion_boards/ubb/wink.gif

danny1238
04-18-2001, 10:47 AM
Thanx SurGL. I should've replaced glFlush() with glutSwapBuffers because of the DOUBLE_BUFFER parameter within the display mode.

zed
04-18-2001, 05:48 PM
from the faq

2.130
What is the AUX library?
Very important: Don't use AUX. Use GLUT instead.
The AUX library was developed by SGI early in OpenGL's
life to ease creation of small OpenGL demonstration programs.
It's currently neither supported nor maintained. Developing
OpenGL programs using AUX is strongly discouraged. Use the
GLUT instead. It's more flexible and powerful and is
available on a wide range of platforms.