This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

linking cygwins glX (in libGL.a) with MS hardware opengl32 libraries


Hello all,

I?m having a few problems converting a program to use hardware accelerated opengl within cygwin.
I have trawled the web and your FAQ section but have not found anything that relates to using glX in cygwin with the opengl32 libraries. I apologise in advance if I have over looked a site or a previous inquiry.


To try and make things simple I have included some example code below which reproduces my problem. This example code opens a standard X window (no glut, I need to solve this without using glut) and draws a couple of polygons. Holding down a mouse button causes the polygons to revolve.

I can create a software cygwin opengl version of the main program which runs fine but the graphics are far too slow to be of any use. Compiling the example code below with the same options also results in a working cygwin software opengl version.

gcc -o softwaregl glexample.c -I/usr/X11R6/include -L/usr/X11R6/lib -lGLU -lGL -lXm -lXt -lX11

The GL headers are taken from /usr/X11R6/include which match the libgl.... from /usr/X11R6/lib


To use hardware opengl in cygwin I need to use the alternative libraries libopengl32 and libglu32 which are located in /lib/w32api or can be taken from the MS visual studio environment. These need the GL headers from /usr/include (not /usr/X11R6/include) to remove the unsatisfied links to the gl routines ending in @0, @4, @8 etc....


I then have a problem. These changes will result in unsatisfied links for all the glX calls. This is because the glX items were in the cygwin libGL library and the new windows libopengl32 contains wgl. To allow the program to satisfy all the links I still need to include libGL.

This is an example of the final call with ?lGL tagged on the end.

gcc -o hardwaregl glexample.c -I/usr/include -I/usr/X11R6/include -L/lib/w32api -L/usr/X11R6/lib -lglu32 -lopengl32 -lXm -lXt -lX11 ?lGL

The program will compile and run but with no graphics. I?m assuming this is due to the glX in libGL opening and setting the window and gl in libopengl32 drawing to an area it knows nothing about.

How can I cure this problem? If someone can demonstrate how I would get the example code below working with hardware graphics I would be grateful. (Just to complicate things a little further, the main program also uses LibGLw which requires a link to the glX in libGL ? Example: GLwM2DrawA.c undefined reference to _glXChooseVisual)

With thanks
Steve.K.


/*build with


software
gcc -o softwaregl glexample.c -I/usr/X11R6/include -L/usr/X11R6/lib -lGLU -lGL -lXm -lXt -lX11


hardware
gcc -o hardwaregl glexample.c -I/usr/include -I/usr/X11R6/include -L/lib/w32api -L/usr/X11R6/lib -lglu32 -lopengl32 -lXm -lXt -lX11 -lGL


*/
#include <stdio.h>
#include <GL/glx.h>
#include <GL/glu.h>

static int attributeList[] = { GLX_RGBA,
                           GLX_RED_SIZE, 1,
                           GLX_GREEN_SIZE, 1,
                           GLX_BLUE_SIZE, 1,
                           GLX_DOUBLEBUFFER,
                           GLX_DEPTH_SIZE, 16,
                           None };

static void initgfx(void);
static void setsize(int width, int height);
static void drawit(void);
static void checkerrors(void);

Display* dpy;
Window win;
GLXContext cx;
int width, height;
GLfloat spin,xaxis, yaxis, zaxis;

int main(int argc, char **argv) {
   XVisualInfo* vi;
   Colormap cmap;
   XSetWindowAttributes swa;
   XEvent event;
   XButtonEvent* button;
   XKeyEvent* key;
   XMotionEvent* motion;
   XExposeEvent* expose;
   XConfigureEvent* config;
   char s[100];
   int i;

   /* get a connection */
   dpy = XOpenDisplay(0);

   /* get an appropriate visual */
   vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);

   /* create a GLX context */
   cx = glXCreateContext(dpy, vi, 0, GL_TRUE);

   /* create a color map */
   cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
                          vi->visual, AllocNone);

   /* create a window */
   swa.colormap = cmap;
   swa.border_pixel = 0;
   swa.event_mask = StructureNotifyMask;
   width = 300;
   height = 300;
   win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, width,
