🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

SDL for Dummies

Started by
5 comments, last by evillive2 19 years, 10 months ago
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.
Mark St. Jean - OwnerWastedInkVwmaggotwV@Yahoo.com
Advertisement
linkapalooza

"blit"=="BLT"=="(BL)ock (T)ransfer"=="copying pixels from one rectangular area to another"

Get off my lawn!

try using SDL_image

http://www.libsdl.org/projects/SDL_image/

docs here

http://jcatki.no-ip.org/SDL_image/

example of using it there also.
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.
Mark St. Jean - OwnerWastedInkVwmaggotwV@Yahoo.com
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);


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.
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 imagethe source rectangle of the surfacethe destination surfacethe 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 surfaceset the color key for the bitmapblit 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. :)
Evillive2

This topic is closed to new replies.

Advertisement