SDL and Pointers [solved]
Posted: Wed Aug 29, 2007 7:35 am
Ok, I'm hoping that some of you know alot about SDL, and maybe some C.
As a learning exercise, I tried to convert LazyFoo's lesson 2 found here:
http://lazyfoo.net/SDL_tutorials/lesson02/index.php Download at the bottom.
Here's what I got:
It runs without errors, but the window just comes up and immediately goes away, even if i try to add a Delay(100000). I have the images in the same directory as the .pb file.
I guess my problem is, I don't know when to use the * and @ for pointers. Can anyone tell me where and what i'm doing wrong?
Thanks.
As a learning exercise, I tried to convert LazyFoo's lesson 2 found here:
http://lazyfoo.net/SDL_tutorials/lesson02/index.php Download at the bottom.
Here's what I got:
Code: Select all
; /*This source code copyrighted by Lazy Foo' Productions (2004-2007) and may not be redestributed without written permission.*/
; //The headers
; #include "SDL/SDL.h"
; including a function not already included in PB - found this in pb forum.
libsdl = OpenLibrary(#PB_Any, "libSDL.so")
Procedure SDL_BlitSurface_( src, srcrect, dst, dstrect)
ProcedureReturn CallCFunctionFast(GetFunction(libsdl, "SDL_BlitSurface"), src, srcrect, dst, dstrect)
EndProcedure
; #include <string>
; //The attributes of the screen
; const int SCREEN_WIDTH = 640;
#SCREEN_WIDTH = 640
; const int SCREEN_HEIGHT = 480;
#SCREEN_HEIGHT = 480
; const int SCREEN_BPP = 32;
#SCREEN_BPP = 32
; //The surfaces that will be used
; SDL_Surface *message = NULL;
message.SDL_Surface
; SDL_Surface *background = NULL;
background.SDL_Surface
; SDL_Surface *screen = NULL;
screen.SDL_Surface
; SDL_Surface *load_image( std::string filename )
Procedure.l load_image(filename.s)
; {
; //Temporary storage For the image that's loaded
; SDL_Surface* loadedImage = NULL;
loadedimage.SDL_Surface
; //The optimized image that will be used
; SDL_Surface* optimizedImage = NULL;
loadedimage.SDL_Surface
; //Load the image
; loadedImage = SDL_LoadBMP( filename.c_str() );
*loadedimage = SDL_LoadBMP_RW_(SDL_RWFromFile_(@filename.s,"rb"),1)
; //If nothing went wrong in loading the image
; If( loadedImage != NULL )
If loadedimage <> #Null
; {
; //Create an optimized image
; optimizedImage = SDL_DisplayFormat( loadedImage );
*optimizedImage = SDL_DisplayFormat_(*loadedimage)
; //Free the old image
; SDL_FreeSurface( loadedImage );
SDL_FreeSurface_(*loadedImage)
; }
EndIf
; //Return the optimized image
; Return optimizedImage;
ProcedureReturn *optimizedImage
; }
EndProcedure
; void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
Procedure apply_surface(x, y, *source.SDL_Surface, *destination.SDL_Surface)
; {
; //Make a temporary rectangle To hold the offsets
; SDL_Rect offset;
offset.SDL_Rect
; //Give the offsets To the rectangle
; offset.x = x;
offset\x = x
; offset.y = y;
offset\y = y
; //Blit the surface
; SDL_BlitSurface( source, NULL, destination, &offset );
sdl_blitsurface_(*source, #Null, *destination, *offset)
; }
EndProcedure
; int main( int argc, char* args[] )
Procedure.l Main()
; {
; //Initialize all SDL subsystems
; If( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
; {
; Return 1;
; }
If SDL_Init_(#SDL_INIT_EVERYTHING)
ProcedureReturn 1
EndIf
; //Set up the screen
; screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
*screen = SDL_SetVideoMode_(#SCREEN_WIDTH, #SCREEN_HEIGHT, #SCREEN_BPP, #SDL_SWSURFACE)
; //If there was an error in setting up the screen
; If( screen == NULL )
; {
; Return 1;
; }
If *screen <> #Null
ProcedureReturn 1
EndIf
; //Set the window caption
; SDL_WM_SetCaption( "Hello World", NULL );
SDL_WM_SetCaption_("Hello World", #Null)
; //Load the images
; message = load_image( "hello_world.bmp" );
*message = load_image("hello_world.bmp")
; background = load_image( "background.bmp" );
*background = load_image("background.bmp")
; //Apply the background To the screen
; apply_surface( 0, 0, background, screen );
apply_surface(0, 0, *background, *screen)
; //Apply the message To the screen
; apply_surface( 180, 140, message, screen );
apply_surface(180, 140, *message, *screen)
; //Update the screen
; If( SDL_Flip( screen ) == -1 )
; {
; Return 1;
; }
If SDL_Flip_(*screen)
ProcedureReturn 1
EndIf
; //Wait 2 seconds
; SDL_Delay( 2000 );
SDL_Delay_(2000)
; //Free the surfaces
; SDL_FreeSurface( message );
SDL_FreeSurface_(*message)
; SDL_FreeSurface( background );
SDL_FreeSurface_(*background)
; //Quit SDL
; SDL_Quit();
SDL_Quit_()
; Return 0;
ProcedureReturn 0
; }
EndProcedure
main()
I guess my problem is, I don't know when to use the * and @ for pointers. Can anyone tell me where and what i'm doing wrong?
Thanks.