DarkElvenAngel
Posts: 1275
Joined: Tue Mar 20, 2018 9:53 pm

Best way to handle sprites

Sat Nov 09, 2019 5:34 pm

Hello,

I'm working on a raw Linux Framebuffer library and I'm thinking to add sprites if for nothing else I can use it for a mouse cursor.

I'm writing all this is C and I'm not sure how it should work.

My current thinking is to take a rectangle from where the sprite will be placed and save that in a working buffer blit the sprite to the framebuffer then when I have to move it Put the background back and repeat...

I just need a basic flow does this seem like a good approach?

Thanks

blackshard83
Posts: 92
Joined: Fri Jan 10, 2014 8:31 am

Re: Best way to handle sprites

Sat Nov 09, 2019 11:44 pm

Of course that's an approach, but it will work well only if your "background" does never change.

DarkElvenAngel
Posts: 1275
Joined: Tue Mar 20, 2018 9:53 pm

Re: Best way to handle sprites

Sun Nov 10, 2019 1:38 am

blackshard83 wrote:
Sat Nov 09, 2019 11:44 pm
Of course that's an approach, but it will work well only if your "background" does never change.
I see that could be a problem since it's very possible that the background could change, how do I deal with that?

DarkElvenAngel
Posts: 1275
Joined: Tue Mar 20, 2018 9:53 pm

Re: Best way to handle sprites

Sun Nov 10, 2019 10:48 pm

I'm thinking a double buffer might be the only approach to solve this issue of background changing.

A buffer for the background that is copied to the main frame buffer then apply the sprites over that and use this background buffer in place of the small working buffer. This will require more memory.

Does this approach seem likely to work better than my original plan?

cleverca22
Posts: 2506
Joined: Sat Aug 18, 2012 2:33 pm

Re: Best way to handle sprites

Sat Nov 30, 2019 3:53 pm

if you dont mind it being raspberry pi specific, you should look into dispmanx

that api lets you draw rgba images at any xy coordinate you want, and it can draw ontop of the framebuffer or even x11

https://github.com/raspberrypi/firmware ... dispmanx.c

DarkElvenAngel
Posts: 1275
Joined: Tue Mar 20, 2018 9:53 pm

Re: Best way to handle sprites

Sat Nov 30, 2019 5:51 pm

cleverca22 wrote:
Sat Nov 30, 2019 3:53 pm
if you dont mind it being raspberry pi specific, you should look into dispmanx

that api lets you draw rgba images at any xy coordinate you want, and it can draw ontop of the framebuffer or even x11

https://github.com/raspberrypi/firmware ... dispmanx.c
Now that is interesting I'll have to check in to it. I'm mostly targeted at raspberry Pi it would be nice to have a solution for other platforms. I would like to see if it works across multiple displays currently I am testing on a pi4 with two framebuffers.

User avatar
dividuum
Posts: 229
Joined: Sun Jun 16, 2013 1:18 pm
Location: Germany
Contact: Website

Re: Best way to handle sprites

Sun Dec 01, 2019 4:28 pm

DarkElvenAngel wrote:
Sat Nov 30, 2019 5:51 pm
Now that is interesting I'll have to check in to it. I'm mostly targeted at raspberry Pi it would be nice to have a solution for other platforms. I would like to see if it works across multiple displays currently I am testing on a pi4 with two framebuffers.
Yes. That will work. HDMI0 is dispmanx display 2, while HDMI1 is display 7. See here:

https://github.com/raspberrypi/firmware ... .h#L58-L68
info-beamer hosted - A user and programmer friendly digital signage platform for the Pi: https://info-beamer.com/hosted

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Best way to handle sprites

Mon Dec 02, 2019 10:56 am

A (long) long time ago when the Raspberry Pi was very new, I wrote some DispmanX code to try and work out and demonstrate the API. If you are interested it is available on github - https://github.com/AndrewFromMelbourne/raspidmx

User avatar
Gavinmc42
Posts: 5097
Joined: Wed Aug 28, 2013 3:31 am

