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 

Cursor Problem (SDL)

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



Joined: 12 Dec 2005
Posts: 2

PostPosted: Mon Dec 12, 2005 7:52 pm    Post subject: Cursor Problem (SDL) Reply with quote

A couple of days ago I decided to start learning how to use SDL. After a bit of searching, I found this topic. I went on ahead and started working on my own program to introduce myself, using the changes from the lesson2.cpp file that pspblizz provided.

I managed to get something compiled rather easily. When I ran it on my PSP, I was expecting something to go wrong, like getting one of the error messages or having my PSP explode, but what happened was completely unexpected. The screen was all black, except for an unmovable cursor in the upper left corner. I tinkered around with the code for a while, but all I managed to do was make the cursor blink when I tried different video modes.

I was completely clueless about what was going on (and still am), so I decided to compile the lesson2.cpp from the topic I mentioned above, and exactly the same thing occured.

Here is my code, in case that is the source of the problem:
Code:
//////// Includes ////////
#include <pspkernel.h>
#include <pspdebug.h>

#include <stdlib.h>

#include <SDL.h>

//////// Definitions ////////
#define printf pspDebugScreenPrintf
#define PSP_SCREEN_WIDTH 480
#define PSP_SCREEN_HEIGHT 272

//////// Function Prototypes ////////
void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B);
void Slock(SDL_Surface *screen);
void Sulock(SDL_Surface *screen);

//////// Main Function ////////
extern "C" int SDL_main(int argc, char *argv[])
{
    if(SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("Unable to initiate video:\n%s", SDL_GetError());
        sceKernelSleepThread();   
    }
    atexit(SDL_Quit);
   
    SDL_Surface *screen;
    screen = SDL_SetVideoMode(480, 272, 32, SDL_SWSURFACE | SDL_FULLSCREEN);
    if(screen == NULL)
    {
        printf("Unable to set 480x272x32 video mode:\n%s", SDL_GetError());
        sceKernelSleepThread();
    }
   
    while(1)
    {
        Slock(screen);
        for(int ly=0; ly >= PSP_SCREEN_HEIGHT; ly++)
        {
            for(int lx=0; lx >= PSP_SCREEN_WIDTH; lx++)
            {
                DrawPixel(screen, lx, ly, rand()%256, rand()%256, rand()%256);
            }
        }
        Sulock(screen);
        SDL_Flip(screen);
    }
    sceKernelSleepThread();
    return 0;
}

//////// Function Definitions ////////
void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B)
{
    Uint32 color = SDL_MapRGB(screen->format, R, G, B);
    switch (screen->format->BytesPerPixel)
    {
        case 1: // Assuming 8-bpp
        {
            Uint8 *bufp;
            bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
            *bufp = color;
        }
        break;
        case 2: // Probably 15-bpp or 16-bpp
        {
            Uint16 *bufp;
            bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
            *bufp = color;
        }
        break;
        case 3: // Slow 24-bpp mode, usually not used
        {
            Uint8 *bufp;
            bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
            if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
            {
                bufp[0] = color;
                bufp[1] = color >> 8;
                bufp[2] = color >> 16;
            }
            else
            {
            bufp[2] = color;
            bufp[1] = color >> 8;
            bufp[0] = color >> 16;
            }
        }
        break;
        case 4: // Probably 32-bpp
        {
            Uint32 *bufp;
            bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
            *bufp = color;
        }
        break;
    }
}

void Slock(SDL_Surface *screen)
{
    if ( SDL_MUSTLOCK(screen) )
    {
        if ( SDL_LockSurface(screen) < 0 )
        {
            return;
        }
    }
}

void Sulock(SDL_Surface *screen)
{
    if ( SDL_MUSTLOCK(screen) )
    {
        SDL_UnlockSurface(screen);
    }
}

I'll also post the contents of the Makefile, just in case:
Code:
TARGET = sdltest
OBJS = main.o

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

LIBDIR =
LDFLAGS =
LIBS= -lpspgu

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SDL Test

PSPSDK=$(shell psp-config --pspsdk-path)
PSPBIN = $(PSPSDK)/../bin
CFLAGS += `$(PSPBIN)/sdl-config --cflags`
LIBS += `$(PSPBIN)/sdl-config --libs`
include $(PSPSDK)/lib/build.mak

If anyone needs any more information to figure out why the cursor is appearing, please ask.

Thanks in advance.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Mon Dec 12, 2005 10:36 pm    Post subject: Reply with quote

Call SDL_ShowCursor(SDL_DISABLE) to disable the cursor. Visit http://www.libsdl.org/ for SDL API documentation.
Back to top
View user's profile Send private message
Lancer



Joined: 12 Dec 2005
Posts: 2

PostPosted: Tue Dec 13, 2005 10:04 am    Post subject: Reply with quote

Looks like the drawpixel function is what was causing nothing to appear. Once I moved on to blitting images things started working out much better.

Thanks to mrbrown for the link.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
rinco



Joined: 21 Jan 2005
Posts: 255
Location: Canberra, Australia

PostPosted: Tue Dec 13, 2005 6:52 pm    Post subject: Reply with quote

The DrawPixel function looks good and it is unlikely that using blits updated the video display. Are you using the most recent version of SDL from svn?

edit: this seems to fix it...
Code:
        for(int ly=0; ly < PSP_SCREEN_HEIGHT; ly++)
        {
            for(int lx=0; lx < PSP_SCREEN_WIDTH; lx++)
            {
                DrawPixel(screen, lx, ly, rand()%256, rand()%256, rand()%256);
            }
        }

Back to top
View user's profile Send private message
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