x to gL ?

Hi, I am trying to make just a simple GL program that will put a pixmap on top of a pixmap background.

I have a function that will read a sun raster image from file, and I’m using it to make my backgroud. It works and here is the stubbed code:

//Create my window

win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
win_x, win_y, width, height,
win_border_width,
BlackPixel(display, screen_num),
WhitePixel(display, screen_num));

//In this next function, readraster reads the image and
//makes it into a pixmap it returns a Pixmap * map, and
//it’s width, height, and depth…

readraster(display,“sea.im1”, &wide, &high, &deep, &map);

//this next block renders the image into my background

XSetWindowBackgroundPixmap(display,win,map);
gcval.tile = map;
gc = XCreateGC(display, win, GCTile, &gcval);
XCopyArea(display,map,win,gc,0,0,wide,high,0,0);
XClearArea(display,win,0,0,wide,high, FALSE);

//since I want to learn GL instead of X, I tried doing
//this next block so as to put a little pixmap ontop of
//my background, but get an error where I’ve put ‘map’
//in the glDrawPixel function. [Map is a pixmap]

readraster(display,“suf.im1”, &wide, &high, &deep,&map);
glRasterPos2i(200,200);
glDrawPixels(wide, high, GL_UNSIGNED_BYTE_3_3_2, GL_RGB, map);
glFlush();

Any code suggestions?

Assuming that the GL_UNSIGNED_BYTE_3_3_2 part is correct,if map is a pixmap then it’s propably not RGB data but indices into a colormap.If this is correct(I don’t know anything about the sun raster format or how you load it) you have to get the current colormap and use each index to get the actual RGB color.But you’re better of reading something like a tga file where you can get RGB(or rather BGR) data directly.

Zen;

I probably shouldn’t have posted the GL code as I am completely guessing as to what goes in there. I am completely new to all of this and the readraster file is something I found on the net. From what I’ve been reading though, it does appear I’m using just RGB data, but I’m not sure.

So to rephrase my question, if I have a function as above that has turned a raster file into a pixmap, what GL function calls should I use to get it on the screen? Does GL even support doing this?

I have the red book and it gets real confusing on this (plus I’m mixing X with it as well which probably isn’t helping). But I read again about tga.

Thanks,

-Markus

I think X doesn’t use true color formats but colormaps and indices into them.So if map is a pixmap(and it is since you feed it to XSetWindowBackgroundPixmap
() it doesn’t contain actual RGB data.Therefore opengl can’t load a pixmap immediately(unless it is possible through glx).Now if you’re just experimenting you shouldn’t use X more than absolutely nescessary(you could even bypass it to begin with using glut) unless you wan’t to get frustrated quickly and give up.Mixing X rendering and opengl rendering isn’t a good idea anyway(at least I don’t know of any reason to do it).So if you want to learn opengl go to nehe.gamedev.net and do the first tutorials.They’ll help you a lot to learn the basics.If you insist on loading a file and rendering it’s contents there are tutorials there to load bmps and tgas.After doing them you’ll understand enough to pick up the specs of most formats and write a loader yourself(although tga files are quite good).If you insist on using the sun raster file and this specific readraster() function I don’t know a thing about,then I can’t help you much.

I think Zen assumes that you know how to setup a OpenGL window for rendering and that it has been done in your code. If that is not the case can you take a look at http://toolbox.sgi.com/linux/Guide/Picks/
a good starting point about OpenGL and X could be http://toolbox.sgi.com/linux/documents/OpenGL/overviews.html#OGLSGS

Zico and Zen;

Thanks for the help! Progress, albeit it slow, is happening here :slight_smile:

-Markus