Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL Again...

Started by ozzoright Apr 20, 2006 at 7:02 PM 7 replies 4.3k views
Original Post
ozzoright
ozzoright
I got SDL working, sorda. I ran this program from the Lazy Foo Tutorials:
/*This source code copyrighted by Lazy Foo' Productions(2006) and may not be redestributed without written permission.*/

#include "SDL/SDL.h"

int main(int argc, char* args[])
{
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );
    
    //Quit SDL
    SDL_Quit();
    
    return 0;    
}





It works fine, no errors. Then I read the next tutorial:
/*This source code copyrighted by Lazy Foo' Productions(2006) and may not be redestributed without written permission.*/

//The headers
#include "SDL/SDL.h"
#include <string>

//The 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;

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;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
    //Make a temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Give the offsets to the rectangle
    offset.x = x;
    offset.y = y;
    
    //Blit the surface
    SDL_BlitSurface( source, NULL, destination, &offset );
}

int main( int argc, char* args[] )
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return 1;    
    }
    
    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
    
    //If there was in error in setting up the screen
    if( screen == NULL )
    {
        return 1;    
    }
    
    //Set the window caption
    SDL_WM_SetCaption( "Hello World", NULL );
    
    //Load the images
    message = load_image( "hello_world.bmp" );
    background = load_image( "background.bmp" );
    
    //Apply the background to the screen
    apply_surface( 0, 0, background, screen );
    
    //Apply the message 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;    
}





Ran it, and got the following errors: multiple definition of 'SDL_main' [Build Error] [SDL_Tutorial.exe] Error 1 I really appreciate the help guys, thanks. -Scott [Edited by - ozzoright on April 20, 2006 7:39:16 PM]
Ezbez
Ezbez
1.) Didn't I just see a giant warning at the top of that code saying that you could not distribute it without written consent? Sorry for pointing this out if you do have written consent, but....

2.)Use [ source ] and [ /source ] tags around code. It makes in more legible and more people will look at it. Just remove the spaces from what I posted above and put your code inside. It creates a nice, little window with a scroll bar for everyone to read.

As for the problem, it might be a linking problem of some sort. What libraries are you linking to?
matthughson
matthughson
You don't have both files opened in the same project or something do you? The error sounds like you have two "main" functions defined.

Matt
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Synt4x
Synt4x
im also having an SDL program, I did AAron Cox first introduction tutorial in VS6.0, but now I just downloaded Visual C++ 2005 Express, the free one everyone keeps tellin me to get. but NOW, I take my old code files, put them into Visual C++ 2005 Express. and now I get this error:


Compiling...
Main.cpp
Compiling manifest to resources...
Linking...
LINK : fatal error LNK1104: cannot open file 'uuid.lib'

can you guys explain to me what uuid.lib is or where I get it or make it not try to load it? thanks for your help,

-Karakadin
ozzoright
ozzoright
Quote:
Original post by Ezbez
1.) Didn't I just see a giant warning at the top of that code saying that you could not distribute it without written consent? Sorry for pointing this out if you do have written consent, but....

2.)Use [ source ] and [ /source ] tags around code. It makes in more legible and more people will look at it. Just remove the spaces from what I posted above and put your code inside. It creates a nice, little window with a scroll bar for everyone to read.

As for the problem, it might be a linking problem of some sort. What libraries are you linking to?


Oh s***, didn't think about that, so I can't post them on this forum, crap, should I pull them then?

I'm linking these libraries to the project:

-lmingw32
-lSDLmain
-lSDL

If that answers your question, I'm an ub3r n00b by the way.
IronGryphon
IronGryphon
Just curious. you did set your project to multithreaded dll right?
SDBradley
CGP
"A person who won't read has no advantage over one who can't read." ~Mark Twain
ozzoright
ozzoright
"I'm an ub3r n00b by the way."

I don't know, how do I do that?

[Edited by - ozzoright on April 20, 2006 7:36:05 PM]
pascalosti
pascalosti
these are the ones I had linked in project options/ parameters/ linker ( i dont think the last 3 are necessary)
-lmingw32 -lSDLmain -lSDL -lSDL_image -lSDL_ttf -lSDL_mixer -ISDL_gfxPrimitives

compiles fine for me, i'd go throught uploading sdl library extensions tutorial again. Im learing SDL too :-)
also try these tutorials:

http://mavdisk.mnsu.edu/longaj/cornerstone.htm

sometimes a different view helps
ozzoright
ozzoright
Wow, thanks everybody. Gamedev has the most n00b friendly forums I know of.

Thanks again everybody.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.