Pixmap to OpenGL

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

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.

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

err… can’t make it work…

Can you write me an example from the code above…

Tks,

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 :stuck_out_tongue: , 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…)

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.