Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3

    Smile 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 (=

  2. #2
    Linux Guru Rubberman's Avatar
    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!

  3. #3
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    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.

  4. #4
    Just 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?

  5. #5
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    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.

  6. #6
    Just 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 =/

  7. #7
    Linux Guru Rubberman's Avatar
    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
    Quote Originally Posted by Voidkahn View Post
    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 =/
    Most of this low-level X-windows stuff is found in hard-copy reference material. You might check the xorg web site, but I think you need to invest in the X-windows reference manual set.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #8
    Just 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...