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!

need help quickly

This is a discussion on need help quickly within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; OSL_IMAGE *tar; int main(int argc, char **argv) { //Initialization of the Oslib library oslInit(0); //Initialization of the graphics mode oslInitGfx(OSL_PF_8888, ...

Reply
 
LinkBack Thread Tools
Old 02-01-2009, 05:40 PM   #1

 
Join Date: Feb 2009
Posts: 69
Trader Feedback: 0
Default need help quickly

Quote:
OSL_IMAGE *tar;

Quote:
int main(int argc, char **argv)
{
//Initialization of the Oslib library
oslInit(0);

//Initialization of the graphics mode
oslInitGfx(OSL_PF_8888, 1);

oslInitConsole(); //Text

oslSetTransparentColor(RG B(255,0,255));



//loads our images into memory
if(load_tar==0)tar = oslLoadImageFile("tar.png ", OSL_IN_RAM, OSL_PF_5551);
if(load_tar==1)tar= oslLoadImageFile("tar1.pn g", OSL_IN_RAM, OSL_PF_5551);
if(load_tar==2)tar = oslLoadImageFile("tar2.pn g", OSL_IN_RAM, OSL_PF_5551);
if(load_tar==3)tar = oslLoadImageFile("tar3.pn g", OSL_IN_RAM, OSL_PF_5551);
Quote:
if(osl_keys->held.right) then load_tar=0;//if I press right i want a different image to load a the reason is that i have alot of code structured around "tar" so i dnt wana have to add like tar1 or tar 2 n double up the main.c
if(osl_keys->held.left) then load_tar=1;
//the load_tar interger is changed but the image doesnt
plz show or direct me to do this properly
kronicali is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-01-2009, 10:00 PM   #2

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

Post the whole code please. (How did you know that the value changed?)
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-01-2009, 11:09 PM   #3

 
Join Date: Feb 2009
Posts: 69
Trader Feedback: 0
Default

i placed a print statement saying "if(load_tar==1)print blah blah on screen"...thats how i knew the value changed..i was wondering if its because the the loadimage function in the main and is called only once? when i change the value of the "int load_tar;" to "int load_tar=0;" manually it loads whatever i set the value to but when i try to pressing left or right in the game the value changes but not the image.
kronicali is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-01-2009, 11:17 PM   #4
The Cake Is A LIE
 
slasher101's Avatar
 
My Mood: Daring
Join Date: Oct 2008
Real First Name: Adam
Location: Melbourne, Australia
Just Played: Far Cry 2
Posts: 669
Blog Entries: 1
Trader Feedback: 0
Default

the CODE, not an explination.

~!SlasheR!~
slasher101 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 02:45 AM   #5

Developer
 
slicer4ever's Avatar
 
Join Date: Jul 2005
Location: everywhere
Posts: 3,357
Trader Feedback: 0
Default

Quote:
loadimage function in the main and is called only once?
yes, if ur only calling it once than that means the image well always be it's initial value, here's how to properly do it:

assuming c++
Code:
//init code
int main(int argc, char **argv){
   int disp_img = 0; //similar to your load_tar
   OSL_IMAGE **Images = new OSL_IMAGE[4];
   Images[0] = oslLoadImageFile("tar.png ", OSL_IN_RAM, OSL_PF_5551);
   Images[1] = oslLoadImageFile("tar1.png ", OSL_IN_RAM, OSL_PF_5551);
   Images[2] = oslLoadImageFile("tar2.png ", OSL_IN_RAM, OSL_PF_5551);
   Images[3] = oslLoadImageFile("tar3.png ", OSL_IN_RAM, OSL_PF_5551);
   while(!osl_quit){
      oslReadKeys();
      oslStartDrawing();
      oslDrawImage(Images[disp_img]);
      oslEndDrawing();
      if(osl_keys->held.left){
          disp_img = 1;
      }
      //all other img changes based on button presses go here
  }
  //release images, and quit oslib calls

  return 0;
}
i haven't used oslib in a while so if i forgot anything my bad, but that's how you would go about in switching between multiple images
__________________
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
slicer4ever is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 06:11 AM   #6

Developer
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,317
Trader Feedback: 0
Default

Code:
OSL_IMAGE **Images = new OSL_IMAGE[4];
Why dynamically allocate memory?
Code:
OSL_IMAGE *Images[4];
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 08:15 AM   #7

 
Join Date: Feb 2009
Posts: 69
Trader Feedback: 0
Default

Quote:

yes, if ur only calling it once than that means the image well always be it's initial value, here's how to properly do it:

assuming c++
Code:

//init code
int main(int argc, char **argv){
int disp_img = 0; //similar to your load_tar
OSL_IMAGE **Images = new OSL_IMAGE[4];
Images[0] = oslLoadImageFile("tar.png ", OSL_IN_RAM, OSL_PF_5551);
Images[1] = oslLoadImageFile("tar1.pn g ", OSL_IN_RAM, OSL_PF_5551);
Images[2] = oslLoadImageFile("tar2.pn g ", OSL_IN_RAM, OSL_PF_5551);
Images[3] = oslLoadImageFile("tar3.pn g ", OSL_IN_RAM, OSL_PF_5551);
while(!osl_quit){
oslReadKeys();
oslStartDrawing();
oslDrawImage(Images[disp_img]);
oslEndDrawing();
if(osl_keys->held.left){
disp_img = 1;
}
//all other img changes based on button presses go here
}
//release images, and quit oslib calls

return 0;
}
i only have started like 2days ago...and its C i read somewhere about malloc not too sure about how to impliment it though anyway i did this and the psp crashed..i did some simple arrays before using text and had no problems but this is drive me nutts!


Quote:
//OSlib header file
#include <oslib/oslib.h>

//Necessary to create eboot
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THRE AD_ATTR_USER | THREAD_ATTR_VFPU);

//declaration of the pointers of our images
OSL_IMAGE *pic0,*tar[4];


int i=2;
int main(int argc, char **argv)
{
//Initialization of the Oslib library
oslInit(0);

//Initialization of the graphics mode
oslInitGfx(OSL_PF_8888, 1);

//Text
oslInitConsole();


//loads our images into memory
pic0 = oslLoadImageFile("pic0.pn g", OSL_IN_RAM, OSL_PF_5551);
tar[0] = oslLoadImageFile("tar.png ", OSL_IN_RAM, OSL_PF_5551);
tar[1] = oslLoadImageFile("tar1.pn g ", OSL_IN_RAM, OSL_PF_5551);
tar[2] = oslLoadImageFile("tar2.pn g ", OSL_IN_RAM, OSL_PF_5551);
tar[3] = oslLoadImageFile("tar3.pn g ", OSL_IN_RAM, OSL_PF_5551);



//main while loop
while (!osl_quit)
{

//Clear the screen
oslCls();


//To be able to draw on the screen
oslStartDrawing();


//initiate the PSP's buttons
oslReadKeys();

//draw on the screen
oslDrawImage(pic0);
oslDrawImage(tar[i]);



if(osl_keys->held.left){
i = 0;
}
if(osl_keys->held.right){
i = 1;
}
if(osl_keys->held.up){

i = 2;
}
if(osl_keys->held.down){
i = 3;
}





//Ends drawing mode
oslEndDrawing();

//Synchronizes the screen
oslSyncFrame();
}

//Terminate the program
oslEndGfx();
oslQuit();
return 0;
}
kronicali is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 10:31 AM   #8

Developer
 
slicer4ever's Avatar
 
Join Date: Jul 2005
Location: everywhere
Posts: 3,357
Trader Feedback: 0
Default

Quote:
Originally Posted by yaustar View Post
Code:
OSL_IMAGE **Images = new OSL_IMAGE[4];
Why dynamically allocate memory?
Code:
OSL_IMAGE *Images[4];
that is true, i've just become too used to using dynamic memory now i guess


anyways @kronicali, your not giving the psp any heap memory, underneath PSP_MAIN_THREAD_ATTR place:

PSP_HEAP_SIZE_KB(-1024);

that should solve your problem, i'll look over your code a little bit more and edit if i see anything else wrong with it that might cause a crash
__________________
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
slicer4ever is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 12:30 PM   #9

 
Join Date: Feb 2009
Posts: 69
Trader Feedback: 0
Default

Quote:
anyways @kronicali, your not giving the psp any heap memory, underneath PSP_MAIN_THREAD_ATTR place:

PSP_HEAP_SIZE_KB(-1024);

that should solve your problem, i'll look over your code a little bit more and edit if i see anything else wrong with it that might cause a crash
still no luck..i think its when m trying to draw the
Quote:
imageoslDrawImage(tar[i]);
when i remove it the program loads...and no crash..when replaced it crashes....this is the only thing holding from completing my 1st ever brew..lol
kronicali is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 01:10 PM   #10

Developer
 
slicer4ever's Avatar
 
Join Date: Jul 2005
Location: everywhere
Posts: 3,357
Trader Feedback: 0
Default

k, well it's working for me, here's my main.c:

Code:
//OSlib header file
#include <oslib/oslib.h>

//Necessary to create eboot
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
//my toolchain isn't fully updated so i have to use 20480, since you should have a fully updated toolchain using -1024 should be fine.
PSP_HEAP_SIZE_KB(20480);

//declaration of the pointers of our images
OSL_IMAGE *pic0, *tar[4];


int i=2;
int main(int argc, char **argv){
     //Initialization of the Oslib library
     oslInit(0);

     //Initialization of the graphics mode
     oslInitGfx(OSL_PF_8888, 1);

     //Text
     oslInitConsole();


     //loads our images into memory
     pic0 = oslLoadImageFile("pic0.png", OSL_IN_RAM, OSL_PF_5551);
     tar[0] = oslLoadImageFile("tar.png", OSL_IN_RAM, OSL_PF_5551);
     tar[1] = oslLoadImageFile("tar1.png", OSL_IN_RAM, OSL_PF_5551);
     tar[2] = oslLoadImageFile("tar2.png", OSL_IN_RAM, OSL_PF_5551);
     tar[3] = oslLoadImageFile("tar3.png", OSL_IN_RAM, OSL_PF_5551);



     //main while loop
     while (!osl_quit){
          //Clear the screen
          oslCls();

          //To be able to draw on the screen
          oslStartDrawing();

          //initiate the PSP's buttons
          oslReadKeys();

          //draw on the screen
          oslDrawImage(pic0);
          oslDrawImage(tar[i]);

          if(osl_keys->held.left){
               i = 0;
          }
          if(osl_keys->held.right){
               i = 1;
          }
          if(osl_keys->held.up){
               i = 2;
          }
          if(osl_keys->held.down){
               i = 3;
          }
          
          //Ends drawing mode
          oslEndDrawing();
          
          //Synchronizes the screen
          oslSyncFrame();
     }
     
     //Terminate the program
     oslEndGfx();
     oslQuit();
     return 0;
}
__________________
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
slicer4ever is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 01:24 PM   #11

 
Join Date: Feb 2009
Posts: 69
Trader Feedback: 0
Default

all am getting is a black screen...even with your code
kronicali is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 01:30 PM   #12

Developer
 
slicer4ever's Avatar
 
Join Date: Jul 2005
Location: everywhere
Posts: 3,357
Trader Feedback: 0
Default

i did get 1 crash before i posted because an image didn't load in properly because i forgot to change a name in the filepath so try this quickly:
Code:
//OSlib header file
#include <oslib/oslib.h>

//Necessary to create eboot
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
//my toolchain isn't fully updated so i have to use 20480, since you should have a fully updated toolchain using -1024 should be fine.
PSP_HEAP_SIZE_KB(20480);

//declaration of the pointers of our images
OSL_IMAGE *pic0, *tar[4];


int i=2;
int main(int argc, char **argv){
     //Initialization of the Oslib library
     oslInit(0);

     //Initialization of the graphics mode
     oslInitGfx(OSL_PF_8888, 1);

     //Text
     oslInitConsole();


     //loads our images into memory
     pic0 = oslLoadImageFile("pic0.png", OSL_IN_RAM, OSL_PF_5551);
     if(pic0==NULL) oslFatalError("pic0 didn't load in");
     tar[0] = oslLoadImageFile("tar.png", OSL_IN_RAM, OSL_PF_5551);
     if(tar[0]==NULL) oslFatalError("pic0 didn't load in");
     tar[1] = oslLoadImageFile("tar1.png", OSL_IN_RAM, OSL_PF_5551);
     if(tar[1]==NULL) oslFatalError("pic0 didn't load in");
     tar[2] = oslLoadImageFile("tar2.png", OSL_IN_RAM, OSL_PF_5551);
     if(tar[2]==NULL) oslFatalError("pic0 didn't load in");
     tar[3] = oslLoadImageFile("tar3.png", OSL_IN_RAM, OSL_PF_5551);
     if(tar[3]==NULL) oslFatalError("pic0 didn't load in");



     //main while loop
     while (!osl_quit){
          //Clear the screen
          oslCls();

          //To be able to draw on the screen
          oslStartDrawing();

          //initiate the PSP's buttons
          oslReadKeys();

          //draw on the screen
          oslDrawImage(pic0);
          oslDrawImage(tar[i]);

          if(osl_keys->held.left){
               i = 0;
          }
          if(osl_keys->held.right){
               i = 1;
          }
          if(osl_keys->held.up){
               i = 2;
          }
          if(osl_keys->held.down){
               i = 3;
          }
          
          //Ends drawing mode
          oslEndDrawing();
          
          //Synchronizes the screen
          oslSyncFrame();
     }
     
     //Terminate the program
     oslEndGfx();
     oslQuit();
     return 0;
}
i won't be back for 5-6 hours gatta go to work, so can't respond till then
__________________
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
slicer4ever is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 01:34 PM   #13

 
Join Date: Feb 2009
Posts: 69
Trader Feedback: 0
Default

Gontry now.
ok kool np..thanks for your help dude.later
-=Double Post Merge =-
lol..how noobish of me...haha thanks so me much i feel like a fool..i forgot to rename my Tar.png files in the folder


::krp did a double post

Last edited by kronicali; 02-02-2009 at 01:50 PM.. Reason: Automerged Doublepost
kronicali is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 02:27 PM   #14

&amp;amp;lt;font color=black&amp;amp;gt;Develo per
 
SuperBatXS's Avatar
 
Join Date: May 2006
Location: Behind you.
Posts: 1,813
Trader Feedback: 0
Default

Pretty inefficient way of checking whether the images loaded. I remember Yaustar showed me a better way. Besides, use the oslib built in function for checking whether the image loaded.
__________________
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195

"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
SuperBatXS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 07:44 PM   #15

Developer
 
slicer4ever's Avatar
 
Join Date: Jul 2005
Location: everywhere
Posts: 3,357
Trader Feedback: 0
Default

SuperBat, quickly written up, but i wouldn't say that's an inefficent way to check(simple checking for null isn't that hard, however i do understand how you mean for a large number of images such checks can become numerous, however i personally wouldn't do it this way, but i figured images not loading correctly was the problem=-)

Quote:
Originally Posted by kronicali View Post
Gontry now.
ok kool np..thanks for your help dude.later
-=Double Post Merge =-
lol..how noobish of me...haha thanks so me much i feel like a fool..i forgot to rename my Tar.png files in the folder


::krp did a double post
glad i managed to help you fix your problem before i left=-), i just realized the output from the fatal error's were all the same, but from the sounds of it you figured it out=-)
__________________
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
slicer4ever is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 09:07 PM   #16

 
Join Date: Feb 2009
Posts: 69
Trader Feedback: 0
Default