height,                        0, vi->depth, InputOutput, vi->visual,
                       CWBorderPixel|CWColormap|CWEventMask, &swa);
   XMapWindow(dpy, win);

   /* add program name to window banner */
   XStoreName(dpy, win, "Knight GL example");

   /* prepare for event loop */
   button = (XButtonEvent*)(&event);
   key = (XKeyEvent*)(&event);
   motion = (XMotionEvent*)(&event);
   expose = (XExposeEvent*)(&event);
   config = (XConfigureEvent*)(&event);
   XSelectInput(dpy, win, KeyPressMask |
                          ButtonPressMask |
                          ButtonReleaseMask |
                          Button1MotionMask |
                          Button2MotionMask |
                          ExposureMask |
                          StructureNotifyMask);

   /* loop handling events */
   while (1) {


int oldx, oldy, deltax, deltay; spin=spin+1.0; drawit();


XNextEvent(dpy, &event); switch (event.type) { case KeyPress: i = XLookupString(key, s, 100, NULL, NULL); if (i) { switch ((int)(s[0])) { case 033: exit(0); break; default: s[i] = 0; printf("%s, %d\n", s, i); break; } } break; case ButtonPress: printf("%d button pressed\n", button->button); break; case ButtonRelease: printf("%d button released\n", button->button); break; case MotionNotify: printf("%3d,%3d tracking\n", motion->x, motion->y); deltax=oldx-motion->x; deltay=oldy-motion->y; if((deltax>0)&&(deltay>0)) { yaxis=1.0; xaxis=0.0;zaxis=0.0; } /*elseif ((diffx<0)&&(diffy<0)) { yaxis=0.0; xaxis=1.0;zaxis=0.0; }*/ oldx=motion->x; oldy=motion->y;

               break;
           case Expose:
                printf("expose %d\n", expose->count);
                printf("  x=%d, y=%d\n", expose->x, expose->y);
                printf("  width=%d, height=%d\n",
                     expose->width, expose->height);
               if (expose->count == 0) {
                   initgfx();
                   drawit();
               }
               break;
           case ConfigureNotify:
               width = config->width;
               height = config->height;
               initgfx();
               setsize(width, height);
               drawit();
               break;

}

   }
}

static void initgfx(void) {
   static done = 0;
   if (!done) {
       done = 1;
       glEnable(GL_DEPTH_TEST);
   	glDepthFunc(GL_LEQUAL);
   	glClearColor(0.0, 0.0, 0.0, 0.0);
   	glClearDepth(1.0);
       glXMakeCurrent(dpy, win, cx);
       glClearColor(0,0,0,1);
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
	/*glOrtho(0, 1, 0, 1, -1, 1);*/
   }
}

static void setsize(int width, int height) {
   glViewport(0, 0, width, height);
}

static void drawit(void) {



   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   gluPerspective(40.0, 1.0, 10.0, 200.0);

glTranslatef(0.0, 0.0, -50.0);

glRotatef(spin, xaxis, yaxis, zaxis);

   glBegin(GL_POLYGON);
   glColor3f(0.0, 0.0, 0.0); glVertex3f(-10.0, -10.0, 0.0);
   glColor3f(0.7, 0.7, 0.7); glVertex3f(10.0, -10.0, 0.0);
   glColor3f(1.0, 1.0, 1.0); glVertex3f(-10.0, 10.0, 0.0);
   glEnd();
   glBegin(GL_POLYGON);
   glColor3f(1.0, 1.0, 0.0); glVertex3f(0.0, -10.0, -10.0);
   glColor3f(0.0, 1.0, 0.7); glVertex3f(0.0, -10.0, 10.0);
   glColor3f(0.0, 0.0, 1.0); glVertex3f(0.0, 5.0, -10.0);
   glEnd();
   glBegin(GL_POLYGON);
   glColor3f(1.0, 1.0, 0.0); glVertex3f(-10.0, 6.0, 4.0);
   glColor3f(1.0, 0.0, 1.0); glVertex3f(-10.0, 3.0, 4.0);
   glColor3f(0.0, 0.0, 1.0); glVertex3f(4.0, -9.0, -10.0);
   glColor3f(1.0, 0.0, 1.0); glVertex3f(4.0, -6.0, -10.0);
   glEnd();

   glBegin(GL_LINES);
   glColor3f(1.0, 0.0, 0.0); glVertex3f(-10.0, -10.0, 0.0);
   glColor3f(1.0, 0.0, 0.0); glVertex3f(10.0, -10.0, 0.0);
   glColor3f(1.0, 0.0, 0.0); glVertex3f(-10.0, 10.0, 0.0);
   glEnd();

   glBegin(GL_LINES);
   glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, -10.0, -10.0);
   glColor3f(1.0, 0.0, 0.7); glVertex3f(0.0, -10.0, 10.0);
   glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 5.0, -10.0);
   glEnd();

   glBegin(GL_LINES);
   glColor3f(1.0, 0.0, 0.0); glVertex3f(-10.0, 6.0, 4.0);
   glColor3f(1.0, 0.0, 0.0); glVertex3f(-10.0, 3.0, 4.0);
   glColor3f(1.0, 0.0, 0.0); glVertex3f(4.0, -9.0, -10.0);
   glColor3f(1.0, 0.0, 1.0); glVertex3f(4.0, -6.0, -10.0);
   glEnd();


glXSwapBuffers(dpy, win);


   glFlush();
   checkerrors();
}

static void checkerrors(void) {
   int i;
   int goterror;

   goterror = 0;
   while (i = glGetError()) {
       goterror = 1;
       fprintf(stderr, "ERROR: 0x%x\n", i);
       fprintf(stderr, "       %s\n", gluErrorString(i));
   }
   if (goterror)
       exit(1);
}

_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger http://www.msn.co.uk/messenger



-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]