Results 1 to 8 of 8
Hi, I'm making a game with the xlib library.
What I want to do is to know if the character is standing on a trap or something else.
So far ...
- 12-11-2009 #1Just Joined!
- Join Date
- Dec 2009
- Posts
- 3
xlib, C programming - Get value from pixel
Hi, I'm making a game with the xlib library.
What I want to do is to know if the character is standing on a trap or something else.
So far I've solved that using the coordinates but when I draw circles or stuff not shaped like a rectangle it gets to hard to make the game exact.
So what I'm asking for is if there is some kind of function in the xlib that tells you which color a pixel has. Because then it'd be much easier.
I've searched but I haven't been able to find anything good. I found XGetPixel() but that appears to work only with images, maybe I can make my window to be an "image"?
Thanks (=
- 12-12-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You could overlay your window with a transparent image so your stuff shows thru, and then use XGetPixel() perhaps.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 12-12-2009 #3
Wouldn't that be a bit slow for a game, pushing pixels back and forward to do collision detection? I do not think this will work fast enough, especially if video ram and system ram are different domains.
My recommendation is to hold a simple black&white cache in local memory, where you mirror your drawings and do the collision testing.Debian GNU/Linux -- You know you want it.
- 12-13-2009 #4Just Joined!
- Join Date
- Dec 2009
- Posts
- 3
Even if it's black and white I would still need to know when I hit a black pixel =/
A bigger problem I have is how to update the display. Everytime I hold another window over my drawings everything disappears.
If I update them myself it starts to kind of flash and by updating I mean drawing the same stuff over and over.
Is there another way to update the display?
- 12-13-2009 #5
There is the X double buffer extension or you use offscreen pixmaps.
You draw everything in the buffer and if everything is ready, you put the whole image on the screen at once.
Consider using SDL for your first games.Debian GNU/Linux -- You know you want it.
- 12-14-2009 #6Just Joined!
- Join Date
- Dec 2009
- Posts
- 3
Well, I haven't been able to find some good tutorials on sdl and c. Moste tutorials are based on c++, even thou they are similar it's not the same.
I haven't been able to get the pachages to my linux anyways.
What I'm trying to do is very simple anyways. So far I've been drawing with rectangles, points, lines and arcs because I don't really have to care that much about how it looks just yet.
Anyways, I'll give that double buffering a try but it seems weird that there isn't just a simple function or something that makes it possible for the drawings to stay where they are.
I've been searching all over but found nothing =/
- 12-14-2009 #7Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 04-12-2010 #8Just Joined!
- Join Date
- Apr 2010
- Posts
- 1
Posting a little late, but perhaps it could still be usefull...
If you are planning to write games with low level stuff like Xlib under C, and wants examples in C, not C++, try this framework: nongnu.org/weaver


Reply With Quote
