LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   GLX Programming (https://www.linuxquestions.org/questions/linux-software-2/glx-programming-489655/)

Waldemar Ciperovich 10-05-2006 07:27 AM

GLX Programming
 
* OpenGL example using only Xlib and GLX.

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <GL/glx.h>
#include <GL/gl.h>

#include <sys/select.h>
#include <sys/types.h>
#include <sys/time.h>

int /* O - Exit status */
main(int argc, /* I - Number of command-line args */
char *argv[]) /* I - Command-line args */
{
Bool mapped; /* Is the window mapped? */
GLXContext context; /* OpenGL context */
Display *display; /* X display connection */
Window window; /* X window */
XVisualInfo *vinfo; /* X visual information */
XSetWindowAttributes winattrs; /* Window attributes */
int winmask; /* Mask for attributes */
XEvent event; /* Event data */
XWindowAttributes windata; /* Window data */
struct timeval timeout; /* Timeout interval for select() */
fd_set input; /* Input set for select() */
int ready; /* Event ready? */
static int attributes[] = /* OpenGL attributes */
{
GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_DEPTH_SIZE, 16,
0
};
display = XOpenDisplay(getenv("DISPLAY"));

vinfo = glXChooseVisual(display, DefaultScreen(display), attributes);

winattrs.event_mask = ExposureMask | VisibilityChangeMask |
StructureNotifyMask | ButtonPressMask |
ButtonReleaseMask | PointerMotionMask;
winattrs.border_pixel = 0;
winattrs.bit_gravity = StaticGravity;
winmask = CWBorderPixel | CWBitGravity | CWEventMask;

window = XCreateWindow(display, DefaultRootWindow(display),
0, 0, 774, 588, 0, vinfo->depth, InputOutput,
vinfo->visual, winmask, &winattrs);

XChangeProperty(display, window, XA_WM_NAME, XA_STRING, 8, 0,
(unsigned char *)argv[0], strlen(argv[0]));
XChangeProperty(display, window, XA_WM_ICON_NAME, XA_STRING, 8, 0,
(unsigned char *)argv[0], strlen(argv[0]));

XMapWindow(display, window);

/*
* Create the OpenGL context...
*/

context = glXCreateContext(display, vinfo, 0, True);
glXMakeCurrent(display, window, context);
--------------------------------------------------------------------------
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 1 (X_CreateWindow)
Serial number of failed request: 12
Current serial number in output stream: 16


All times are GMT -5. The time now is 05:37 AM.