View Full Version : xwin, glut, opengl won't display triangle

05-20-2002, 03:07 PM
This program compiles and runs. The glut window appears with nothing but the xwindows background in it and it does not draw the triangle.
What am I doing wrong?

compiled with
gcc -o tri tri.c -L/usr/X11R6/lib -lglut -lGL -lGLU

#include <GL/gl.h>
#include <GL/glut.h>

void displayCB(void) /* function called whenever redisplay needed */
glClear(GL_COLOR_BUFFER_BIT); /* clear the display */
glColor3f(1.0, 1.0, 1.0); /* set current color to white */
glBegin(GL_POLYGON); /* draw filled triangle */
glVertex2i(200,125); /* specify each vertex of triangle */
glEnd(); /* OpenGL draws the filled triangle */
glFlush(); /* Complete any pending operations */

void keyCB(unsigned char key, int x, int y) /* called on key press */
if( key == 'q' ) exit(0);

int main(int argc, char *argv[])
int win;

glutInit(&argc, argv); /* initialize GLUT system */

glutInitWindowSize(400,500); /* width=400pixels height=500pixels */
win = glutCreateWindow("Triangle"); /* create window */

/* from this point on the current window is win */

glClearColor(0.0,0.0,0.0,0.0); /* set background to black */
gluOrtho2D(0,400,0,500); /* how object is mapped to window */ glClear(GL_COLOR_BUFFER_BIT); /* clear the display */
glutDisplayFunc(displayCB); /* set window's display callback */
glutKeyboardFunc(keyCB); /* set window's key callback */

glutMainLoop(); /* start processing events... */

/* execution never reaches this point */

return 0;

05-20-2002, 05:37 PM
Works for me, except I had to add -lm to the compile command-line.

This is on a Mandrake 8.3 (Cooker) system using a Matrox G450.

Are you sure you have GL set up correctly? Do the Mesa demos run as expected for you?

05-21-2002, 02:10 AM
I must not have Mesa configured correctly because I can't seem to compile the demos. make bounce tells me don't know how to make ../src-glu/libGLU.la Stop

when I gcc bounce.c directly and run, the window appears black but then nothing happens. cubemap core dumps.

I set LD_LIBRARY_PATH to /usr/X11R6/lib
does not affect anything at run time...

What else do I need to do to configure Mesa?