Drawing Open GL in an arbitrary window

I am trying to have OpenGL draw inside a tcl window without using any
special TCL widget like togl. My basic question is this:
I am using modified code from NeHe tutorials to setup my window on a linux
box. I want to be able to pass these functions information like the window
handle, etc. which I have taken from an already created window in tcl. What
information do I need to get from tcl and to which variables do I set that
information. Here is the Xinit, I am using. I am not using glut.

Thanks Seth

PS maybe someone could explain to me what an atom is :slight_smile:

#include <X11/Xlib.h> // Standard X header for X libraries
#include <X11/Xatom.h> // Header to provide X’s Atom functionality
#include <X11/keysym.h> // Header to provide keyboard functionality under X
#include <GL/gl.h> // Header File For The OpenGL32 Library
#include <GL/glx.h> // Header File For The X library for OpenGL
#include <GL/glu.h> // Header File For The GLu32 Library
#include <stdio.h> // Standard I/O routines

Atom wmDeleteWindow; // Custom message to Delete Window
Display *dpDisplay; // Display variable
Window win; // Current Window variable

void xInitWindow(int *argv, char **argc)
{
XVisualInfo *xvVisualInfo;
Colormap cmColorMap;
XSetWindowAttributes winAttributes;
GLXContext glXContext;

/* Open the Display */
dpDisplay = XOpenDisplay(NULL);
if(dpDisplay == NULL)
{
printf(“Could not open display!
\r”);
exit(0);
}

/* Check for GLX extension to X-Windows */
if(!glXQueryExtension(dpDisplay, NULL, NULL))
{
printf(“X server has no GLX extension.
\r”);
exit(0);
}

/* Grab a doublebuffering RGBA visual as defined in dblBuf */
xvVisualInfo = glXChooseVisual(dpDisplay, DefaultScreen(dpDisplay),
dblBuf);
if(xvVisualInfo == NULL)
{
printf(“No double buffering RGB visual with depth buffer
available.
\r”);
exit(0);
}

/* Create a window context */
glXContext = glXCreateContext(dpDisplay, xvVisualInfo, None, True);
if(glXContext == NULL)
{
printf(“Could not create rendering context.
\r”);
exit(0);
}

/* Create the color map for the new window */
cmColorMap = XCreateColormap(dpDisplay, RootWindow(dpDisplay,
xvVisualInfo->screen), xvVisualInfo->visual, AllocNone);
winAttributes.colormap = cmColorMap;
winAttributes.border_pixel = 0;
winAttributes.event_mask = ExposureMask | ButtonPressMask |
StructureNotifyMask |
KeyPressMask;

/* Create the actual window object */
win = XCreateWindow(dpDisplay,
RootWindow(dpDisplay, xvVisualInfo->screen),
0,
0,
640, // Horizontal Size
480, // Veritical Size
0,
xvVisualInfo->depth,
InputOutput,
xvVisualInfo->visual,
CWBorderPixel | CWColormap | CWEventMask,
&winAttributes);

/* Set the standard properties for the window. */
XSetStandardProperties(dpDisplay,
win,
“Read from File”,
“lesson3”,
None,
(char **) argv,
(int) argc,
NULL);

/* Establish new event */
wmDeleteWindow = XInternAtom(dpDisplay, “WM_DELETE_WINDOW”, False);
XSetWMProtocols(dpDisplay, win, &wmDeleteWindow, 1);

/* Bind the OpenGL context to the newly created window. */
glXMakeCurrent(dpDisplay, win, glXContext);

/* Make the new window the active window. */
XMapWindow(dpDisplay, win);
}