Displaying image in SDL

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
plysek
Posts: 7
Joined: Mon Feb 16, 2009 8:31 am

Displaying image in SDL

Post by plysek »

This simple program should display an image:

Code: Select all

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

PSP_MODULE_INFO&#40;"Przykladowa aplikacja SDL", 0, 1, 1&#41;;
PSP_HEAP_SIZE_KB&#40;20480&#41;;                              
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU&#41;;

#define printf pspDebugScreenPrintf
int exit_callback&#40; int arg1, int arg2, void *common &#41;
&#123;                                                    
        sceKernelExitGame&#40; &#41;;                        
        return 0;                                    
&#125;                                                    

int CallbackThread&#40; SceSize args, void *argp &#41;
&#123;                                             
        int cbid;                             
        cbid = sceKernelCreateCallback&#40; "Exit Callback", exit_callback, NULL &#41;;
        sceKernelRegisterExitCallback&#40; cbid &#41;;                                 
        sceKernelSleepThreadCB&#40; &#41;;                                             
        return 0;                                                              
&#125;                                                                              

int SetupCallbacks&#40; void &#41;
&#123;                         
        int thid = 0;     
        thid = sceKernelCreateThread&#40; "update_thread", CallbackThread, 0x11, 0xFA0, 0, 0 &#41;;
        if&#40;thid >= 0&#41;                                                                      
        &#123;                                                                                  
                sceKernelStartThread&#40; thid, 0, 0 &#41;;                                        
        &#125;                                                                                  
        return 0;                                                                          
&#125;                                                                                          




int InitVideo&#40; &#41; 
&#123;                
         if &#40;SDL_Init&#40; SDL_INIT_VIDEO &#41; != 0&#41;
         &#123;                                   
                printf&#40; "SDL_Init&#40;&#41;&#58; %s\n", SDL_GetError&#40;&#41; &#41;;
                SDL_Quit&#40; &#41;;                                 
                return 1;
         &#125; else return 0;
&#125;

int main&#40; int argc, char **argv &#41;
&#123;
        pspDebugScreenInit&#40; &#41;;
        SetupCallbacks&#40; &#41;;

        SDL_Surface *screen;
        screen = SDL_SetVideoMode&#40; SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE &#41;;

        SDL_Surface *image;
        SDL_Surface *temp;

        temp = SDL_LoadBMP&#40; "image.bmp" &#41;;
        if&#40; temp == NULL &#41;
        &#123;
                printf&#40; "SDL_LoadBMP&#40;&#41;&#58; %s\n", SDL_GetError&#40; &#41; &#41;;
        &#125;

        image = SDL_DisplayFormat&#40; temp &#41;;

        if&#40; image == NULL &#41;
        &#123;
                printf&#40; "SDL_DisplayFormat&#40; &#41;&#58; %s\n", SDL_GetError&#40; &#41; &#41;;
        &#125;

        SDL_FreeSurface&#40; temp &#41;;

        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&#40; screen &#41;;
        SDL_Delay&#40; 2500 &#41;;

        SDL_FreeSurface&#40; image &#41;;

        return 0;
&#125;
i have modified the code from SDL wiki, but it doesnt work. Why?

Here is my makefile:

Code: Select all

TARGET = hello
OBJS = sdl.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

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=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
and the image.bmp:
http://lysek.y0.pl/image.bmp
plysek
Posts: 7
Joined: Mon Feb 16, 2009 8:31 am

Post by plysek »

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?
User avatar
Wally
Posts: 663
Joined: Mon Sep 26, 2005 11:25 am

Post by Wally »

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
plysek
Posts: 7
Joined: Mon Feb 16, 2009 8:31 am

Post by plysek »

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.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You have to use psplinkusb with the Slim.
Post Reply