Problems compiling sample OpenGL apps .

Karel Miklav karel.miklav at siol.net
Mon Nov 1 02:36:38 PST 2004


Some example apps. that work perfectly under Mandrake are not built
properly in FreeBSD 5.3 RC1 / X.Org. All I get is a window filled with
whatever was behind it.

Glxgears run well, everything is compiled and linked without any
problem. If I play with the order of GL libraries linked, there is some
improvement, but the display is garbled and there's no animation.

Anybody have any idea what am I doing wrong?

--

Regards,
Karel

--

> cat hello.c
#include <GL/glut.h>

void display(void)
{
    // clear all pixels
    glClear (GL_COLOR_BUFFER_BIT);

    //draw white polygon
    glColor3f (1.0, 1.0, 1.0);
    glBegin(GL_POLYGON);
       glVertex3f (0.25, 0.25, 0.0);
       glVertex3f (0.75, 0.25, 0.0);
       glVertex3f (0.75, 0.75, 0.0);
       glVertex3f (0.25, 0.75, 0.0);
    glEnd();

    // don't wait, start processing buffered OpenGL routines
    glFlush ();
}

void init (void)
{
    // select clearing color
    glClearColor (0.8, 0.0, 0.0, 0.0);

    // initialize viewing values
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int argc, char * argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (250, 250);
    glutInitWindowPosition (100, 100);
    glutCreateWindow ("hello");

    init ();

    glutDisplayFunc(display);
    glutMainLoop();

    return 0;
}




> cat makefile
CC = gcc
INCLUDES = -I/usr/include
LLDLIBS = -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm -L/usr/X11R6/lib

TARGETS = hello

all: default

default: $(TARGETS)

.c.o:
	$(CC) -c $(INCLUDES) $<

$(TARGETS): $$@.o
	$(CC) $@.o $(LLDLIBS) -o $@

clean:
	-rm -f *.o *~ $(TARGETS)



More information about the freebsd-questions mailing list