Acme-MITHALDU-BleedingOpenGL
view release on metacpan or search on metacpan
pogl_gl_top.xs view on Meta::CPAN
int
__had_dbuffer_hack()
#ifdef HAVE_GLpc /* GLX */
#// $ID = glpcOpenWindow($x,$y,$w,$h,$pw,$steal,$event_mask,@attribs);
HV *
glpcOpenWindow(x,y,w,h,pw,event_mask,steal, ...)
int x
int y
int w
int h
int pw
long event_mask
int steal
CODE:
{
XEvent event;
Window pwin = (Window)pw;
unsigned int err;
int *attributes = default_attributes + 1;
int *a_buf = NULL;
RETVAL = newHV(); /* Create hash to return GL Object info */
if(items > NUM_ARG){
int i;
a_buf = (int *) malloc((items-NUM_ARG+2) * sizeof(int));
a_buf[0] = GLX_DOUBLEBUFFER; /* Preallocate */
attributes = a_buf + 1;
for (i=NUM_ARG; i<items; i++) {
attributes[i-NUM_ARG] = SvIV(ST(i));
}
attributes[items-NUM_ARG] = None;
}
if (debug) {
int i;
for (i=0; attributes[i] != None; i++) {
printf("att=%d %d\n", i, attributes[i]);
}
}
/* get a connection */
if (!dpy_open) {
dpy = XOpenDisplay(NULL);
dpy_open = 1;
}
if (!dpy) {
croak("ERROR: failed to get an X connection");
} else if (debug) {
printf("Display open %x\n", dpy);
}
/* get an appropriate visual */
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributes);
if (!vi) { /* Might have happened that one does not
* *need* DOUBLEBUFFER, but the display does
* not provide SINGLEBUFFER; and the semantic
* of GLX_DOUBLEBUFFER is that if it misses,
* only SINGLEBUFFER visuals are selected. */
attributes--; /* GLX_DOUBLEBUFFER preallocated there */
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributes); /* Retry */
if (vi)
DBUFFER_HACK = 1;
}
if (a_buf)
free(a_buf);
if(!vi) {
croak("ERROR: failed to get an X visual\n");
} else if (debug) {
printf("Visual open %x\n", vi);
}
/* A blank line here will confuse xsubpp ;-) */
#ifdef HAVE_GLX
/* create a GLX context */
ctx = glXCreateContext(dpy, vi, 0, GL_TRUE);
if (!ctx) {
croak("ERROR: failed to get an X Context");
} else if (debug) {
printf("Context Created %x\n", ctx);
}
/* 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 = event_mask;
#endif /* defined HAVE_GLX */
if (!pwin) {
pwin = RootWindow(dpy, vi->screen);
if (debug) printf("Using root as parent window 0x%x\n", pwin);
}
if (steal) {
win = nativeWindowId(dpy, pwin); /* What about depth/visual */
} else {
win = XCreateWindow(dpy, pwin,
x, y, w, h,
0, vi->depth, InputOutput, vi->visual,
CWBorderPixel|CWColormap|CWEventMask, &swa);
/* NOTE: PDL code had CWBackPixel above */
}
if (!win) {
croak("No Window");
} else {
if (debug) printf("win = 0x%x\n", win);
}
XMapWindow(dpy, win);
#ifndef HAVE_GLX /* For OS/2 GLX emulation stuff -chm 2009.09.14 */
/* On OS/2: cannot create a context before mapping something... */
/* create a GLX context */
ctx = glXCreateContext(dpy, vi, 0, GL_TRUE);
if (!ctx)
croak("No context!\n");
LastEventMask = event_mask;
( run in 0.731 second using v1.01-cache-2.11-cpan-4e7a2411597 )