lol yeah i figured that out i do that soetimes when am to lazy to retype...one more thing i have and animation system not the best but it works gud for my programming lvl..anyway i.

#define RIGHT 0

///then have my animation code

then i set tar_position=RIGHT;

but when the game loads i see the whole sprite sheet...then i starts animating..i thought setting the position would take care of it that problem?
kronicali is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-02-2009, 09:30 PM   #17

Developer
 
slicer4ever's Avatar
 
Join Date: Jul 2005
Location: everywhere
Posts: 3,357
Trader Feedback: 0
Default

it's hard to say without seeing how ur actually handling the animation
__________________
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
slicer4ever is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-03-2009, 08:36 AM   #18

 
Join Date: Feb 2009
Posts: 69
Trader Feedback: 0
Default

ok i will upload the code later when i get home frm school..
-=Double Post Merge =-
Quote:
//OSlib header file
#include <oslib/oslib.h>

//Necessary to create eboot
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THRE AD_ATTR_USER | THREAD_ATTR_VFPU);
//my toolchain isn't fully updated so i have to use 20480, since you should have a fully updated toolchain using -1024 should be fine.
PSP_HEAP_SIZE_KB(20480);

//variables
#define RIGHT 0
#define DOWN 50


//declaration of the pointers of our images
OSL_IMAGE *pic0, *tar[4];

