PDA

View Full Version : openGL rendering problems in my plugin :(


gasol
June 11th, 2007, 05:21 PM
EDIT: Problem solved ^_^



I have some problems with being able to render simple openGL commands to a (X) window.

The functions in the plugin are called as they should be:

I have been building out the helloworld plugin and havent renamed all the functions yet...

helloworldPaintWindow is the function that gets called when the window should be redrawn.
In this function i have a small piece of openGL code:

If I have understood this correctly, this would first set the colour to red, and get the opacity value from the window.
The is pushes the matrix and moves to x and y (z = 0). Then it _should_ draw a little square. Then it pops the matrix and
restores the colour. But it wont show anything on the window i have created!


x = w->attrib.x + w->width;
y = w->attrib.y;

glColor4us(0xFFFF, 0, 0, w->lastPaint.opacity);
glPushMatrix();
glTranslatef(x, y, 0.0f);

glBegin(GL_QUADS);

glVertex3f( 5.0f, 5.0f, -5.0f);
glVertex3f( 5.0f, -5.0f, -5.0f);
glVertex3f(-5.0f, -5.0f, -5.0f);
glVertex3f(-5.0f, 5.0f, -5.0f);

glEnd();
glPopMatrix();

glColor4usv(defaultColor);



This is the code is use to create the window; so basicaly i create i window set some attributes and maps it.
The window shows up as completly black (as i should if there is nothing painted on it)
This code resides in the ScreenInit function.

hs->dock = XCreateSimpleWindow(dpy, s->root,
s->width - xsh.width, 0,
xsh.width, xsh.height, 0,0,0);

if(hs->dock < 0)
return FALSE;

state[nState++] = s->display->winStateAboveAtom;
state[nState++] = s->display->winStateStickyAtom;
state[nState++] = s->display->winStateSkipTaskbarAtom;
state[nState++] = s->display->winStateSkipPagerAtom;

XSetClassHint(dpy, hs->dock, &class_hints);

XChangeProperty (dpy, hs->dock,
s->display->winStateAtom,
XA_ATOM, 32, PropModeReplace,
(unsigned char *) state, nState);

XChangeProperty (dpy, hs->dock,
s->display->winTypeAtom,
XA_ATOM, 32, PropModeReplace,
(unsigned char *) &s->display->winTypeToolbarAtom, 1);


XMapWindow (dpy, hs->dock);



The main problem I have is that I haven't figured out how the coordinate system works when i want to draw on a window

As I have (mis?)understood the openGL coordinate system it works like this:


1.0f(y)
|
|
-1.0f(x) ------------ 1.0f (x)
|
|
-1.0f(y)
0.0f, 0.0f)

But how do this map onto a window? And what happens when i go negative on Z axis ?

Edit: And if use the AddwindowDamage(w) where w is my window, the paint function will just get called straight away since they seems to be creating some endless loop =/


I Would be very thankful for some help here
^_^

//Gasol