QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

PNG draw example

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, ...

Reply
 
LinkBack Thread Tools
Old 12-10-2005, 06:21 PM   #1
Mushroom Man
 
Psilocybeing's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 318
Trader Feedback: 0
Default PNG draw example

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();
Attached Files
File Type: rar PNGex.rar‎ (115.3 KB, 23 views)

Last edited by Psilocybeing; 12-10-2005 at 06:35 PM..
Psilocybeing is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-10-2005, 08:45 PM   #2
 
Soulphalanx's Avatar
 
Join Date: Sep 2005
Location: TROY
Posts: 2,989
Trader Feedback: 0
Default

any needed libraries?

other than the obvious libpng
Soulphalanx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-10-2005, 08:55 PM   #3
 
Yeldarb's Avatar
 
Join Date: Jul 2005
Posts: 984
Trader Feedback: 0
Default

Quote:
Originally Posted by Soulphalanx
any needed libraries?

other than the obvious libpng
Code:
LIBS = -lpspgu -lpng -lz -lm -lpspumd -lpsppower -lpspusb -lpspusbstor -lpspaudiolib -lpspaudio -lpsprtc -lpsputility  -lmad
(From the Makefile)
__________________
[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]
Yeldarb is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-10-2005, 09:20 PM   #4
 
Join Date: Sep 2005
Location: meh
Posts: 2,799
Trader Feedback: 0
Default

yes, you shoulda also included the makefile...
thanks anyways...
cyanide is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-11-2005, 03:03 AM   #5
Mushroom Man
 
Psilocybeing's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 318
Trader Feedback: 0
Default

The makefile is included in the archive
Psilocybeing is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-11-2005, 03:25 AM   #6
 
Join Date: Sep 2005
Location: meh
Posts: 2,799
Trader Feedback: 0
Default

/me slaps myself
cyanide is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-11-2005, 07:27 AM   #7

...
 
xigency's Avatar
 
Join Date: Oct 2005
Location: The US of A Hombrew: Quak Arena Projects: RIFT
Posts: 381
Trader Feedback: 0
Default

hey thanks, i've been looking for that too. and also, i think the more RPG's, the better :-P
__________________
...
xigency is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-12-2005, 01:40 PM   #8
Mushroom Man
 
Psilocybeing's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 318
Trader Feedback: 0
Default

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..
Psilocybeing is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-12-2005, 02:29 PM   #9
Mushroom Man
 
Psilocybeing's Avatar
 
Join Date: Sep 2005
Location: UK
Posts: 318
Trader Feedback: 0
Default

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.
Attached Files
File Type: rar gfx.rar‎ (15.4 KB, 9 views)

Last edited by Psilocybeing; 12-12-2005 at 02:58 PM..
Psilocybeing is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-16-2005, 09:23 AM   #10
 

 
Join Date: Jun 2005
Location: Canada
Posts: 1,486
Trader Feedback: 0
Default

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
Shatterdome is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
draw , png

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 03:23 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us