Eclipse (Neon.2) and SDL2

After much trial and error, here are the instructions to using Eclipse and SDL2:

  1. Download and install Eclipse Neon.2 for C/C++
  2. Download and install MingW
    1. Install to C:\Mingw\
    2. In the bin folder, copy gcc.exe and rename it to mingw32-gcc.exe
  3. Download SDL2 MingW version and unzip to C:\SDL2
  4. Add C:\mingw\mingw32\bin to your PATH
  5. Copy SDL2.dll to C:\Windows\SysWOW64 if running 64-bit or C:\Windows\System32 if running 32-bit
  6. Run Eclipse
  7. Create a new C project and select MingW toolchain
  8. Add a new C source file and add this code
    #include <SDL.h>
    
    int main (int argc, char** argv) {
     // Create window
     SDL_Window* window = NULL;
     window = SDL_CreateWindow ( "Hello World!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN );
    
     // Setup renderer
     SDL_Renderer* renderer = NULL;
     renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED);
    
     // Set background color to red
     SDL_SetRenderDrawColor( renderer, 255, 0, 0, 255 );
    
     // Clear window
     SDL_RenderClear( renderer );
    
     // Create a square at ( 50, 50 ) with 50 width/height
     SDL_Rect r;
     r.x = 50;
     r.y = 50;
     r.w = 50;
     r.h = 50;
    
     // Fill square with blue color
     SDL_SetRenderDrawColor( renderer, 0, 0, 255, 255 );
     SDL_RenderFillRect( renderer, &r );
    
     // Draw everything to screen
     SDL_RenderPresent(renderer);
    
     // Wait for 5 seconds
     SDL_Delay( 5000 );
    
     // Close window and exit
     SDL_DestroyWindow(window);
     SDL_Quit();
    
     return EXIT_SUCCESS;
    }
  9. Add “C:\SDL2-2.0.5\i686-w64-mingw32\include\sdl2” to the Project “Include”
  10. Add “C:\SDL2-2.0.5\i686-w64-mingw32\lib” to the Project “Library Paths”
  11. Add “mingw32, sdl2main, sdl2” (in that order) to the Project “Libraries”
  12. Compile and run! 🙂
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s