[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xlib problems (Lol. I've only been programming in it for 10 days...)







>Currently I'm working on an RTS engine, writing the GUI code; in Xlib.
>It's all working fine, etc. and now I'm stuck with a problem none of the
>books I have seem to address. How do I draw a coloured image to the
>screen?

Use MITSHM: Basically an area of memory is mapped into your process and X11s.
Only works if X11 and the process are on the same machine.

You can then just prod values into this memory.

>The only way of doing it I've come across so far has been, basically;
>make an XImage, and use XPutPixel to put the pixel values in, one at a
>time, then XPutImage to draw to the window (or pixmap in my case). Can
>anyone help / point me to a tutorial for this stuff? I can't find a
>thing.
>(Nb. Color allocation stuff in Np. I have at least 3 books on X with
>colors. But they only seem to cover allocating colors, or using planes,
>which'd be stupid for a picture with >500 different colors.)

Colour allocation is for 8bit displays: you want to find out what the current
display is at. If it's 8 bit, I'd recommend establishing either a 6x6x6 RGB
palette or an optimised 256 colour palette and producing a 4096 entry colour
mapping table. That way, a truecolour->palette entry translation is quite fast.

     colour = table[((red&15)<<8)((green&15)<<4)((blue&15))]

And then remap all the GFX as they're loaded.

For other displays, you need to work out what the pixel format is, and write the
shared ram in that format, again remapping the GFX as they load, for example,
inserting a blank byte for 32bpp, and then you can draw the image to the shared
ram with memory copies. This is the neato way to do it, because you can draw all
your pictures in truecolour and anyone who's running at 24bpp will get
loveliness and it still works on an 8 bit display.


The other, and probably better alternative, is to go look at some of the
libraries that will remove some of this aggro - writing an RTS is a big job
anyway..