Problem getting Image to display.

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

Moderators: cheriff, TyRaNiD

Post Reply
JesusXP
Posts: 79
Joined: Tue Jan 17, 2006 11:16 am
Location: Ontario, Canada

Problem getting Image to display.

Post by JesusXP »

Hi guys... I'll post my code here, and maybe you can let me know whats wrong, I'm trying to get a picture to display and than control him with the d-pad. This is just mashing together stuff I learned from the scriptscribbler.com/psp tut's...

Code: Select all

/*	
	Program Name: Fuckin Around - Part Deux
	Author: Mark Pereira
	Date: Wed Feb 8, 1:19AM
*/

#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include "graphics.h"

#define printf pspDebugScreenPrintf
#define MAX&#40;X,Y&#41; &#40;&#40;X&#41;>&#40;Y&#41;?&#40;X&#41;&#58;&#40;Y&#41;&#41;

PSP_MODULE_INFO&#40;"Fuckin Around - Part Deux", 0, 1, 1&#41;;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;&#123;
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

/* Callback thread */
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;
/* Sets up the callback thread and returns its thread id */
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 thid;
&#125;

int main&#40;&#41;&#123;

	SceCtrlData pad;
	char buffer&#91;200&#93;;
	Image* ourImage;
	
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	initGraphics&#40;&#41;;
	
	sprintf&#40;buffer, "meDude.png"&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	
	if&#40;!ourImage&#41;&#123;
		//Image load failed
		printf&#40;"Image load failed!\n"&#41;;
	&#125;else&#123;
		int x = 0;
		int y = 0;

		sceDisplayWaitVblank&#40;&#41;;
		blitAlphaImageToScreen&#40;0, 0, 32, 32, ourImage, x, y&#41;;
		while&#40;1&#41;&#123;
			sceDisplayWaitVblankStart&#40;&#41;;
			
			sceCtrlReadBufferPositive&#40;&pad, 1&#41;;

			if&#40;pad.Buttons & PSP_CTRL_LEFT&#41;&#123;
				if&#40;x>0&#41;&#123;x--;&#125;
			&#125;

			if&#40;pad.Buttons & PSP_CTRL_RIGHT&#41;&#123;
				if&#40;x<480-32&#41;&#123;x++;&#125;
			&#125;
			
			if&#40;pad.Buttons & PSP_CTRL_UP&#41;&#123;
				if&#40;y>0&#41;&#123;y--;&#125;
			&#125;
			
			if&#40;pad.Buttons & PSP_CTRL_DOWN&#41;&#123;
				if&#40;y<272-32&#41;&#123;y++;&#125;
			&#125;
			
		&#125;	
		
		flipScreen&#40;&#41;;
	&#125;
	
	sceKernelSleepThread&#40;&#41;;
	return 0;
&#125;

I havent got a clue, please help.... I have compiled (make kxploit) I have placed theDude.png in the same folders on the psp (/fuckinround , /fuckinround2%), No clue now what to do, Any help would be greatly appreciated, thanks.
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

Post by NovaCaine »

Hey JesusXP,

Well for starters your loading an image called meDude.png. Are you able to just load up the image and show it without moving it around?

Is the code just exiting right away or is it just giving you a black screen?

Other than that, I can't see any problems with your code at this point

EDIT: Just trying to run your code now, and noticed that above blitAlphaImageToScreen you should have sceDisplayWaitVblankStart, not sceDisplayWaitVblank.

EDIT2: Hmm, Ok got it compiling now, but I just get a black screen.....

Have to go now, and I don't have the net at home atm, so I'll give it another try tomorrow, unless you've fixed it by then :P
Last edited by NovaCaine on Thu Feb 09, 2006 1:57 pm, edited 1 time in total.
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Can't see anything special there too. More information would be good, at least what actually happens when you start the program.

Then, my first guess would be the image isn't loaded correctly, so try giving the complete path to your image to the loader first, ie "ms0:/PSP/GAME/YOURFOLDER/meDude.png". That seems to often be the problem with getting data from the stick loaded.
NovaCaine
Posts: 34
Joined: Tue Dec 20, 2005 3:31 pm
Location: New Zealand
Contact:

Post by NovaCaine »

Thats what I originally thought too, but it loads something, it just doesn't render to the screen. And correct me if I'm wrong JesusXP, but this code looks exactly like lesson 4 from Yeldarb site
Wil
Posts: 15
Joined: Wed Feb 23, 2005 7:30 pm
Location: Las Vegas
Contact:

Post by Wil »

Uhm... wow. Try this.

Code: Select all

/*   
   Program Name&#58; Fuckin Around - Part Deux
   Author&#58; Mark Pereira
   Date&#58; Wed Feb 8, 1&#58;19AM
*/

#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include "graphics.h"

