# How do I set up SDL in visual C++ 2010 express?

This topic is 2451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've searched for tutorials but couldn't find any good ones, so I decided to ask here, how do I set up SDL in Visual C++ 2010 express?

##### Share on other sites
LazyFoo's SDL tutorials: http://lazyfoo.net/SDL_tutorials/index.php

The explanations are very clear and easy to follow. Start with Lesson 1 and you are good to go. If you do not understand any of the steps, just post again to ask.

##### Share on other sites
[quote name='fisyher' timestamp='1303910640' post='4803534']
LazyFoo's SDL tutorials: [url="http://lazyfoo.net/SDL_tutorials/index.php"]http://lazyfoo.net/S...rials/index.php[/url]

The explanations are very clear and easy to follow. Start with Lesson 1 and you are good to go. If you do not understand any of the steps, just post again to ask.
[/quote]

Wow, that guy sure ain't lazy. o.o
Thanks.

##### Share on other sites
So I tried lesson 1, all compiles fine.
But when I run the program it's just a black screen without any picture on it, what have I done wrong?

##### Share on other sites
make sure the file hello.bmp exists and is located at the right path.

##### Share on other sites
Its there and in the right path, but It still doesn't work. :c

##### Share on other sites
have you written the code or did you just copy it? It is easy to miss a line. The full source can be downloaded at the bottom of the page. If that source don't work you have probably not set up SDL properly.

##### Share on other sites
I guess I'll go over the setting up part once more.

##### Share on other sites
When I think about it, a blank window sounds more like an error in the code than SDL being not properly set up.
Try add the following code after hello = SDL_LoadBMP( "hello.bmp" ); :
[code] if (!hello)
{
}[/code]

##### Share on other sites

That's what I got in stdout.

##### Share on other sites
So the problem is that it could not open hello.bmp, most likely because it didn't found it. I don't know what visual c++ use for current directory when running your program. Maybe the file should be located at he project root. If you replace the filename ("hello.bmp") with the full path to the file ("C:\\...\hello.bmp") it should work.

##### Share on other sites
I clicked the properties on hello.bmp, and it said;
Item Type: Does not participate in build

##### Share on other sites
I think that just means that visual c++ will not try to compile that file.

##### Share on other sites
Tried all other options, doesn't do anything... :c

##### Share on other sites
[quote name='xzbobzx' timestamp='1304432952' post='4805957']
I clicked the properties on hello.bmp, and it said;
Item Type: Does not participate in build
[/quote]
BMP files are binary data, binary data and other data files are never compiled they are just that data.

Make sure that your runtime directory is setup properly in the solution file, by default when launching the exe from the IDE it doesn't start in the same directory as to which it builds, it starts in the solution directory.

1. Right click your project and open properties on it.
2. Go to the debugging item in the tree view
3. Set the working directory to the one where the bmp is located

##### Share on other sites
Also didn't work... :|

##### Share on other sites
If you haven't already, change the path back to just "hello.bmp" (that is, don't use the full path).

Then, check and see what the working directory is set to, as NightCreature83 described. I'm not looking at Visual Studio right now, but the path might be expressed in terms of a macro; if you're not sure how to interpret the path, you could post it here.

Or, you could just try putting the file in a few different directories until you find one that works. A good place to start would probably be the project directory itself (the directory where your source code and so on is).

By default, when you run your program from within the IDE, the working directory is set to "$(ProjectDir)", which is the directory containing the project file and source files. However, if you were to run your program from outside the IDE, then the working directory is the directory of the executable. You can change the working directory of a program by going to the project properties (alt+f7), and changing the "Working Directory" field under "Debugging->General". #### Share this post ##### Link to post ##### Share on other sites I also get this sometimes: LINK : [external drive]\SDL_Tutorial\Debug\SDL_Tutorial.exe not found or not built by the last incremental link; performing full link [external drive] being, of course, my external drive. :| #### Share this post ##### Link to post ##### Share on other sites [quote name='fastcall22' timestamp='1304441195' post='4806013'] By default, when you run your program from within the IDE, the working directory is set to "$(ProjectDir)", which is the directory containing the project file and source files. However, if you were to run your program from outside the IDE, then the working directory is the directory of the executable. You can change the working directory of a program by going to the project properties (alt+f7), and changing the "Working Directory" field under "Debugging->General".
[/quote]

Ah, ok, so it should work if I placed the 'hello.bmp' in the folder containing the .exe?

Edit: it worked.

##### Share on other sites
[quote name='xzbobzx' timestamp='1304441579' post='4806015']
I also get this sometimes:
[external drive] being, of course, my external drive. :|
[/quote]
That's unrelated. I'd try the previous suggestions (e.g. check to see what the current working directory is) and see if that gets you anywhere.

##### Share on other sites
[quote name='xzbobzx' timestamp='1304441926' post='4806018']
[quote name='fastcall22' timestamp='1304441195' post='4806013']
By default, when you run your program from within the IDE, the working directory is set to "\$(ProjectDir)", which is the directory containing the project file and source files. However, if you were to run your program from outside the IDE, then the working directory is the directory of the executable. You can change the working directory of a program by going to the project properties (alt+f7), and changing the "Working Directory" field under "Debugging->General".
[/quote]

Ah, ok, so it should work if I placed the 'hello.bmp' in the folder containing the .exe?

Edit: it worked.
[/quote]
Are you running the application from the IDE, or from the desktop?

The typical setup for development (I think) would be to run the application from the IDE, leave the working directory set to the project directory, and store your game data in the project directory. (One advantage of this approach is that you won't have to duplicate the data for each build configuration.)

##### Share on other sites
[quote name='xzbobzx' timestamp='1304441579' post='4806015']
I also get this sometimes: