Archived

This topic is now archived and is closed to further replies.

Mkk

Problems with tilemapping and some other questions (C++/SDL)

Recommended Posts

I have started to do a game that should use tilemapping but I think that I´m doing something badly wrong. I have done a character that can walk over the screen and that works ok but when I fill screen with 32*32 bitmaps then game start to act very slowly. One article in here gamedev.net talked something about "off-screen buffer", what´s that? What´s performance difference between drawing a basic 2D-platform game with SDL or OpenGL (let´s forget all special effects and that kind of stuff)? I´m planning to do game that would use SDL for drawing all basic stuff and do more special effects with OpenGL, does it sound like a good plan? Or would it be more efficient to draw whole game with OpenGL? If I put images to screen with SDL can I draw over them with OpenGL? Thanks for the answers. [edited by - Mkk on November 16, 2003 8:56:55 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Mkk
One article in here gamedev.net talked something about "off-screen buffer", what´s that?



For ex: games usually use double-buffering - one buffer for drawing and one which is presented on screen. after each frame the 2 buffers are flipped. this is done to avoid flickering.

quote:

What´s performance difference between drawing a basic 2D-platform game with SDL or OpenGL (let´s forget all special effects and that kind of stuff)?


first of all, look at the documentation of SDL. SDL uses OPENGL, they are not competing APIs. SDL just makes it easier to use OpenGL when porting to other OSs. So if you use SDL for rendering , it uses OpenGL.

quote:

I´m planning to do game that would use SDL for drawing all basic stuff and do more special effects with OpenGL, does it sound like a good plan? Or would it be more efficient to draw whole game with OpenGL?


as i said above SDL uses OpenGL so everything you render will be through OpenGL.

quote:

If I put images to screen with SDL can I draw over them with OpenGL?


look above.

look up some tutorials on google and search the forums - you''ll be surprised how many people have had problems like this and have been solved. and be sure to try the "For beginners" forums.

Share this post


Link to post
Share on other sites
The only relation to OpenGL the SDL has is it will initialize a window for you. If you''re not using gl* functions you are using SDL, which in MSWindows uses DirectDraw for blitting.

One issue I had once was when using surfaces with alpha channels. Most non-bleeding edge video card can''t to hardware accelerated blits with alpha channels.

The solution I used is this: Have an SDL_Surface that is the same size as the screen. Do all yout blitting to this surface. at the end of the frame, blit the buffer to the screen. Oh yeah make sure your back buffer and various surfaces are Software surfaces since sw->sw alpha blits are way faster than sw->hw or hw->hw alpha blits when not supported by the card.

BTW: SDL_GetVideoInfo will tell you wheather your vid card can do alpha blits.

Of course if your not using alpha channels, then this won''t help a bit. Well, except for the back buffer.

Share this post


Link to post
Share on other sites
It might help if we could see the code that you are having problems with, so that we could see what you are doing that would slow it down so much. Assuming you have a fairly decent graphics card, filling the screen with 32x32 bitmaps shouldn''t slow you down a whole lot.

As far as the tradeoff between SDL and OpenGL, as Ilici said it is irrelevant. My personal recommendation is to implement all drawing in OpenGL, as that allows you to take advantage of the special properties of 3D-style rasterization (smooth shading with diffuse colors, great for colored fonts and lighting, etc...; alpha blending, good for transparency and levels of translucency; simple and easy image scaling and rotation if required; and so on) that are more difficult to achieve using a traditional 2D style rendering interface. Most modern video cards are designed and optimized for 3D anyway, so it is possible your performance may be better using OpenGL.

When using SDL to create a window and initialize for OpenGL, you can use the function call SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) to enable usage of a double buffer. If the context is set up to use double buffering, then all OpenGL rendering calls will draw pixels to the double buffer rather than the screen. After all drawing is done, you call SDL_GL_SwapBuffers() which handles any system- specific calls to swap the double buffer and the visible buffer. As Ilici said, this is to avoid flickering and visible artifacts as the screen is drawn.


Josh
vertexnormal AT linuxmail DOT org


Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.

Share this post


Link to post
Share on other sites