#define printf pspDebugScreenPrintf
#define MAX&#40;X,Y&#41; &#40;&#40;X&#41;>&#40;Y&#41;?&#40;X&#41;&#58;&#40;Y&#41;&#41;

PSP_MODULE_INFO&#40;"Fuckin Around - Part Deux", 0, 1, 1&#41;;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;&#123;
   sceKernelExitGame&#40;&#41;;
   return 0;
&#125;

/* Callback thread */
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;
/* Sets up the callback thread and returns its thread id */
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 thid;
&#125;

int main&#40;&#41;&#123;

   SceCtrlData pad;
   Image* ourImage;
   int x = 0;
   int y = 0;
   
   pspDebugScreenInit&#40;&#41;;
   SetupCallbacks&#40;&#41;;
   initGraphics&#40;&#41;;

   ourImage = loadImage&#40;"meDude.png"&#41;;

   while&#40;1&#41;&#123;
      
      sceCtrlReadBufferPositive&#40;&pad, 1&#41;;

      if&#40;pad.Buttons & PSP_CTRL_LEFT&#41;&#123;
         if&#40;x>0&#41;&#123;x--;&#125;
      &#125;

      if&#40;pad.Buttons & PSP_CTRL_RIGHT&#41;&#123;
         if&#40;x<480-32&#41;&#123;x++;&#125;
      &#125;
         
      if&#40;pad.Buttons & PSP_CTRL_UP&#41;&#123;
         if&#40;y>0&#41;&#123;y--;&#125;
      &#125;
         
      if&#40;pad.Buttons & PSP_CTRL_DOWN&#41;&#123;
         if&#40;y<272-32&#41;&#123;y++;&#125;
      &#125;

      blitAlphaImageToScreen&#40;0, 0, 32, 32, ourImage, x, y&#41;;
      flipScreen&#40;&#41;;
         
   &#125;

   return 0;
&#125;
*SHOULD* work -- see, you sent the image to the screen buffer and then entered an infinate loop. You never got to flipScreen() so it never displayed. Good luck.

Wil
Wil
JesusXP
Posts: 79
Joined: Tue Jan 17, 2006 11:16 am
Location: Ontario, Canada

Post by JesusXP »

I was on the irc room with Loco-san and we were able to get it working!!



This is the newly modified code, I really appreciate all the fast feedback, I used #pspdev on efnet as well though, and was able to get some real-time interaction and help. Thanks again though..


And you are correct, this is mostly made up of the code from Lesson 4


Code: Select all


/*	
	Program Name&#58; Fuckin Around - Part Deux
	Author&#58; Mark Pereira
	Date&#58; Wed Feb 8, 1&#58;19AM
*/

#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include "graphics.h"

#define printf pspDebugScreenPrintf
#define MAX&#40;X,Y&#41; &#40;&#40;X&#41;>&#40;Y&#41;?&#40;X&#41;&#58;&#40;Y&#41;&#41;

PSP_MODULE_INFO&#40;"Fuckin Around - Part Deux", 0, 1, 1&#41;;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;&#123;
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

/* Callback thread */
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;
/* Sets up the callback thread and returns its thread id */
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 thid;
&#125;

int main&#40;&#41;&#123;

	SceCtrlData pad;
	char buffer&#91;200&#93;;
	Image* ourImage;
	
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	initGraphics&#40;&#41;;
	
	sprintf&#40;buffer, "meDude.png"&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	
	if&#40;!ourImage&#41;&#123;
		//Image load failed
		printf&#40;"Image load failed!\n"&#41;;
	&#125;else&#123;
		int x = 0;
		int y = 0;
		sceDisplayWaitVblankStart&#40;&#41;;
		
		while&#40;1&#41;&#123;
			clearScreen&#40;0&#41;;
			blitAlphaImageToScreen&#40;0, 0, 32, 32, ourImage, x, y&#41;;
			
			
			sceCtrlReadBufferPositive&#40;&pad, 1&#41;;

			if&#40;pad.Buttons & PSP_CTRL_LEFT&#41;&#123;
				if&#40;x>0&#41;&#123;x--;&#125;
			&#125;

			if&#40;pad.Buttons & PSP_CTRL_RIGHT&#41;&#123;
				if&#40;x<&#40;480-32&#41;&#41;&#123;x++;&#125;
			&#125;
			
			if&#40;pad.Buttons & PSP_CTRL_UP&#41;&#123;
				if&#40;y>0&#41;&#123;y--;&#125;
			&#125;
			
			if&#40;pad.Buttons & PSP_CTRL_DOWN&#41;&#123;
				if&#40;y<&#40;272-32&#41;&#41;&#123;y++;&#125;
			&#125;
			sceDisplayWaitVblank&#40;&#41;;
			flipScreen&#40;&#41;;
		&#125;	
	
	&#125;
	
	sceKernelSleepThread&#40;&#41;;
	return 0;
&#125;
Post Reply