# SDL Help

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

## Recommended Posts

Hey there, I've been learning SDL lately, and trying to make a function to optimize images for output, but I'm having some problems.

Firstly, this is the function that I have

 SDL_Surface *load_image(std::string filename) { //Temporary storage for the image that's loaded SDL_Surface* loadedImage = NULL; //The optimized image that will be used SDL_Surface* optimizedImage = NULL; //Load the image loadedImage = SDL_LoadBMP( filename.c_str() ); //If nothing went wrong in loading the image if( loadedImage != NULL ) { //Create an optimized image optimizedImage = SDL_DisplayFormat( loadedImage ); //Free the old image SDL_FreeSurface( loadedImage ); } //Return the optimized image return optimizedImage; 

Now this seems all good and whatnot, but I get these errors.

 C:\Documents and Settings\Home\Desktop\SDLg1\MiniSpriteGameSDL\main.c|17|error: syntax error before ':' token| C:\Documents and Settings\Home\Desktop\SDLg1\MiniSpriteGameSDL\main.c||In function load_image':| C:\Documents and Settings\Home\Desktop\SDLg1\MiniSpriteGameSDL\main.c|26|error: filename' undeclared (first use in this function)| C:\Documents and Settings\Home\Desktop\SDLg1\MiniSpriteGameSDL\main.c|26|error: (Each undeclared identifier is reported only once| C:\Documents and Settings\Home\Desktop\SDLg1\MiniSpriteGameSDL\main.c|26|error: for each function it appears in.)| ||=== Build finished: 4 errors, 0 warnings ===|

I honestly have been scratching my head at it for a while :\

##### Share on other sites
Did you include <string>?

##### Share on other sites
Yes, I did. And I actually managed to get rid of the majority of problems. (simply changed the load_image(std::string filename to load_image(char* filename) and removed the c_str as it was pointless. I think the tutorial I'm following is fairly old, and some of the functionality must be broken (not the first problem I've had with it).

##### Share on other sites

[font="Courier New"]
C:\Documents and Settings\Home\Desktop\SDLg1\MiniSpriteGameSDL\[color=red]main.c|17|error: syntax error before ':' token|
[/font]

Wait, main.c? Are you using C or C++? If you're compiling main.c as a C source, then it's no wonder why std::string wouldn't work...

##### Share on other sites
Yeah haha and I just noticed that too! Thanks for pointing that out, now I feel kind of silly

##### Share on other sites
I have a better idea: Learn SFML You'll be glad you did. it's so much better than SDL, and it's C++

##### Share on other sites
I have a better idea: Stay with SDL You'll be glad you did. it's so much better than SFML

##### Share on other sites

I have a better idea: Stay with SDL You'll be glad you did. it's so much better than SFML

Either you're poking fun at me for not providing details and you don't believe this...
or
You haven't spent more than 1 minute looking at what SFML provides and what SDL provides if you think it isn't worth him learning SFML.

##### Share on other sites
I looked at SFML too, and yeah, it is a lot better.

[color="#006600"][font="Courier,"]1/ Test : sprites
SDL displayed 9 frames
SFML displayed 303 frames
--> SFML is 3366% faster than SDL

2/ Test : alpha-blended sprites
SDL displayed 5 frames
SFML displayed 216 frames
--> SFML is 4320% faster than SDL

3/ Test : rotating sprites
SDL displayed 3 frames
SFML displayed 277 frames
--> SFML is 9233% faster than SDL

4/ Test : static text
SDL displayed 416 frames
SFML displayed 6092 frames
--> SFML is 1464% faster than SDL

5/ Test : dynamic text
SDL displayed 363 frames
SFML displayed 948 frames
--> SFML is 261% faster than SDL[/font]
[/quote]

Seems much faster, but I thought I'd learn both anyways, just to broaden horizon a bit.

##### Share on other sites
Seems much faster, but I thought I'd learn both anyways, just to broaden horizon a bit.

You can make SDL a little faster in that benchmark by making sure the surfaces are in the correct format. SDL_rotozoom is not even meant to be used like that because it's known to be slow. The biggest reason why SFML is faster is because it uses OpenGL. One of the things I don't like about SFML is that it doesn't give you the low level control that SDL does. Is it even possible to do pixel perfect software rendering in an efficient way in SFML? Why on earth does sf::Sleep take float and not an integer? I don't going to say that SDL is better but I think it's not as easy as saying one is better than the other. It depends on what you want to do and what your preferences are.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 21
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633383
• Total Posts
3011584
• ### Who's Online (See full list)

There are no registered users currently online

×