![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on PNG draw example within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I've started planning/working on an RPG(yes, yet another RPG) as I have a background in client/server work in that area, ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() Mushroom Man
|
I've started planning/working on an RPG(yes, yet another RPG) as I have a background in client/server work in that area, and wish to bring a nice little MMORPG to the PSP.
Being technically classed as a noob when it comes to coding the PSP, my years of Perl/PHP/VB have tided me along quite well thus far, but one thing that I didn't know how to do was to draw images onto the PSPs screen. I couldn't find an article or anything, but many examples in the source code of other peoples work. Here is a stripped version of one example I found, just to show how to draw a PNG image on the screen of your PSP. Below is a snippet of code that will draw a backdrop using the grass tile in the res directory. Enjoy ![]() Code:
char buffer[200];
Image* imgTest;
int x=0;
int y=0;
pspDebugScreenInit();
SetupCallbacks();
initGraphics();
sprintf(buffer,"res/grass.png");
imgTest = loadImage(buffer);
sceDisplayWaitVblankStart();
while (x < 480)
{
while (y < 272)
{
blitAlphaImageToScreen(0 ,0 ,32 , 32, imgTest, x, y);
y = y + 32;
}
x = x + 32;
y = 0;
}
flipScreen();
Last edited by Psilocybeing; 12-10-2005 at 06:35 PM.. |
|
|
|
|
|
#3 | |
![]() |
Quote:
Code:
LIBS = -lpspgu -lpng -lz -lm -lpspumd -lpsppower -lpspusb -lpspusbstor -lpspaudiolib -lpspaudio -lpsprtc -lpsputility -lmad
__________________
[url=http://www.barbdwyer.com/footer.php][img]http://www.barbdwyer.com/8Ball.jpg[/img][/url] [FONT=Verdana][SIZE=1] [b]PSP Developer Resource Site:[/b] [url=http://www.psp-programming.com]PSP-Programming.com[/url] [b]Other:[/b] [url=http://wake-boarding.org]Wakeboarding[/url], [url=http://water-skiing.org]Waterskiing[/url], [url=http://wake-surfing.org]Wake Surfing[/url], [url=http://www.guitarhero-4.com]Guitar Hero IV[/url][/SIZE][/FONT] |
|
|
|
|
|
|
#8 |
![]() Mushroom Man
|
Just a little update on the RPG, I've got the basics of rending the backdrop via a map file, using PNG tiles 18x18 in size. Should have custom map sizes sorted soon, currently it will only display a single screen, 25x14 tiles in size.
Once I've got the dynamic loading sorted, movement should be fairly easy to put it, and then rendering characters etc should be pretty easy thanks to alpha. Not a whole lot of point in posting this code, but incase anyone is wanting to work on a similar project and wants to checkout my approach to rending, here's the code . It's not perfect, but it renders fine.The format of the test.map file is 364(yeah, 25x14!=364, that's why it's not perfect) 2 digit numbers, which refer to the number of the PNG to render from the res directory. I've also included a copy of the source/res that should build straight up. Code:
int main() {
char buffer[200];
char line[2];
int xTemp=0;
int yTemp=0;
int imageCount=0;
int tileSet[25][14];
Image* imageCache[500];
FILE *fp;
pspDebugScreenInit();
SetupCallbacks();
initGraphics();
printf("Loading images");
fp = fopen("test.map", "r");
while ( fgets(line, 2, fp) != NULL)
{
if (atoi(line))
{
if (xTemp > 25)
{
xTemp = 0;
yTemp = yTemp + 1;
}
sprintf(buffer,"res/%i.png", atoi(line));
tileSet[xTemp][yTemp] = atoi(line);
if (!mapData[atoi(line)])
{
imageCache[atoi(line)] = loadImage(buffer);
printf(".");
imageCount = imageCount + 1;
}
xTemp = xTemp + 1;
}
}
fclose(fp);
printf("\n%i image loaded\nRendering(2s pause)", imageCount);
sceKernelDelayThread(2000000);
while (1)
{
int x=0;
int y=0;
int x_coord=0;
int y_coord=0;
sceDisplayWaitVblankStart();
while (x <= 462)
{
while (y <= 240)
{
blitAlphaImageToScreen(0, 0, 18, 18, imageCache[tileSet[x_coord][y_coord]], x, y);
y = y + 18;
y_coord = y_coord+1;
}
x = x + 18;
y = 0;
x_coord = x_coord+1;
y_coord = 0;
}
flipScreen();
}
sceKernelSleepThread();
return 0;
}
Last edited by Psilocybeing; 12-12-2005 at 02:36 PM.. |
|
|
|
|
|
#9 |
![]() Mushroom Man
|
By the way, if anyone can spot where I've gone wrong (25x14!=364), the pointer would be much appreciated
![]() edit: Hrm, I somehow broke that code. Sorry. edit: strange, when the imageCache variable is declared in the main function, it seems it doesn't initialise properly, returning 1 as the pointer for all of the images in the array. When it is declared as a global variable underneath the includes, it works fine. Oh well, here's the working copy :P editx3: as for 25x14, yeah 26x14=364, and a counter I've put in confirms it is outputting 364 tiles, so it's working fine, haha. Last edited by Psilocybeing; 12-12-2005 at 02:58 PM.. |
|
|
|
|
|
#10 |
![]() |
I think with any variable declared in the main() function you need to manually initialize it, which is a pain for arrays....but when declared globably (under the #includes) then the compiler will automagically initialize it for you...
__________________
PSN: Shatterdome |
|
|
|
![]() |
| Tags |
| draw , png |
| Thread Tools | |
|
|