Thread: sdl blitting

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    sdl blitting

    ok im using this tutorial

    http://lazyfooproductions.com/SDL_tu...on02/index.php


    i have it set SDL installed fully i even downloaded to source for this but it still wont work,the screen goes up but its completely black! this is so annoying


    wait do the contents of the sdl folders have to be emptied into into the dev-cpp folder or can i just leave them in the folders and compy the folders?
    Last edited by lilhawk2892; 09-16-2006 at 01:51 PM.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Post your code. Assuming you're using the exact code that the tutorial provides:
    Code:
    /*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;    
    }
    You must not be compiling it properly if the code above produces a black screen. (Or maybe the images loaded in the code don't exist or something.) You might want to read the part of the tutorial that covers this: http://lazyfooproductions.com/SDL_tu...on01/index.php
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    actually ive done everything needed...ive even made a folder and put the code and images in it

    i have it at empty project

    project options>the gui one>parameters>-lmingw32 -lSDLmain -lSDL


    and ive just checked over the cotnents of my dev-cpp folders to make sure sdl is installed correctly..i get nothing ill read over the images part again it might help

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    With my very old version of Dev-C++, I actually had to add -lSDL.dll in (otherwise I got a black screen!), and the order of them mattered. I used
    Code:
    -lSDL.dll -lSDL -lSDLmain
    [edit] The images have to be in the same directory as the executable. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    thanks!!!!! hmm well while im at it might as well check to see if my dev is old


    EDIT:IT WORKED!!!!! im blitting ,IM BLITTING


    thanks i dont know why it didnt work before!

    well i suppose i should really break down the code (shouldnt take more than an hour)

    but thank you so much! now i just need to worry about the problems ill face in the other tutorials....YOU ARE god ...atleast at SDL
    Last edited by lilhawk2892; 09-16-2006 at 03:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems compiling this SDL app
    By Rider in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2007, 12:22 PM
  2. SDL and MinGW Studio
    By Vicious in forum Tech Board
    Replies: 0
    Last Post: 07-30-2004, 09:59 PM
  3. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  4. maps, tilesets, and blitting (SDL)
    By Flikm in forum Game Programming
    Replies: 1
    Last Post: 07-31-2002, 03:07 PM
  5. sdl in c++
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-07-2002, 07:46 AM