Setting up Code::Blocks to work with SDL - 多媒体编程库

tmobile-sdl - Simple DirectMedia Layer, is a cross-platform designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning port of "Civilization: Call To Power."

supports , , CE, BeOS, MacOS, Mac OS X, , NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64, RISC OS, SymbianOS, and OS/2, but these are not officially supported.  is written in C, but works with C++ natively, and has bindings to several other languages, including Ada, C#, D, Eiffel, Erlang, Euphoria, Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP, Pike, Pliant, Python, Ruby, Smalltalk, and Tcl.  is distributed under GNU version 2. This license allows you to use freely in commercial programs as long as you link with the dynamic library. – libsdl.org

Here it is the article we copied from another website for you to enjoy programming in CB – Bryan.

First off, what is ? stands for Simple Direct-Media Layer.
As the name suggests, it is quite a simple library to use! Good to know for graphics beginners (plus, it is compatible with OpenGL)
What do I need to download?

* The reason that I want you to download it with the MinGW compiler is that I can give you the specific paths. If you want to, you can install MinGW seperately, but it’s just easier to explain if you get it with
Once you have downloaded Code::Blocks, install it to the default directory: C:\Program Files\CodeBlocks
Then, and this is the important bit, you need to copy the files into the correct places.

  • Copy the contents of \-1.2.13\include\ to C:\Program Files\CodeBlocks\MinGW\include\
  • Copy the contents of \-1.2.13\lib\ to C:\Program Files\CodeBlocks\MinGW\lib\

And there we have it! But we’re not done yet… unfortunately. We still need to set up the build options in Code::Blocks, so fire up the IDE.
Now go to File>New>Project and select Console application (Don’t worry, we are doing graphics, this is just a generic thing)
Call the project "New Project" (you’ll see why we give it such a generic name later on)
Copy \-1.2.13\bin\.dll to the project folder. (You need to do this for each project) ** See note at the end of this tutorial
Now go to Project>Build Options and make sure that New Project is selected in the tree menu on the left, this is so that it is set for both Debug and Release compile options.
Now, click the Linker Settings tab, and click the add button. Copy and paste this exactly as it is:
C:\Program Files\CodeBlocks\MinGW\lib\libmingw32.a;C:\Program Files\CodeBlocks\MinGW\lib\libSDL.dll.a;C:\Program Files\CodeBlocks\MinGW\lib\libSDLmain.a;
All that we’re doing here is setting up our build options to build our program with the stuff in it.
Now, click OK, and OK again, to return to the main window of Code::Blocks.
Nearly done!
Now go to Settings>Compiler & Debugger and click the Linker Settings tab (again) and copy and paste this exactly as it is (again) :
C:\Program Files\CodeBlocks\MinGW\lib\libmingw32.a;C:\Program Files\CodeBlocks\MinGW\lib\libSDL.dll.a;C:\Program Files\CodeBlocks\MinGW\lib\libSDLmain.a;
Click OK and OK again, and you’re back to the code window.
Just to test that it all works, try this code:

cpp

#include </.h>

const int SCREEN_WIDTH  = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_DEPTH  =  32;

int main(int argc, char *argv[]) {      SDL_Surface *screen;      Uint8       *p;      int         x = 10; //x coordinate of our pixel      int         y = 20; //y coordinate of our pixel      /* Initialize  */      SDL_Init(SDL_INIT_VIDEO);      /* Initialize the screen / window */      screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);      /* Make p point to the place we want to draw the pixel */      p = (Uint8 *)screen->pixels + y * screen->pitch + x * screen->format->BytesPerPixel;      /* Draw the pixel! */      *p=0xff;      /* update the screen (aka double buffering) */      SDL_Flip(screen);      while(true);
}

Now we’re getting somewhere! Hit F9 to compile and run this, and you should get a window with a pixel drawn somewhere in the top left corner.

WOOHOO! YOUR FIRST PROJECT!

OK, now that we know it works, go to File>Save project as user-template and choose a descriptive name for it. (This is why we called the project "New Project")

Now, if you go to File>New>From user template you should see your project template. Select it, and you should have a duplicate of the project that we just created. From now on, you can select this whenever you want to create an application! Nifty, huh? BUT: Don’t forget to copy .dll to your new project!

A useful note:

You can copy .dll to your system32 directory, BUT your programs will rely on it being there… so, if you run it on another computer that doesn’t have .dll already installed, then your program won’t work. This is why I recommend that you copy your drivers to your project each time

Another note:

Wherever your .exe program is, .dll needs to be in the exact same directory. Remember this, it’s important!

Good luck with coding!

Came from: http://www.dreamincode.net/forums/showtopic57275.htm

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Related posts:

  1. Debugging with Code::Blocks
  2. QT4+MinGW+Code::Blocks IDE集成
  3. Code::Blocks IDE: 手动安装和配置编译器指南
  4. Code::Blocks IDE in openSUSE 11.1编译和安装指南
  5. 如何在Windows上安装Code Blocks 8.02官方发布版
  6. Code::Blocks Debug Shortcut and Example
  7. CodeBlocks下SDL编译成功实例
  8. ProjectManager, Project and ProjectFile in Code::Blocks
  9. Code::Blocks编译skyeye步骤
  10. C::B IDE的命令行参数

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Contact us

Admin: Bryan Wu