PDA

View Full Version : Pixel Collision detection in SDL+OpenGL



arthurprs
04-11-2007, 05:15 PM
hi guys im starting a new project to show on a contest, it will be a plataform adventure game in 2d (like -> mario, metal slug),

i think pixel collision detection is the best option for it, but i searched on google and in the forum and don't found nothing about 2d collision detection in opengl,

i don't any ideia how get pixels from gl texture ...

someone can help me?

User137
04-11-2007, 05:46 PM
Pixel collision is "oldschool", not really used almost at all nowadays. But if you really want to do that in OpenGL, you should keep texture data in memory and make own GetPixel function to read from it. Same texture data that you pass on glTexImage2D when loading them. OpenGL itself offers glReadPixels ( http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/readpixels.html ) but you may find it as much slower choice.

Suggesting geometrical; circle, rectangle, line etc... collision instead.

JernejL
04-11-2007, 05:58 PM
i searched on google and in the forum and don't found nothing about 2d collision detection in opengl

Opengl is NOT a collision detection / physics engine.

WILL
04-11-2007, 06:53 PM
Well probably the worst method of doing this kind of collision detection would be to use your original texture alone.

Reasons:

:arrow: You might not want ALL of your sprite to collide (ie. the bottom lining of your feet to give some perspective)
:arrow: The fastest way to draw something would be to have it in texture memory and reading pixels in texture memory could cost you some speed.
:arrow: The bigger the sprite frame the more scans/pixels you'd have to check and this might make your engine even slower. If you had a lot of sprites on screen at one time this could mean a huge change in FPS in mid-gameplay.

There are some ways that would improve things a bit though:

:arrow: Make a mask for each sprite frame so that you know what is collide-able and what is not.
:arrow: Pre-scan your sprite/mask frames for edges so you don't have to check the entire thing needlessly.
:arrow: Create masks that consist of merely a small set of single pixel points and when you pre-scan your mask you can store these points for each frame into a much smaller/compact array and discard the bulky mask textures themselves in exchange for the more efficient array of points.


Anyhow, just a few suggests that might help. Usually it just takes some creative thought to find neat little ways to optimize the functionality of things like this. ;)

arthurprs
04-11-2007, 07:31 PM
i searched on google and in the forum and don't found nothing about 2d collision detection in opengl

Opengl is NOT a collision detection / physics engine.
i don't said that.




~~~

I know that its sometimes very slow and oldschool, but implementing poligon collision requires loading tons of info per title (only the main char image have more than 20 titles) ;/ and its really time spending ..