PDA

View Full Version : Pixmap to OpenGL



bobGL
04-04-2006, 09:51 PM
How to load a Pixmap into an OpenGL Texture:

Picture picture;
Pixmap dest;
XWindowAttributes temp_attr;

...
...

picture = XRenderCreatePicture(desktop->dpy1, children[i], format, CPSubwindowMode, &pa);

XRenderComposite(desktop->dpy1, hasAlpha ? PictOpOver : PictOpSrc, picture, None, dest, 0, 0, 0, 0, 0, 0, temp_attr.width, temp_attr.height);


glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

GLuint texName;
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, temp_attr.width, temp_attr.height, GL_RGB, GL_UNSIGNED_BYTE, &dest->data); // Crash Here

jide
04-05-2006, 08:35 AM
As for all textures you'll have to get the information contained in the pixmap (red,green,blue and alpha values). Don't know how to do that.

RigidBody
04-05-2006, 10:12 AM
try XGetImage:

XImage *XGetImage(Display *display, Drawable d, int x, int y, unsigned int width, unsigned int height, unsigned long plane_mask, int format);

Drawable d is the Pixmap's XID.

once you have the XImage, you can use XGetPixel to get access to its pixels. or you can just take a look at the XImage structure definition in Xlib.h

bobGL
04-05-2006, 07:04 PM
err... can't make it work...

Can you write me an example from the code above...

Tks,

RigidBody
04-07-2006, 03:49 AM
EDIT: i posted an example here which might cause
trouble on run-time because no colormap is created.
if it works on your computer, good for you :p , but
if not: go to the opengl wiki:

Main Page/Platform specifics/Linux/Programming/Creating a texture from a bitmap

(and please let me know if it runs on your computer without problems...)