Re: Best way to handle sprites

Mon Dec 02, 2019 11:38 am

When I do this on a Pi3 I get two layers, one for the mouse cursor

Code: Select all

vcgencmd dispmanx_list
The cursor layer I have used as a sprite up to 64x64 pixels on VC4 Pi's
The manual seems to indicate there is only one cursor block/layer.
But I'm not if more than one cursor/sprite can be done.

I get this on a Pi4.

Code: Select all

vcgencmd dispmanx_list
display:3 format:XRGB8888 transform:0 layer:-127 src:0,0,656,416 dst:32,32,656,416 cost:454 lbm:0 
The display numbers actually match on VC4 Pi's, those numbers are rubbish for a Pi4?
So how is the mouse cursor done on a Pi4?
Can that method be used for sprites?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Gavinmc42
Posts: 5097
Joined: Wed Aug 28, 2013 3:31 am

Re: Best way to handle sprites

Mon Dec 02, 2019 11:46 am

https://www.raspberrypi.org/forums/view ... p?t=254293
Both drivers are used. v3d does the 3d. vc4 does the rendering.
Somehow I missed this post.

Nope, still no idea how the Pi4 does it.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

DarkElvenAngel
Posts: 1275
Joined: Tue Mar 20, 2018 9:53 pm

Re: Best way to handle sprites

Mon Dec 02, 2019 3:24 pm

AndyD wrote:
Mon Dec 02, 2019 10:56 am
A (long) long time ago when the Raspberry Pi was very new, I wrote some DispmanX code to try and work out and demonstrate the API. If you are interested it is available on github - https://github.com/AndrewFromMelbourne/raspidmx
That's very helpful thanks!

This is all very good information hopefully I'll get a chance to try this all out soon.

Thanks for all the replies

DarkElvenAngel
Posts: 1275
Joined: Tue Mar 20, 2018 9:53 pm

Re: Best way to handle sprites

Fri Mar 13, 2020 3:56 pm

AndyD,

I was looking at your repo and was wondering if it's possible to build the pngviewer as a static binary I'm trying to test something during boot up and if that is possible it would save time if it doesn't work.

Thanks for sharing your code I'm finding it useful just a bit to get your head around when you have other projects.

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Best way to handle sprites

Sun Mar 15, 2020 8:42 pm

Hi @DarkElvenAngel,

It has been a while and I don't have a lot of time these days. I am happy to have a look at this. There is no reason for the library holding the common code to be shared. That happened a while ago when I accepted a pull request. I have been meaning to change that for a while. For pngview there are two other libraries libbcm_host and libpng that are both shared objects. I am not sure if either of them are available as static libraries, but I am happy to have a look, just may take a while.

DarkElvenAngel
Posts: 1275
Joined: Tue Mar 20, 2018 9:53 pm

Re: Best way to handle sprites

Mon Mar 16, 2020 8:55 pm

AndyD wrote:
Sun Mar 15, 2020 8:42 pm
Hi @DarkElvenAngel,

It has been a while and I don't have a lot of time these days. I am happy to have a look at this. There is no reason for the library holding the common code to be shared. That happened a while ago when I accepted a pull request. I have been meaning to change that for a while. For pngview there are two other libraries [] and libpng that are both shared objects. I am not sure if either of them are available as static libraries, but I am happy to have a look, just may take a while.
Thank-you @AndyD,

I completely understand about time and not ever having enough. I was trying to do this myself and if all else failed just link the libraries I couldn't build in. I'm just not that certain how to do that and all attempts failed. My end goal was to need the least or none of the current dynamic library. As I was trying to put this in a initramfs to load a splash image. I was successful in removing the dependence for libpng so I could use JPG and other formats but libbcm_host is the hang up I think it needs to be dynamically linked. Take your time I'm only just picking around with this stuff if I can sort it before you I'll just post back here. Thanks again for posting this great repo when I have time to dig into more I'm sure to learn a lot.

Thanks again for your time

Return to “Graphics programming”