PDA

View Full Version : Transparent Problem in OpenGL - X11/xfce4



xyzv.net
02-09-2012, 12:59 AM
Im working on a screen overlay in C++ with opengl, having an issue with window transparency & rendering polygons. This is done in xfce4.

Its a standard window, with one modification to show the background as transparent.
XMatchVisualInfo(dpy, DefaultScreen(dpy), 32, TrueColor, vi);

The problem is that I am trying to render 2 solid squares, the second is showing through the previously drawn rect and showing the background....
http://i42.tinypic.com/a44pwp.png

The first quad is rendered with color:
glColor4ub(255,255,255,0);
The second is rendered with:
glColor4ub(255,0,255,0);

I can't figure out why the second QUAD is drawn as transparent, regardless of the 4th argument to glColor4, it has no effect. If the R,G,B vals are not set to 255, the render becomes partially transparent.

Has anyone got any ideas as to what im missing here...


#include <X11/Xlib.h>
#include <cstdlib>
#include <GL/glx.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <unistd.h>
#include <iostream>

#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092

typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*);




void renderGL() {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor( 0.0, 0.0, 0.0,0.0f) ;

glLoadIdentity();
glOrtho( 0, 1024,768, 0, -1, 1 );


glClearColor(0,0,0,0);
int x = 50;
int y = 50;
int w = 200;
int h = 200;

glColor4ub(255,255,255,0);
glBegin (GL_QUADS);
glVertex3f (x-3, y-3, 0.0);
glVertex3f (w+x+3, y-3, 0.0);
glVertex3f (w+x+3, h+y+3, 0);
glVertex3f (x-3, h+y+3, 0);
glEnd ();

x+=50;
y+=50;

glColor4ub(255,0,255,266);
glBegin (GL_QUADS);
glVertex3f (x-3, y-3, 0.0);
glVertex3f (w+x+3, y-3, 0.0);
glVertex3f (w+x+3, h+y+3, 0);
glVertex3f (x-3, h+y+3, 0);
glEnd ();
}



int main (int argc, char ** argv){
Display *dpy = XOpenDisplay(0);

int nelements;
GLXFBConfig *fbc = glXChooseFBConfig(dpy, DefaultScreen(dpy), 0, &amp;nelements);

static int attributeList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, None };
XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy),attributeList);
XMatchVisualInfo(dpy, DefaultScreen(dpy), 32, TrueColor, vi);
XSetWindowAttributes swa;
swa.colormap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
swa.border_pixel = 0;

swa.background_pixmap = None ;
swa.event_mask = StructureNotifyMask;
Window win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1024,768, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &amp;swa);

XMapWindow (dpy, win);

//oldstyle context:
// GLXContext ctx = glXCreateContext(dpy, vi, 0, GL_TRUE);

std::cout << "glXCreateContextAttribsARB " << (void*) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB") << std::endl;
GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (GLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");

int attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
0};

GLXContext ctx = glXCreateContextAttribsARB(dpy, *fbc, 0, true, attribs);

glXMakeCurrent (dpy, win, ctx);
renderGL();
glXSwapBuffers (dpy, win);

sleep(5);

ctx = glXGetCurrentContext();
glXDestroyContext(dpy, ctx);
}