-
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?
-
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
-
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
-
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]
-
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