How to Initialize SDL2 in Orwell Dev C++

Jan 25, 2015 at 5:37am
hello, you can use SDL 2.0.3 in Orwell Dev C++ 5.6.1
in following way (for 32bit):
( latest Dev C++: http://sourceforge.net/projects/orwelldevcpp/ )

1) download "SDL2-devel-2.0.3-mingw.tar.gz"
from http://libsdl.org/download-2.0.php
and extract them to "dev_lib" folder (you can choose your own path.)
C:\dev_lib\

2) start Dev C++, create an Empty project: File>new>Project
then select "empty project" press "ok"

3) Tools>Compiler Options > Directories > in C++ includes tab:
add following by click little orange folder icon:
C:\dev_lib\SDL2-2.0.3\i686-w64-mingw32\include\SDL2

4) then in Libraries tab to the left:
add following by click little orange folder icon:
C:\dev_lib\SDL2-2.0.3\i686-w64-mingw32\lib

5) then, Project > Project options > Parameters Tab > Linker :
add this string:
-lmingw32 -lSDL2main -lSDL2

6) Directories Tab > Include Directories:
add: C:\dev_lib\SDL2-2.0.3\i686-w64-mingw32\include\SDL2

7) in Library Directories, add: C:\dev_lib\SDL2-2.0.3\i686-w64-mingw32\lib

8) copy the
SDL2.dll
file from
C:\dev_lib\SDL2-2.0.3\i686-w64-mingw32\bin
to, where your project executable will run.

Done!

now compile and run this SDL code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <SDL.h>
#include <iostream>

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

int main( int argc, char* args[] ){	
	SDL_Window* window = NULL;	
	SDL_Surface* screenSurface = NULL;	
	if( SDL_Init( SDL_INIT_VIDEO ) < 0 ){
		printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
	}
	else{		
		window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
		if( window == NULL ){
			printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
		}
		else{			
			screenSurface = SDL_GetWindowSurface( window );			
			SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );			
			SDL_UpdateWindowSurface( window );			
			SDL_Delay( 2000 );
		}
	}	
	SDL_DestroyWindow( window );	
	SDL_Quit();
	return 0;
}


if you see a white screen for 2 sec, then its ok!
:)


EDIT:
you can use the new created project folder as "template" so you need not initialize for every new SDL project (use copy of the "template")
Last edited on Feb 1, 2015 at 5:14pm
Jan 25, 2015 at 5:48am
But... why? Just use an IDE not horribly out-of-date.
Last edited on Jan 25, 2015 at 5:49am
Jan 25, 2015 at 6:32am
I don't understand why DevC++ is still a thing amongst beginners... This version is pretty up to date, but there are better alternatives such as Codeblocks and Visual Studio.
Last edited on Jan 25, 2015 at 6:33am
Jan 25, 2015 at 12:04pm
Why do we have to pick on people because of the tools they use? What's "better" is always subjective.
Jan 25, 2015 at 1:08pm
well, i also have Visual Studio 2012 and Code::Blocks 13.12.
but, most of the time i use Orwell Dev C++ 5.6.1. because it feels more clear and shows more precise errors reports on failure (my learning stage is libraries), the IDE also starts quicker than the other two.
But... why? Just use an IDE not horribly out-of-date.

you probably didn't try the version i am using(it comes with gcc 4.8), probably more latter version are available.

now why i posted this?
i tried to initialize SDL2 with the IDEs i have, according to larzfoo tutorials. it worked very easily with VS. but didn't worked with my C::B.
and there is nothing about how to initialize SDL2 in Dev C++.
so, it can be used as an reference to beginners. (as there is no complete example on this in whole vast internet !!!)
IMO for beginners using windows, Dev C++ is the best.
Jan 25, 2015 at 6:12pm
Guys, it's Orwell Dev C++. It's a more updated version developed by other people.
Jan 25, 2015 at 6:27pm
Ah, crap. Always get the names of those two mixed up. My apologies, carry on.
Jan 25, 2015 at 6:34pm
¿what's the difference between points 4b, 4c and point 3?
Jan 25, 2015 at 9:01pm
¿what's the difference between points 4b, 4c and point 3?

hmm, serial points looks better. updated.
Jan 25, 2015 at 11:23pm
so, ¿what's the difference between points 3 and 6 and between points 4 and 7?
Jan 26, 2015 at 11:37pm
so, ¿what's the difference between points 3 and 6 and between points 4 and 7?


http://lazyfoo.net/SDL_tutorials/lesson03/windows/devcpp/index.php
above link describes for SDL 1.2 + Dev C++,
that doesn't say about my point 6 and 7.
and without 6 and 7 it didn't initialized for me.
i don't know much about them, i am still learning.
that worked by chance while trying several things!
Topic archived. No new replies allowed.