PDA

View Full Version : I'm having trouble displaying a polygon...



Fredric
04-09-2000, 04:13 PM
I'm at the point in my OpenGL book where the author explains how to plot points on the screen and make a polygon. I tried, for myself, to display a polygon in a window with the following code:

#include 'windows.h'
#include 'gl/gl.h'
#include 'gl/glaux.h'
#include 'conio.h'

void CALLBACK DrawScene()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //r,g,b,a
glClear(GL_COLOR_BUFFER_BIT);


glBegin(GL_POLYGON); // begin drawing the square
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.0, 0.0);
glVertex2f(50.0, 0.0);
glVertex2f(50.0, 50.0);
glVertex2f(0.0, 5.0);
glEnd();

glFlush(); // force drawing
}

void main()
{
auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
auxInitPosition(100,100,250,250);
auxInitWindow("A simple square");


auxMainLoop(DrawScene);

cprintf("Push any key to close the coloured window...\n");
getch();
}
I get no compile-time errors, and the application runs fine. It opens the window, but it doesn't display the polygon that I defined in the code. Can anyone help me out here?

dmy
04-09-2000, 04:29 PM
seems like you didn't setup the projection matrix...

try to add these lines after glClear:




glViewport(0,0,150,150);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100,+100,-100,+100);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();



Dolo/\/\ightY

Fredric
04-09-2000, 05:04 PM
I linked glu32.lib to the project, included glu.h in the preprocessor, added the code that you gave me, but it still does not display my square... http://www.opengl.org/discussion_boards/ubb/frown.gif I'm using VC++ 6.0 if that makes any sort of difference...

04-18-2000, 05:06 PM
Try moving back

glTranslated(0,0,-1);

04-20-2000, 11:58 AM
Originally posted by Fredric:
I'm at the point in my OpenGL book where the author explains how to plot points on the screen and make a polygon. I tried, for myself, to display a polygon in a window with the following code:

#include 'windows.h'
#include 'gl/gl.h'
#include 'gl/glaux.h'
#include 'conio.h'

void CALLBACK DrawScene()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //r,g,b,a
glClear(GL_COLOR_BUFFER_BIT);


glBegin(GL_POLYGON); // begin drawing the square
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(0.0, 0.0);
glVertex2f(50.0, 0.0);
glVertex2f(50.0, 50.0);
glVertex2f(0.0, 5.0);
glEnd();

glFlush(); // force drawing
}

void main()
{
auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
auxInitPosition(100,100,250,250);
auxInitWindow("A simple square");


auxMainLoop(DrawScene);

cprintf("Push any key to close the coloured window...\n");
getch();
}
I get no compile-time errors, and the application runs fine. It opens the window, but it doesn't display the polygon that I defined in the code. Can anyone help me out here?


Hello mate I was looking at your code, some thing puzzled me why are you using single quotes around your includes??, also if you are using AUX, then it should not be any trouble for you to use GLUT, just re-write the code in GLUT that's what I use, I have VC++ 4.0, yes (ooolllddd), and my codes work fine actually I'm going to get the new VC++ 6.0 soon, but anyway the code looks fine just try using GLUT instead...