C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Zitat von yaustar Calling functions with infinite loops inside other infinite loops in functions is an EXTREMELY bad idea. You ...
-
08-13-2008, 05:59 AM #8881QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- dfgd
- Beiträge
- 66
- Points
- 4.008
- Level
- 40
- Downloads
- 0
- Uploads
- 0
-
08-13-2008, 06:38 AM #8882QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Technically, I should have used enums instead of #defines, but that is easy enough to change.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
08-13-2008, 10:12 PM #8883Developer

- Registriert seit
- Aug 2007
- Beiträge
- 74
- Points
- 3.206
- Level
- 35
- Downloads
- 0
- Uploads
- 0
You still need to add enum in your variable declartions:
Otherwise:Code:enum state { MAIN_MENU, MAIN_GAME }; int main() { enum state currentState = MAIN_MENU; return 0; }
For state machines, enum's are most definitely preferred.Code:typedef enum _state { MAIN_MENU, MAIN_GAME, } state; int main() { state currentState1 = MAIN_MENU; // or if you prefer to make it more explicit // so people know it's an enumerated type // like what you do with typedef'd structs // struct _mystruct var instead of mystruct var // to make it unambiguous enum _state currentState2 = MAIN_MENU; return 0; }PSP PRX LibDoc's Lives On!
http://silverspring.lan.st/
My new home:
http://my.malloc.us/silverspring/
-
08-14-2008, 04:12 AM #8884QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I'm still learning C++, and I was wondering what is the best lib to use for 2D graphics???
-
08-14-2008, 04:42 AM #8885QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
There is no "best" in programming. It always just depends on what you need exactly.
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
08-14-2008, 05:35 AM #8886QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
ok sorry. thanks for the info.
-
08-14-2008, 08:33 AM #8887QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- dfgd
- Beiträge
- 66
- Points
- 4.008
- Level
- 40
- Downloads
- 0
- Uploads
- 0
-
08-14-2008, 08:44 AM #8888OMFG

- Registriert seit
- Jul 2005
- Ort
- Toronto
- Beiträge
- 2.814
- Points
- 19.453
- Level
- 88
- Downloads
- 0
- Uploads
- 0
oslib
-
08-14-2008, 05:12 PM #8889QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
wat slasher said
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
08-14-2008, 05:55 PM #8890
I need a simplest example of how to blit an image using oslib. Any help?
-
08-14-2008, 06:45 PM #8891lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
That should work, its not tested.Code:int main() { oslInit(0); oslInitGfx(OSL_PF_8888,1); OSL_IMAGE * background = oslLoadImageFile("Background.png",OSL_IN_RAM,OSL_PF_8888); while (!osl_quit){ oslStartDrawing(); background->x = 0; background->y = 0; oslDrawImage(background); oslEndDrawing(); oslSyncFrame(); } oslEndGfx(); oslWaitVSync(); oslQuit(); return 0; }
You might want to look into the samples and see how they put images on screen.
-
08-15-2008, 12:50 AM #8892words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Removed unneeded things, made it compilable, swizzle it for speed, unload resources for good practice and typically background images don't have an alpha channel so I changed the pixel format:
Code:#include <oslib/oslib.h> PSP_MODULE_INFO("oslib", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); int main() { oslInit(0); oslInitGfx(OSL_PF_8888,1); OSL_IMAGE *background = oslLoadImageFilePNG("Background.png", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_5650); while (!osl_quit){ oslStartDrawing(); oslDrawImage(background); oslEndDrawing(); oslSyncFrame(); } if (background != NULL) oslDeleteImage(background); oslEndGfx(); oslQuit(); return 0; }
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
08-15-2008, 12:53 AM #8893QJ Gamer Green
- Registriert seit
- Aug 2008
- Ort
- Cyprus
- Beiträge
- 48
- Points
- 5.495
- Level
- 47
- Downloads
- 0
- Uploads
- 0
Single action on button press
Hi, I recently started C programming, and I have a question. What code should I use to make the psp execute code only once when I press a button?
-
08-15-2008, 01:16 AM #8894QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
ok, really great place that helped me learn. psp-programming.com
@SG57 - where are you telling the image the x and y of the screen that you are puting the image on???? or is that not included on this code cause it's a background?? if so then how would you define the x and y for a non-background image?? thanx.
-
08-15-2008, 02:33 AM #8895words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
PSProgrammer - the OSL_IMAGE structure contains everything about the image (x, y, scale, rotation angle, offsets, image data, etc.). By default, when loading an image it's x and y values are initialized to 0. You could also use a different function that takes your own x and y values as arguments ignoring it's own members.

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
08-15-2008, 02:56 AM #8896QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I'm really unfamiliar with oslib, and I'm still learning C++, but what would I need to put in the function to give me my own x and y variables???
-
08-15-2008, 03:02 AM #8897QJ Gamer Green
- Registriert seit
- May 2007
- Beiträge
- 70
- Points
- 3.522
- Level
- 37
- Downloads
- 0
- Uploads
- 0
PSPProgramer, as SG57 said for example:
myImage now has x and y variables, along with the other variables mentioned by SG57. To use them you'd say for example:Code:OSL_IMAGE *myImage;
which would set the image's x to 20 and y to 50. Hope that made sense.Code:myImage->x = 20; myImage->y = 50;
[url="http://www.safarial.homebrewheaven.net"]Blog[/url]
-
08-15-2008, 03:03 AM #8898QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Do you know how to write a function that takes two parameters?
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
08-15-2008, 03:34 AM #8899words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Totally off topic post (since it's a learning experience for PSProgrammer so I won't post anything) but hey there yaustar :) I haven't talked directly to you in forever

