Tomáš Zato
Tomáš Zato

Reputation: 53358

Adding SDL library to my program

there are a few questions on that already, but all askers are, lets say it, one level above me. All I know there are some download links here and that I should probably download SDL-1.2.15-win32-x64.zip (64-bit Windows) to match my system and SDL-devel-1.2.15-mingw32.tar.gz (Mingw32) to match my compiler. Now what? The development archive contains some C++ project and I have no idea, what should I do with it. What files to include? What files to link in linker?

Edit:

Info

System: Windows 7x64
IDE: Code::Blocks Compiler: G++

Upvotes: 3

Views: 38430

Answers (3)

Tomáš Zato
Tomáš Zato

Reputation: 53358

So the actual answer to my question is just the link to this manual for dummies: http://lazyfoo.net/SDL_tutorials/lesson01/index.php
Here anyone can choose his environment to get the help. I get no credits to this answer - @Ergo Proxy has posted it as comment to my question. But this is what I needed.

Upvotes: 5

akrami
akrami

Reputation: 309

I have installed SDL on visual studio. it's easy and you'd better use it because it doesn't need mingw. go to SDL website and download SDL-devel-1.2.15-vc.zip package. then extract it in your system. then open your visual studio, goto your project's properties in "VC directories" section you should set the SDL address. add SDL\lib to "lib directories" and SDL\include to "includes". after this, in project properties goto linker\input then add "SDL.lib" to it's first property. after all you can compile your codes with it.

Upvotes: 0

Leo Chapiro
Leo Chapiro

Reputation: 13979

It seems to be a good begin: using SDL2 to create an application window. You need just to link the static sdl.lib (or sdl2.lib if you have the very last version of SDL). Try to compile and execute it.

#include <SDL2/SDL.h>
#include <iostream>

int main(int argc, char* argv[]){

  SDL_Init(SDL_INIT_VIDEO);   // Initialize SDL2

  SDL_Window *window;        // Declare a pointer to an SDL_Window

  // Create an application window with the following settings:
  window = SDL_CreateWindow( 
    "An SDL2 window",                  //    window title
    SDL_WINDOWPOS_UNDEFINED,           //    initial x position
    SDL_WINDOWPOS_UNDEFINED,           //    initial y position
    640,                               //    width, in pixels
    480,                               //    height, in pixels
    SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL //    flags - see below
  );

  // Check that the window was successfully made
  if(window==NULL){   
    // In the event that the window could not be made...
    std::cout << "Could not create window: " << SDL_GetError() << '\n';
    return 1;
  }

  // The window is open: enter program loop (see SDL_PollEvent)

  SDL_Delay(3000);  // Pause execution for 3000 milliseconds, for example

  // Close and destroy the window
  SDL_DestroyWindow(window); 

  // Clean up
  SDL_Quit(); 
  return 0;   

}

Upvotes: 3

Related Questions