Faster alternatve to GetPixel

Previous topic - Next topic

yaKC

I've been working on a game for a few years using GetPixel, however I'm stuck at around 60 checks max per frame as it's really slow, I read that it transfers the framebuffer everytime you use it. Is there anyway to use Lockbits, or Getpixels (multiple) so that i only need to transfer once? Or perhaps a way using OpenGL?
I can use a 1 pixel sprite collsion as analternative with an image but this game really needs live info from the screen. not the whole screen just around a 32x32 area around the player.
Thanks in advance if anyone has a solution :D

bigsofty

#1
You could use GRABSPRITE() to grab the 32x32 area around the player and if your not changing the background each frame, just reuse the array data?

EDIT: Oops missed out turning the sprite into a pixel array stage ( SPRITE2MEM() ), thanks for the reminder Dreamerman ;)
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

dreamerman

It all depends on your game, for what and how you are using this. But as Bigsofty mentioned you can use GrabSprite (don't know how fast it would be), Mem2Sprite and of course OpenGL either in GLB or inline C++. Don't remember now if any one made fast sprite2mem but as you can see in this topic about Mem2Sprite using OpenGL can give you much better results. You can combine this with some other tricks - draw player and part of background to offscreen sprite then use Mem2Sprite and so on...
Check my source code editor for GLBasic - link Update: 20.04.2020

MrPlow

#3
I have an idea that might be of use - I did something like this for an android app.
Not sure how effective this would be for your use case, it could work for small resolutions or subset of the display

Idea:
Create a function that...
1. draw the objects items on screen
2. along with the function send the main color of the the object as parameter
3. create an array or type storing x,y,w,h,color of object

Second function to fetch from type and array by x,y coords

I used a cruder version for a color picker routine...
It might not suit your problem but maybe it might give you ideas
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs