forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Displaying image in SDL

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
plysek



Joined: 16 Feb 2009
Posts: 7

PostPosted: Mon Feb 23, 2009 9:22 am    Post subject: Displaying image in SDL Reply with quote

This simple program should display an image:
Code:

#include <SDL/SDL.h>                                                                                                                                                   
#include <pspdebug.h>                                                                                                                                                 
#include <pspkernel.h>                                                                                                                                                 
#define SCREEN_WIDTH 480                                                                                                                                               
#define SCREEN_HEIGHT 272                                                                                                                                             

PSP_MODULE_INFO("Przykladowa aplikacja SDL", 0, 1, 1);
PSP_HEAP_SIZE_KB(20480);                             
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU);

#define printf pspDebugScreenPrintf
int exit_callback( int arg1, int arg2, void *common )
{                                                   
        sceKernelExitGame( );                       
        return 0;                                   
}                                                   

int CallbackThread( SceSize args, void *argp )
{                                             
        int cbid;                             
        cbid = sceKernelCreateCallback( "Exit Callback", exit_callback, NULL );
        sceKernelRegisterExitCallback( cbid );                                 
        sceKernelSleepThreadCB( );                                             
        return 0;                                                             
}                                                                             

int SetupCallbacks( void )
{                         
        int thid = 0;     
        thid = sceKernelCreateThread( "update_thread", CallbackThread, 0x11, 0xFA0, 0, 0 );
        if(thid >= 0)                                                                     
        {                                                                                 
                sceKernelStartThread( thid, 0, 0 );                                       
        }                                                                                 
        return 0;                                                                         
}                                                                                         




int InitVideo( )
{               
         if (SDL_Init( SDL_INIT_VIDEO ) != 0)
         {                                   
                printf( "SDL_Init(): %s\n", SDL_GetError() );
                SDL_Quit( );                                 
                return 1;
         } else return 0;
}

int main( int argc, char **argv )
{
        pspDebugScreenInit( );
        SetupCallbacks( );

        SDL_Surface *screen;
        screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE );

        SDL_Surface *image;
        SDL_Surface *temp;

        temp = SDL_LoadBMP( "image.bmp" );
        if( temp == NULL )
        {
                printf( "SDL_LoadBMP(): %s\n", SDL_GetError( ) );
        }

        image = SDL_DisplayFormat( temp );

        if( image == NULL )
        {
                printf( "SDL_DisplayFormat( ): %s\n", SDL_GetError( ) );
        }

        SDL_FreeSurface( temp );

        SDL_Rect src, dest;

        src.x = 0;
        src.y = 0;
        src.w = image->w;
        src.h = image->h;

        dest.x = 100;
        dest.y = 100;
        dest.w = image->w;
        dest.h = image->h;

        SDL_Flip( screen );
        SDL_Delay( 2500 );

        SDL_FreeSurface( image );

        return 0;
}


i have modified the code from SDL wiki, but it doesnt work. Why?

Here is my makefile:
Code:

TARGET = hello
OBJS = sdl.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP
LIBS = -lSDL -lGL -lz -lpng -lm -ljpeg -lpsppower_driver -lpspvfpu -lpsphprm -lpsprtc -lpspaudio -lpspgu -lpspirkeyb -lpsppower
PSP_EBOOT_TITLE = Test SDL

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak


and the image.bmp:
http://lysek.y0.pl/image.bmp
Back to top
View user's profile Send private message
plysek



Joined: 16 Feb 2009
Posts: 7

PostPosted: Mon Feb 23, 2009 9:31 am    Post subject: Reply with quote

hmm i forgot to init the video, but still it doesnt show the image...
ekhm ok i did now the SDL_BlitSurface( image, NULL, screen, &src);
and it works! but he problem that it waits a moment with the image displayed and then psp power off automaticly, and i can even push home to exit, why is that?
Back to top
View user's profile Send private message
Wally



Joined: 26 Sep 2005
Posts: 672

PostPosted: Mon Feb 23, 2009 9:43 am    Post subject: Reply with quote

plysek wrote:
hmm i forgot to init the video, but still it doesnt show the image...
ekhm ok i did now the SDL_BlitSurface( image, NULL, screen, &src);
and it works! but he problem that it waits a moment with the image displayed and then psp power off automaticly, and i can even push home to exit, why is that?


Sounds like a bus error.. I suggest setting PSPLink up will fix it
Back to top
View user's profile Send private message AIM Address
plysek



Joined: 16 Feb 2009
Posts: 7

PostPosted: Tue Feb 24, 2009 1:42 am    Post subject: Reply with quote

it doesnt work on my psp, i have 5.0m33-3 slim it says with v1.0 "The game could not be started" and with v1.5 and v1.5_nocorrupt it is corrupted data.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Feb 24, 2009 5:27 pm    Post subject: Reply with quote

You have to use psplinkusb with the Slim.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group