Sign in to follow this  

SDL for Dummies

This topic is 4862 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

Damn, I know alot of C++, alot. I know classes, pointers, arrays, all the things you would consider important in C++, and I cant even figure out SDL, I can initialize a window, and loop to keep it open, not hard. Now when I try loading in a bmp, its a different story. I can initialize a surface, load a bmp to it, but I cant load it to the screen. Every tutorial I find doesent explain what the parimeters are, I mean they do but not to someone that doesent know what there doing. I dont know what "bliting" is, I dont know what rectangles are for, anything. Is there anywhere I can find a SDL for Dummies tutorial, something that explains whats going on like im a complete moron. I want to get Focus on SDL but im broke, I tried finding the book online, but no success. Damn im lost.

Share this post


Link to post
Share on other sites
Cone3d isnt that great, its helpful to sum, but I got get it, they dont explain it enough to help me. What is SDL_img or whatever? All I want to do is load images and make a part of them transparent, thats all. The games I want to make arent that complicated.

Share this post


Link to post
Share on other sites
Have you tried reading through the documentation that comes with the SDL library? It has some great, simple examples to get you started. You can download it from http://www.libsdl.org/docs.php.

Another great book is Programming Linux Games, which you can download from the web at:
http://www.overcode.net/~overcode/writing/plg/

Yes, it is for linux games, but the chapters on SDL apply to SDL on any platform.

To answer your question, you use SDL_BlitSurface to copy one surface to another. The following code creates a main screen surface, loads a bitmap to a second surface, then blits the bitmap to the screen:

SDL_Surface* pScreen = SDL_SetVideoMode (640,480,8,SDL_SWSURFACE);
SDL_Surface* pBmp = SDL_LoadBMP("image.bmp");
SDL_BlitSurface (pBmp, NULL, pScreen, NULL);


Share this post


Link to post
Share on other sites
Quote:
Original post by Thrust
What is SDL_img or whatever? All I want to do is load images and make a part of them transparent, thats all.


read up on sdl_Image it might just help you.

Share this post


Link to post
Share on other sites
Quote:
Cone3d isnt that great, its helpful to sum, but I got get it, they dont explain it enough to help me. What is SDL_img or whatever? All I want to do is load images and make a part of them transparent, thats all. The games I want to make arent that complicated.


Ok, so you need to learn the very basics of how things work first. That is ok, everyone starts somewhere. I know TANSTAAFL's book Isometric Game Programming with DX7 does a good job explaining this in the first couple of chapters and even if you don't want to use DirectDraw it still has some cool stuff in it that can be used as general knowledge.

Anyway, for the basic graphics stuff you want to do, you need to understand a few basic concepts. First off you want to init SDL, then set the screen attributes (width, height, bpp, fullscreen, double buffer, etc.). This is all outlined right in the SDL documentation. The next step is understanding what goes on to get an image onto the screen. A bitmap for example can be loaded from disk onto a surface using SDL_LoadImage. You need to load it to a surface so that it is in a format the graphics API you use can readily use it without having to load it from the disk every time you want to display it. Now to display the image to the screen once it is on a surface you would use SDL_Blt. Blits generally take a few common parameters no matter if you are using SDL, DDraw or something else. They mostly all require:

the source surface of the image
the source rectangle of the surface
the destination surface
the destination coordinates or destination rectangle

With SDL and some other graphics API's, you can set a color key for a surface. By setting the color key for a surface to a particular color, that color is ignored when blitting from that surface making it transparent.

So, to get a bitmap drawn to the screen in SDL, the steps are as follows:

init SDL and get access to the primary surface/screen.
load a bitmap to a surface
set the color key for the bitmap
blit the bitmap surface to the screen surface.


Now you can imagine that most games have a bunch of graphics, especially for animated sprites etc. In most cases similar images are grouped into one bitmap of multiple images, animations especially. This is where specifying the source rectangle of an image comes in handy. You might want to check out some of the tile and sprite sheets available from some RPGMaker sites that pop up on google to get an idea of what I mean. But the point is that each image is defined by it's source surface and it's source rectangle. With that information, you can pick and choose which parts of a bitmap you want to draw and then where to draw it.

Hope that helps cus I am really tired right now and I don't know if I even made sense anymore. I will delete it if I don'tunderstand it in the morning. :)

Share this post


Link to post
Share on other sites

This topic is 4862 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this