PDA

View Full Version : OpenGl and cygwin???



Jackal
07-20-2005, 10:25 AM
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.




#include "/usr/X11R6/include/GL/freeglut.h"

#define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \
glVertex2f((x1), (y1)); glVertex2f((x2),(y2));glEnd();

//drawing out the lines
void display()
{
glClearColor(50.0,100.0,200.2,0.0);

drawOneLine(0,0,200,200);

glutSwapBuffers();
}

//the main function
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 150);
glutInitWindowPosition(100, 100);
glutCreateWindow("Test");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
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?

Ehsan Kamrani
07-20-2005, 09:49 PM
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 );
glLoadIdentity();
gluOrtho2D( -200, 200, -200, 200 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}

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:
void Idle()
{
glutPostRedisplay( display );
}

and then in your main function, add the following function:
glutIdleFunc( Idle );

-Ehsan-

Jackal
07-21-2005, 07:41 AM
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.

Jackal
07-21-2005, 09:00 AM
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.

Overmind
07-21-2005, 11:06 AM
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).