Think i can still occasionally PM you some C++ questions? I'd really like that
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
08-15-2008, 05:01 AM #8900QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
08-15-2008, 05:14 AM #8901
-
08-15-2008, 05:59 AM #8902words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Yes, there are two methods actually. The file type doesn't matter but in this case i'll use PNG
One uses temporary file data:
and the other a virtual file system:Code://Binary data representing a PNG file const int test_data[] = {...}; //The size of the above array data const int test_data_size = ???; //Set data for the temporary file oslSetTempFileData(test_data, test_data_size, &VF_MEMORY); //Load a PNG file using the temporary file (oslGetTempFileName to get its name) OSL_IMAGE* image = oslLoadImageFilePNG(oslGetTempFileName(), OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_5650);
Code://Binary data representing a PNG file const int test_png[] = {...}; //Each entry consists of a name, a pointer to the data, the size of the data, and a file type. OSL_VIRTUALFILENAME ram_files[1] = { {"ram:/test.png", (void*)test_png, sizeof(test_png), &VF_MEMORY} }; //Add these files to the list oslAddVirtualFileList(ram_files, oslNumberof(ram_files)); //We can now open them as if they were real files... OSL_IMAGE *img = oslLoadImageFilePNG("ram:/test.png", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_5650);
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
08-15-2008, 06:16 AM #8903
-
08-15-2008, 08:01 AM #8904QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
yeah thank you for the help.
-
08-15-2008, 07:29 PM #8905
- Registriert seit
- Apr 2008
- Beiträge
- 47
- Points
- 2.658
- Level
- 31
- Downloads
- 0
- Uploads
- 0
PSProgrammer - What you have there is a pointer to a struct. If you look up 'struct' on google you can find thousands of tutorials explaining their declaration and use. When you have just a 'normal' struct you can refer to its members by 'name_of_struct.name_of_m ember' whereas if you have a pointer to a struct, as is the case here then you can use 'name_of_struct->name_of_member' rather than '(*name_of_struct).name_o f_member'. Looks much nicer.
Structs are an invaluable asset in C/C++ programming. Good luck, mate. :)
-
08-15-2008, 09:36 PM #8906
(how I do it is)You would grab a variable, and have it when no buttons are pressed set to 0. Then, under your code to exec...ahh..screw it...here's a sample:
That should work, just make sure to declare it. There are probably simpler methods, but, this isn't one of them.Code:if(pad.Buttons & PSP_CTRL_CROSS) { if(!buttonBool0) { //CODE RIGHT IN HERE } buttonBool0=1; } else buttonBool0=0;
-
08-15-2008, 11:33 PM #8907QJ Gamer Green
- Registriert seit
- Aug 2008
- Ort
- Cyprus
- Beiträge
- 48
- Points
- 5.495
- Level
- 47
- Downloads
- 0
- Uploads
- 0
Thanks, I will test it after my virtualbox problem is solved. It's been three days I cannot access my source code from it and compile it :Argh:
-
08-16-2008, 04:14 AM #8908QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Or alternatively, in case you have a lot of different button presses you want to handle and not have a variable for each button:
Code:int lastButtons = 0; while(isrunning) { sceCtrlReadData(&pad); int pressed = ~lastButtons & pad.Buttons; // only buttons that have been pressed down this frame int released = lastButtons & ~pad.Buttons; // in case you want to react on the buttons being released rather than pushed if(pressed & PSP_CTRL_CROSS) { ... code that will only be executed the instant the button gets pushed down } lastButtons = pad.Buttons; }Geändert von Raphael (08-16-2008 um 04:28 AM Uhr)
Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
08-16-2008, 10:58 AM #8909QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Hey thanks for al the help Khatharr and SG57, I got alot more done. Also I find now that I quite like OSLib
-
08-17-2008, 05:13 AM #8910
Donot we need to do oslSwapBuffer after enddrawing syncframe like flipscreen()?


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum