I donât get what you are asking⌠would you like a simple glx based OpenGL program to play with?
If so, here is a very simple program that does not use glut, or anything else⌠Call the code below gltemplate.c if you are going to use the compile line I recommend in the comments. Also, the postings here sometimes mangles lines⌠so you may need to connect some lines in the code.
âBen
/*
- To compile use cc -o gltemplate gltemplate.c -lGL -L/usr/X11R6/lib -lX11
*/
#include <GL/glx.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <math.h>
#include <stdio.h>
Display *dpy;
Window window;
static Bool
WaitForMapNotify(Display *d, XEvent *e, XPointer arg)
{
return e->type == MapNotify && e->xmap.window == *(Window *) arg;
}
void
initialize(void)
{
int i;
XSetWindowAttributes swa;
XSizeHints hints;
XVisualInfo *vi = NULL;
XEvent ev;
GLXContext cx;
char title[256];
static int attr[] = {
GLX_RGBA,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_DEPTH_SIZE, 1,
GLX_STENCIL_SIZE, 0,
None,
};
dpy = XOpenDisplay(0);
if (dpy == NULL) {
fprintf(stderr, "Can't connect to display \"%s\"
",
getenv(âDISPLAYâ));
exit(1);
}
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attr);
if (vi == NULL) {
fprintf(stderr, "No matching visual on \"%s\"
",
getenv(âDISPLAYâ));
exit(1);
}
sprintf(title, "gltemplate");
swa.border_pixel = 0;
swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
vi->visual, AllocNone);
swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask
|
ButtonPressMask;
window = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 10, 10,
50, 50,
0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask,
&swa);
XStoreName(dpy, window, title);
hints.min_aspect.x = hints.min_aspect.y =
hints.max_aspect.x = hints.max_aspect.y = 1;
hints.min_aspect.x = hints.min_aspect.y =
hints.max_aspect.x = hints.max_aspect.y = 1;
hints.x = hints.y = 100;
hints.width = hints.height = 399;
hints.min_width = hints.min_height = 100;
hints.flags = PSize | PAspect | PPosition | PMinSize;
XSetNormalHints(dpy, window, &hints);
XMoveResizeWindow(dpy, window, 100, 100, 399, 399);
XMapWindow(dpy, window);
XIfEvent(dpy, &ev, WaitForMapNotify, (XPointer) &window);
if ((cx = glXCreateContext(dpy, vi, 0, GL_TRUE)) == NULL) {
fprintf(stderr, "Can't create context
");
exit(1);
}
if (!glXMakeCurrent(dpy, window, cx)) {
fprintf(stderr, "Canât make window current to context
");
exit(1);
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glDisable(GL_DEPTH_TEST);
}
void
usage()
{
fprintf(stderr,"Bad option
");
exit(1);
}
void
resize_window()
{
XWindowAttributes windowattr;
XGetWindowAttributes(dpy, window, &windowattr);
glViewport(0, 0, windowattr.width, windowattr.height);
}
void
drawScene(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
/* put all your opengl drawing stuff here⌠as in */
glColor3f(1.0, 1.0, 1.0);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFinish();
}
int
main(int argc, char *argv[])
{
XEvent event;
char buffer[5];
int bufsize = 5;
KeySym key;
XComposeStatus compose;
initialize();
drawScene();
while(GL_TRUE) {
while(XPending(dpy)) {
XNextEvent(dpy, &event);
switch(event.type) {
case ConfigureNotify:
resize_window();
drawScene();
break;
}
}
}
}