int tar_march;
int tar_position;
int time=0;
int i=2;

void tarAnimate()
{ time++;
if(time>12.6){

//Moves the sprite in the row that it is in
tar_march++;

//Moves the sprite constantly with no static position
oslSetImageTileSize(tar[i],(tar_march * 50),tar_position,50,50);

//resets the sprite movement in that row
if (tar_march == 6 && tar_position==RIGHT) {tar_march = 0; tar_position=DOWN;}
if (tar_march == 6 && tar_position==DOWN) {tar_march = 0; tar_position=RIGHT;}

time=0;
}

}

int main(int argc, char **argv){
//Initialization of the Oslib library
oslInit(0);

//Initialization of the graphics mode
oslInitGfx(OSL_PF_8888, 1);

//Text
oslInitConsole();


//loads our images into memory
pic0 = oslLoadImageFile("pic0.pn g", OSL_IN_RAM, OSL_PF_5551);
if(pic0==NULL) oslFatalError("pic0 didn't load in");
tar[0] = oslLoadImageFile("tar.png ", OSL_IN_RAM, OSL_PF_5551);
if(tar[0]==NULL) oslFatalError("pic0 didn't load in");
tar[1] = oslLoadImageFile("tar1.pn g", OSL_IN_RAM, OSL_PF_5551);
if(tar[1]==NULL) oslFatalError("pic0 didn't load in");
tar[2] = oslLoadImageFile("tar2.pn g", OSL_IN_RAM, OSL_PF_5551);
if(tar[2]==NULL) oslFatalError("pic0 didn't load in");
tar[3] = oslLoadImageFile("tar3.pn g", OSL_IN_RAM, OSL_PF_5551);
if(tar[3]==NULL) oslFatalError("pic0 didn't load in");


tar_position=RIGHT;

//main while loop
while (!osl_quit){
//Clear the screen
oslCls();

//To be able to draw on the screen
oslStartDrawing();

//initiate the PSP's buttons
oslReadKeys();

//draw on the screen
oslDrawImage(pic0);
oslDrawImage(tar[i]);
//call animation for tar
tarAnimate();


if(osl_keys->held.left){
i = 0;
}
if(osl_keys->held.right){
i = 1;
}
if(osl_keys->held.up){
i = 2;
}
if(osl_keys->held.down){
i = 3;
}

//Ends drawing mode
oslEndDrawing();

//Synchronizes the screen
oslSyncFrame();
}

//Terminate the program
oslEndGfx();
oslQuit();
return 0;
}
here it is

Last edited by kronicali; 02-03-2009 at 07:13 PM.. Reason: Automerged Doublepost
kronicali is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
quickly

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 05:58 AM.



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