LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-05-2006, 07:27 AM   #1
Waldemar Ciperovich
LQ Newbie
 
Registered: May 2006
Posts: 14

Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
(II) [GLX]: Initializing GLX extension - X wont go hydro Linux - Software 3 02-20-2003 06:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration