Hi, I am trying to make an opengl application in cygwin that simply draws lines. It is a mess.
The only thing that remotly works is freeglut. It brings up a window… glx.h doesn’t even appear to exist and it won’t link if I try to use regular glut.
The only things that work are freeglut specific things like drawing the predefined teapot or cube.
Lines don’t show up.
glClearColor() causes the window to go black with a few pixels lit up with random colors here and there.
#define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \
glVertex2f((x1), (y1)); glVertex2f((x2),(y2));glEnd();
//drawing out the lines
//the main function
int main(int argc, char** argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
I use this to compile and link -
gcc gluttest.c -L /usr/X11R6/lib -lX11 -lXm -lXmu -lXext -lglut -lglu32 -lopengl32 -o test.exe
The output is a window with a black backround with randomly lit up pixels here and there. Is there something wrong with the libraries I’m using?
I guess that your code has some problems.
1.Values specified by glClearColor are clamped to the range [0,1].So use from the values between 0 and 1.
2.At the beginning of your display function, you should clear the color buffer:
glClear( GL_COLOR_BUFFER_BIT );
3.You should create a reshape function and specify the projection matrix and your viewport.As an example, you can use from the following code:
void reshape( int width, int height )
glViewport( 0,0, width, height );
glMatrixMode( GL_PROJECTION );
gluOrtho2D( -200, 200, -200, 200 );
glMatrixMode( GL_MODELVIEW );
And then in your main funcion , add this call after creating the window:
glutReshapeFunc( reshape );
4.When you use from the double buffering, you should specify an idle function. So you can use from the following funcion:
glutPostRedisplay( display );
and then in your main function, add the following function:
glutIdleFunc( Idle );
Code problems aren’t an issue, though I made the changes you recommended. It does compile and run in windows with vc++ and looks exactly like it is supposed to.
Under cygwin, it just doesn’t do it. Right now it compiles and links, when you run it nothing happens - at all - not even a window comes up.
OK, for anyone who runs into this looking for help in a search…
You need to bring up the xwindow using “startxwin.bat” instead of using “startx” or “xinit”. Strangely now I get errors when trying to use startx… Oh well startxwin.bat works.
freeglut I never got working, but using regular glut it compiles and runs fine in cygwin using
gcc gluttest.c -lglut32 -lglu32 -lopengl32 -o test.exe
Wow. I love these sort of problems.
It shouldn’t be neccesary to start X to use OpenGL on Cygwin, neither should you have to use glx. You should use wgl, just the same as you would do with VS.
I never actually tried glut with cygwin, but with SDL I get a normal windows window without code changes between VS, Cygwin, Mingw32 and Linux-GCC (except the usual compiler differences).