文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Setting up SDL Extension Libraries in Dev C++

Setting up SDL Extension Libraries in Dev C++

时间:2006-05-26  来源:whtonline

Setting up SDL Extension Libraries in Dev C++

Last Updated 2/20/06
In this tutorial you're going to learn to set up SDL_image. If you know how to set up this extension, you can set any of them up.

SDL_image is located on this page.

Also, always make sure that when you get an SDL extension (SDL_image, SDL_ttf, SDL_mixer, etc) that you also get the newest version of SDL. New versions of the SDL extensions don't like old versions of SDL. If you don't, Dev C++ will compile the program but the program will complain at run time (it's typically something about an entry point).

Scroll down to the Binary section and download the Windows development library


Every extension libary has 3 essential parts:

  1. The header file.
  2. The lib file.
  3. The *.dll file(s)
They're all set up pretty much the same way no matter which extension you're setting up.

Open up the zip archive and there should be a folder inside.
Open the folder and it'll contain a 2 subfolders.

First, open the include subfolder in the archive and extract the header file inside to the SDL subfolder inside of the Dev C++ include folder. It should be at C:\Dev-Cpp\include\SDL.

Next extract the lib file that's inside of lib subfolder of the archive to the Dev C++ lib folder.
The Dev C++ lib folder should be at C:\Dev-Cpp\lib.

Next extract the *.dll file(s) located in the lib subfolder of the archive to the Dev C++ bin folder.
It should be at C:\Dev-Cpp\bin.

Now extract the *.dll file(s) to C:\WINDOWS\SYSTEM32.
This is so whenever you make an SDL extension app, the program will be able to find the *.dll file(s) even if they're is not in the same directory as the *.exe

Now open up your SDL project and go to the project options.

Under the Parameters tab, paste:

-lSDL_image
in the linker after "-lmingw32 -lSDLmain -lSDL".


If you were linking SDL_ttf you'd put
-lSDL_ttf
if you were linking SDL_mixer you'd put
-lSDL_mixer
etc, etc.

To use SDL_image make sure to include the header file.

#include "SDL/SDL_image.h" If you were setting up SDL_ttf you'd put
#include SDL/SDL_ttf.h
If you were setting up SDL_mixer you'd put
#include SDL/SDL_mixer.h
etc, etc.

Now the extension library is all set up.
Now you can use SDL_image functions.

The main one you want to know about is IMG_Load().
SDL_Surface *load_image( std::string filename ) { //The image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image using SDL_image loadedImage = IMG_Load( filename.c_str() ); //If the image loaded if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } //Return the optimized image return optimizedImage; } Here is a revised version of the image loading function from the previous tutorial. As you can see IMG_Load() functions exactly the same as SDL_LoadBMP(), but there's one big exception: IMG_Load() can load BMP, PNM, XPM, LBM, PCX, GIF, JPEG, TGA and PNG files.

From this tutorial on, PNG image files will be the primary image format used. PNGs have great compression and are near lossless.
Download the media and source code for this tutorial here.

I highly recommend that you download the documentation for SDL_image and keep it handy.
It can be found here.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载