Jump to content
  • Advertisement
Sign in to follow this  
Dark_Oppressor

OpenGL SDL+OpenGL Pixel Access?

This topic is 3090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a little 2D particle game. I've got a two-dimensional array the same size as my screen that holds all of the particles. Thus, each particle is a single pixel. I've got some basic behavior working for the particles. My problem is actually rendering them to the screen, I've tried numerous methods, and I can't seem to get above ~5 FPS. I first tried directly accessing the pixels using glDrawPixels, but found that that is incredibly slow. My current setup loops through the particle array and renders any particles that aren't air. This rendering was in immediate mode, but tonight I read up on display lists and am now using those for rendering the particles. This gave me a 1-2 FPS gain, to my average of 5 FPS as stated above. I know that VBOs exist, but from what I know, they aren't so much faster than DLs that they are going to magically solve my problem. It seems that any method that involves rendering to the screen 786,432 times (my resolution is 1024x768) is going to be far too slow. Is that correct, or am I missing something? That being said, my best guess is that the solution is going to be doing something software side and ultimately creating a single texture with the current gamestate, and just rendering that to the screen. I actually tried that before my current method, by using glTexSubImage2D, but that was not much faster. Am I correct in thinking that this is the way to go?

Share this post


Link to post
Share on other sites
Advertisement
When I was writing an OpenGL raycaster I used a texture memory buffer and just wrote pixel data to that using some macros. The glTexSubImage2D function worked great to generate a texture which I mapped to a full screen quad. I would say that's the best method for quick and dirty pixel rendering.

Share this post


Link to post
Share on other sites
I second jjanevski's suggestion, of updating your own texture in RAM and updating OpenGL's copy of it before rendering each frame, but I personally would also segment it so I could cut back on updating unchanged areas; if you can rely on a fixed resolution or don't mind a bit of offscreen waste at some resolutions, I'd break the screen up into a number of 32x32 or 64x64 pixel blocks.

Share this post


Link to post
Share on other sites
I actually tried using jjanevski's method already, and unfortunately it got me ~3 FPS. I think the overhead of calling glTexSubImage2D enough times to put each particle on the texture is just too much. Right now, I'm instead using glBegin(GL_POINTS) + glVertex2f, and this gets ~70 FPS, not counting other factors.

Wyrframe, the game already has a fixed resolution, so no problem there. What exactly do you mean by breaking the screen up into blocks of pixels? Do you mean several different textures used for rendering them all to the screen?

And to anyone else, I am beginning to wonder if maybe there is no good way to do this in OpenGL. I am thinking about trying good old fashioned SDL tonight, because I know I can pretty easily screw with a surface and then render that in SDL. What do you guys think?

Share this post


Link to post
Share on other sites
I tried using SDL, but that was only slower, so I'm going to stick with OpenGL. I've read a little about pixel buffer objects, and now I'm wondering if those might help me out.

Will pixel buffer objects help speed up drawing a ton of individual pixels?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!