 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Lancer
Joined: 12 Dec 2005 Posts: 2
|
Posted: Mon Dec 12, 2005 7:52 pm Post subject: Cursor Problem (SDL) |
|
|
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 |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Mon Dec 12, 2005 10:36 pm Post subject: |
|
|
| Call SDL_ShowCursor(SDL_DISABLE) to disable the cursor. Visit http://www.libsdl.org/ for SDL API documentation. |
|
| Back to top |
|
 |
Lancer
Joined: 12 Dec 2005 Posts: 2
|
Posted: Tue Dec 13, 2005 10:04 am Post subject: |
|
|
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 |
|
 |
rinco
Joined: 21 Jan 2005 Posts: 255 Location: Canberra, Australia
|
Posted: Tue Dec 13, 2005 6:52 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|