Sign in to follow this  
Skizlar

issue with visual C++/SDL... please help

Recommended Posts

I just started Lazy Foo's SDL tutorial a few hours ago and I've hit a major roadblock. I completed tutorial 1 (the install and test tutorial) without a hitch and promptly moved on to tutorial 2. I should probably say that I have been writing simple programs with C++ for nearly 2 years now and have a firm grasp on the basics of the language. I haven't been using Visual C++ quite as long and I'm not too familiar with the inner workings of linkers and such but I usually don't have many problems debugging my code. Anyway, I'm feeling impatient and want to move on with the tutorials. So now with my problem... I followed the tutorial word for word and wrote the program on my own, no copy and pasting. I added in function prototypes instead of using the in-line format Foo uses and moved the function definitions to the end of the file. Then, when I compiled, Visual C++ gave me "error C3861: 'SDL_DiplayFormat': identifier not found" I don't know if I'm missing something obvious or what but I've tried re-installing SDL and reformatting my code to fit the style Foo uses but still get the same error. From my understanding this error comes up when you don't declare a function prototype but this function is part of the SDL library so there should be no problem. Any advice will be greatly appreciated as I want to move on with SDL soon so I can start writing graphics into my games. Text-based games were fun for awhile but it's time to move on.

Share this post


Link to post
Share on other sites
Nobody can really help you with this question because you have not shown us anything to be able to determine where your problem may lie. Seeing as you stated that you didn't copy/paste and that you copied it by hand, I have two guesses:

Did you #include "SDL.h"?

Did you forget that SDL_DisplayFormat() is a function, not a variable and thus requires that you include the '()'?

It seems that you don't have nearly as firm a grasp on C++ as you may think... ;) Note that this is not a Visual C++ issue but a syntax issue.

Share this post


Link to post
Share on other sites
Here is the full source file as I have it now. Visual C++ knows the paths for the SDL Include and Library files and SDL.lib and SDLmain.lib are listed under additional dependencies in the linker properties. Also, SDL.dll is in the same file as the project. Forgive me for not be specific enough the first time but I'm sure you don't like reading through other peoples code as much as me.

This is a basic basic program that blits a message ("hello world") onto a background image.

#include "SDL.h" //I don't think this is the problem because all the other
#include <string> //SDL functions work fine..

//attributes of the screen
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//the surfaces that will be used
SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;

//image loader function
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 loading the image
if( loadedImage != NULL )
{


//!!Here is where the error comes up. As you can see, the () are
//!!right where they should be

//Create an optimized image
optimizedImage = SDL_DiplayFormat( loadedImage );

//Free the old image
SDL_FreeSurface( loadedImage );
}

return optimizedImage;
}






Again, the error given to me was:

": error C3861: 'SDL_DiplayFormat': identifier not found"

Really if it's a syntax error and you find it, call me an idiot all you like because I've been staring at this thing for hours and I've found nothing. Again any advice is greatly appreciated. I'll keep toying around with it to see if I can get it to work.

You probably don't need the rest but here it is anyway, just for good measure.




//surface blitting function
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
//Make a temporary rectangle to hold the offsets
SDL_Rect offset;

//set the rectangle offsets
offset.x = x;
offset.y = y;

//blit the surface
SDL_BlitSurface( source, NULL, destination, &offset );
}



int main( int argc, char* args[] )
{
//Start SDL and check to see if it started properly
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return 1;
}

//set up the screen
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

//make sure the screen set up properly
if ( screen == NULL )
{
return 1;
}

//Set the window caption
SDL_WM_SetCaption( "Hello World", NULL );

//Load the images
message = load_image( "message.bmp" );
background = load_image( "background.bmp" );

//apply the background to the screen
apply_surface( 0, 0, background, screen);

//apply the maessage to the screen
apply_surface( 180, 140, message, screen );

//update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}

//wait 2 seconds
SDL_Delay( 2000 );

//free the surfaces
SDL_FreeSurface( message );
SDL_FreeSurface( background );

//Quit SDL
SDL_Quit();

return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by phresnel
Maybe because SDL_DiplayFormat != SDL_DisplayFormat?
Skizlar, did you try correcting this spelling mistake?
Quote:
Original post by Skizlar
forgive the messy code the tabs didn't post for some reason...
You need to surround it with [ source] [/source] tags.

Share this post


Link to post
Share on other sites
Quote:
Original post by Skizlar
Good lord....

Thanks I'm going to go slam my head in a door now.


Be grateful for the error you just made. Every obstacle you pass becomes a fragment of The Great Wisdom ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this