NEW 6 years ago
Using this exact code:
gb.display.drawImage(0, 50, img, 0, 50, 80, 14);
What I get:
What I expect:
It should draw the entire x axis from 0-80.
But it only draws the first 30~ pixels and just cuts off.
NEW 6 years ago
Thank you, found the bug and fixed it......it was unbelievably stupid lol
NEW 6 years ago
Brilliant! Great news. Thank you for your help. Hope to see the fix pushed to Arduino IDE soon so I can finish polishing up my game!
NEW 6 years ago
While implementing my first Gamebuino game I am running into some performance issues related to drawing images. The game features a 3D-like view which requires drawing images with a transparent color which partially overlap. This means it requires drawing more pixels than in a normal 2D game.
I did some benchmarking and get the following results:
So a couple of questions:
Btw, I can share my benchmark code if that helps.
Sorunome
6 years ago
Is it normal that CPU usage is so high without any code in the loop?
at 25 FPS you have 40ms time for each frame to calculate. the screen is 160x128 pixels, at 16 bits per pixel, making 327680 bits to send per frame. The SPI speed to send data to the screen at 24MHz, so sending the screen alone takes 14ms. That is 35% CPU time. Adding things like the sound interrupt (44.1kHz) etc. explains why a lank sketch has such a high CPU usage already.
Is it expected that drawing images with a transparent color is significantly slower?
Yes, as you can't just memcpy but have to check for every single pixel of the source image if they are the transparent color, and if so, skip them
Can I do anything in my code to improve performance?
No need to clear the screen if you do a full re-draw, try to avoid transparency, other things
Can anything be done in the Gamebuino library to improve performance?
Probably, and I'm happy for suggestions!
NEW 6 years ago
Is it normal that CPU usage is so high without any code in the loop?
at 25 FPS you have 40ms time for each frame to calculate. the screen is 160x128 pixels, at 16 bits per pixel, making 327680 bits to send per frame. The SPI speed to send data to the screen at 24MHz, so sending the screen alone takes 14ms. That is 35% CPU time. Adding things like the sound interrupt (44.1kHz) etc. explains why a lank sketch has such a high CPU usage already.
Is it expected that drawing images with a transparent color is significantly slower?
Yes, as you can't just memcpy but have to check for every single pixel of the source image if they are the transparent color, and if so, skip them
Can I do anything in my code to improve performance?
No need to clear the screen if you do a full re-draw, try to avoid transparency, other things
Can anything be done in the Gamebuino library to improve performance?
Probably, and I'm happy for suggestions!
eriban
6 years ago
Thanks for your (quick) reply. With your confirmation that this is the way it is and why, I refactored my drawing code to minimize the number and size of images with transparent pixels. The impact of this change is significant. At 15 FPS, CPU load went down from 86% to 63%. 20 FPS is now definitely feasible, and maybe even 25 FPS. :-)
I am not yet familiar enough with the Gamebuino library and programming for Arduino in general to suggest performance improvements to the library right now, but will definitely do so when/if I am able to.
NEW 6 years ago
I should make errors... I don't have success to use spritesheet
I would use crop seems easy but i always have this error:
exit status 1
no matching function for call to 'Gamebuino_Meta::Image::drawImage(int, int, Gamebuino_Meta::Image&, int, int, int, int)'
The code line is: gb.display.drawImage(7, 2, ParaCol1, 0, 0, 10, 12);
Seems like the code of example... no idea, it's will be enough for today but i don't success... I'll finish to make unique image as i success to manage it ...
NEW 6 years ago
I should make errors... I don't have success to use spritesheet
Where are you stick?
I would use crop seems easy but i always have this error:
Crop is currently only in the git repo, it hasn't made its way to the one released via the Arduino IDE yet
NEW 6 years ago
OK, thanks Sorunome. Spritesheet make no error but the fram was invisible, so as it was not more easy as a simple crop, i would use it.
Have i an easy way to use librairy from the repo instead of actual ?
NEW 6 years ago
Thanks for your (quick) reply. With your confirmation that this is the way it is and why, I refactored my drawing code to minimize the number and size of images with transparent pixels. The impact of this change is significant. At 15 FPS, CPU load went down from 86% to 63%. 20 FPS is now definitely feasible, and maybe even 25 FPS. :-)
I am not yet familiar enough with the Gamebuino library and programming for Arduino in general to suggest performance improvements to the library right now, but will definitely do so when/if I am able to.
NEW 6 years ago
Have i an easy way to use librairy from the repo instead of actual ?
On linux you clone the repo into `~/Arduino/libraries/` folder....on windows and mac there should be equivalent folders somewhere
NEW 6 years ago
Hi every one !
Someone to explain me how work the transparency in indexed mode ? For exemple, i want the everything in magenta are transparence, how i do that ?
i tried many thing but nothing work properly :(
Thanks !!
NEW 6 years ago
It is easy. Use setTransparentColor on the image.
For example:
Image myImage = ...; void setup() { gb.begin(); myImage.setTransparentColor(INDEX_PURPLE); } void loop() { while(!gb.update()); gb.display.drawImage(0, 0, myImage); }
NEW 6 years ago
There is no need to use setTransparentColor(), as you should set it in the header of the image data!
geed
6 years ago
Yes but how ? :)
I "converted" my pictures with the "image converter" on this site. I created them with piskel and they use only color of the GB palette.
What i must write in the header to do this ? for exemple, if i write 0xCA30 or MAGENTA, it doesn't work. Magenta's pixels aren't transparent.
Thanks
NEW 6 years ago
Sorunome correct me if i make a mistake but you can't do it with a file picture loaded and not binary written in code. As i said i begin so i have maybe missed something with it.
NEW 6 years ago
That is indeed correct, indexed BMPs can't have transparency, thus you have to use setTransparentColor() for them.
You can, however, load 32 bit depth BMPs and it'll automatically convert to rgb565 with setting the transparent color