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; Hi, I'm new to the PSP homebrew programing scene, lucky not to C++ however, and I can't figure out for ...
-
03-28-2006, 06:49 PM #151
- Registriert seit
- Feb 2006
- Ort
- Arkhangelsk, Russia
- Beiträge
- 21
- Points
- 4.193
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Hi, I'm new to the PSP homebrew programing scene, lucky not to C++ however, and I can't figure out for the life of me how to display one picture over the other withough erasing the first picture. If anyone could help it would be greatly appresiated.
Curently I have it set up as such.
As you can see I have it draw one picture and then draw the smaller, however, instead of drawind the second picture over the first, it just erases the first picture instead of drawing over it.Code:char buffer1[200]; char buffer2[200]; Image* bg; Image* set; sprintf(buffer1, "bg.png"); bg = loadImage(buffer1); sprintf(buffer2, "set.png"); set = loadImage(buffer2); sceDisplayWaitVblankStart(); blitAlphaImageToScreen(0 ,0 ,480 ,272 ,bg ,0 ,0 ); flipScreen(); sceDisplayWaitVblankStart(); blitAlphaImageToScreen(0 ,0 ,60 ,34 ,set ,60 ,34 ); flipScreen();
Sorry if this is noobish BTW.
Geändert von F.T.P. (03-28-2006 um 06:52 PM Uhr)
-
03-29-2006, 05:29 AM #152Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
F.T.P.: Try this
but I'm not sure it will work, I just found it.Code:void printTextImage(int x, int y, const char* text, u32 color, Image* image)
-
03-29-2006, 05:35 AM #153
- Registriert seit
- Jan 2006
- Beiträge
- 10
- Points
- 4.279
- Level
- 41
- Downloads
- 0
- Uploads
- 0
F.T.P. you have 2 screen buffers, remove the flipScreen between your blitAlphaImageToScreen, you'll draw on the same screen buffer.
-
03-29-2006, 05:37 AM #154Mushroom Man
- Registriert seit
- Sep 2005
- Ort
- UK
- Beiträge
- 318
- Points
- 7.283
- Level
- 56
- Downloads
- 0
- Uploads
- 0
The graphics.c package uses double buffering, so when you flip the buffers(between displayed and hidden) the buffer that you were editing is now being displayed, and the buffer that was being displayed is now being edited. Writing to the first buffer will not write over to the second, so in essence you must re-draw the scene upon every flip.
Zitat von F.T.P.
Code:sceDisplayWaitVblankStart(); blitAlphaImageToScreen(0 ,0 ,480 ,272 ,bg ,0 ,0 ); blitAlphaImageToScreen(0 ,0 ,60 ,34 ,set ,60 ,34 ); flipScreen();
-
03-29-2006, 06:43 AM #155Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Does anyone know the command to activate usb ( I found the example in the sdk but somehow it didnt work form me...). Cause I want to activate it when I press 'X'. If anyone wold give me an example it would be great. Thanks in advance.
Edit: Nevermind I just got it to compile. Too bad that I just lost my USB-cable =SGeändert von SodR (03-29-2006 um 11:58 AM Uhr)
-
03-29-2006, 08:24 PM #156
- Registriert seit
- Feb 2006
- Ort
- Arkhangelsk, Russia
- Beiträge
- 21
- Points
- 4.193
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Damn, that helped alot. Thanks you guys. :)
-
03-30-2006, 12:32 PM #157
Have anyone ever notice that when printing text to the screen whether over a picture or not, if the xcoord is <0 of the screen... nothing is printed at all?
Would someone mind telling me what can be done about this?
I'm currently using: printTextScreen(,,,)Geändert von Devun_06 (03-30-2006 um 12:35 PM Uhr)
-
03-31-2006, 01:40 PM #158
- Registriert seit
- Dec 2005
- Beiträge
- 32
- Points
- 4.439
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Hey, how could I disable 'Home' -button, so nothing would happen if you press it, or how could I get my program to straight exit when pressing 'Home'? I tried one method, and when you press 'Home', that stupid "Do you want to quit program" -popup comes to the screen, but after a second it will get me back to XMB. So how could I disable that "Do you want to quit program" -popup showing up at all?
EDIT: Got it working, no problems anymore :)Geändert von MiiKKiZ (03-31-2006 um 01:48 PM Uhr)
-
03-31-2006, 03:49 PM #159
If you're getting the XMB return system then I guess your running 1.5. I've never tried overriding the original home key feature, but I think this might help.
SceCtrlData Pad;
sceCtrlReadBufferPositive (&Pad,1);
if(Pad.Buttons & PSP_CTRL_HOME){sceKernelE xitGame();}
-
04-01-2006, 09:27 AM #160Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
I have not tested it my self but if you code that nothing will happen when you press home, like this:
SceCtrlData Pad;
sceCtrlReadBufferPositive (&Pad,1);
if(Pad.Buttons & PSP_CTRL_HOME)
I think it will work as it were disabled. At least you can always try.
-
04-02-2006, 08:52 PM #161Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Hi Guys, just a little Q re C syntax.
I have some variables in a buffer that represent ASCII values that I
would like to print to screen as ASCII.
I can print them as decimal values like so:
printf("variable is: %d",data[0]);
So if I have the ASCII character '0' in the buffer, it will print as:
variable is: 48
which is it's decimal value. What do I need to replace the %d with for ASCII?
Cheers, Art.
-
04-02-2006, 08:54 PM #162QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
%c I believe. If I'm right, I read it here: http://irc.essex.ac.uk/www.iota-six....ming_intro.asp
-
04-02-2006, 09:00 PM #163Bush Programmer

- Registriert seit
- Nov 2005
- Beiträge
- 3.658
- Points
- 60.149
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Yep, I Googled it and came back to answer myself

Thanx ;)
-
04-02-2006, 09:01 PM #164QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
No prob. You know You can also do other things, like %02x for showing the value in a 2 character hex form, and %08x for 8 char...
-
04-04-2006, 11:48 PM #165words 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
hmmm....Soccer, thats what you told me for hex, and its true, looked it up and everything... use %02x to only use/get the hex in 2 character/byte form...

...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
-
04-06-2006, 11:17 AM #166QJ Gamer Blue
- Registriert seit
- Apr 2006
- Ort
- Northampton, England
- Beiträge
- 59
- Points
- 4.272
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Hi everyone, i'm trying to make a png photo viewer with music in the background. Can anybody please help.
Any help would be greatly appreciated.Code:#include <pspkernel.h> #include <pspdisplay.h> #include <pspdebug.h> #include <pspgu.h> #include <png.h> #include <pspdisplay.h> #include <pspctrl.h> #include <stdio.h> #include <psppower.h> #include <pspaudio.h> #include <pspaudiolib.h> #include "mp3player.h" #include "graphics.h" PSP_MODULE_INFO("images and music", 0, 1, 1); #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) #define printf pspDebugScreenPrintf /* Exit callbacks */ int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } /* Callback thread */ int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelSleepThreadCB(); return 0; } /* Sets up the callback thread and returns its id */ int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main(void) { SetupCallbacks(); initGraphics(); SceCtrlData pad; int i; int j; int selComponent = 0; int selComponent2 = 0; char buffer[200]; char image[5]; char music[5]; Image* ourImage; pspAudioInit(); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(selComponent == 0) { image == "1.png"; } else if(selComponent == 1) { image == "2.png"; } else if(selComponent == 2) { image == "3.png"; } else if(selComponent == 3) { image == "4.png"; } else if(selComponent == 4) { image == "5.png"; } if(selComponent2 == 0) { music == "1.mp3"; } else if(selComponent2 == 1) { music == "2.mp3"; } else if(selComponent2 == 2) { music == "3.mp3"; } else if(selComponent2 == 3) { music == "4.mp3"; } else if(selComponent2 == 4) { music == "5.mp3"; } if(pad.Buttons & PSP_CTRL_UP) { if(selComponent > 0) { selComponent--; } for(i=0; i<10; i++) { sceDisplayWaitVblankStart(); } } else if(pad.Buttons & PSP_CTRL_DOWN) { if(selComponent < 4) { selComponent++; } for(i=0; i<10; i++) { sceDisplayWaitVblankStart(); } } if(pad.Buttons & PSP_CTRL_LEFT) { if(selComponent2 > 0) { selComponent2--; } for(j=0; j<10; j++) { sceDisplayWaitVblankStart(); } if(pad.Buttons & PSP_CTRL_RIGHT) { if(selComponent2 > 1) { selComponent2++; } for(j=0; j<10; j++) { sceDisplayWaitVblankStart(); } } printf("Image viewer (with added music!)"); sprintf(buffer, image); if (!ourImage) { //Image load failed printf("Image load failed!/n"); } else { int x = 0; int y = 0; sceDisplayWaitVblankStart(); while (x <= 480) { while (y <= 272) { blitAlphaImageToScreen(0, 0, 480, 272, ourImage, x, y); y += 272; } x += 480; y = 0; } MP3_Init(1); MP3_Load(music); MP3_Play(); while(1) { sceCtrlReadBufferPositive(&pad, 1); if(pad.Buttons & PSP_CTRL_CROSS) { break; } else if(pad.Buttons & PSP_CTRL_CIRCLE) { MP3_Pause(); for(i=0; i<10; i++) { sceDisplayWaitVblankStart(); } } MP3_Stop(); MP3_FreeTune(); flipScreen(); for(i=0; i<1; i++) { sceDisplayWaitVblankStart(); } } return 0; }
-
04-07-2006, 08:57 AM #167Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
code-zero: Maybe you should tell us what the problem is instead of yout posting your source. Doesn't it compile? If so what error code? Or at which point does your program crash?? We need more info
-
04-07-2006, 11:29 AM #168words 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
code-zero, there are multiple resons why it might not work... 1 being you initalized the MP3 playing in a loop, along with 2 infinite loops as well lol.. . Why not post your problems complying? Oh and it also looks like you are just copying and pasting from Yeldarbs *tuts*, 'ourImage'? SelComponent? blitting the backround/image with a loop for know reason? (remove the > and < junk, just do blitAlphaImageToScreen(0, 0, 480, 272, ourImage, 0, 0)<- that will blit ourImage to the co-ordinates of 0, 0 and the ourImage's dimensions are 480x272 in this) There are some more problems in theree, but ill let you debug to get used to having too.
Geändert von SG57 (04-07-2006 um 11:32 AM Uhr)

...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
-
04-07-2006, 11:34 AM #169QJ Gamer Blue
- Registriert seit
- Apr 2006
- Ort
- Northampton, England
- Beiträge
- 59
- Points
- 4.272
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I went through yeldarbs tuts, but I used the same variables to try and make it a little easier to understand, and I didn't copy and paste. I printed it off and typed it,
.
-
04-14-2006, 04:05 AM #170Developer

- Registriert seit
- Sep 2005
- Ort
- Sweden
- Beiträge
- 941
- Points
- 10.075
- Level
- 67
- Downloads
- 0
- Uploads
- 0
I'm having problem installing PSPGL on my PC. I downloaded pspgl using svn (svn co svn://svn.ps2dev.org/psp/trunk/pspgl ) and that works just fine. But how am I supposed to install it?? The readme is like a riddle, why cant it just tell me what to do? I tryed to just go into the dir (cd pspgl) and type "make". After that alot of text rolls on the screen and after like a half a minute I get this error:
I have tryed to re-download pspgl a couple of times but I get the same error everytime. Worth to notice is that almost every line of the text that rolls by before the error looks like this:Code:[Alotofdirnameshere]/TEMP/ccimwEpb.s: Assembler messages: [Alotofdirnameshere]/TEMP/ccimwEpb.s: "Error: Illegal operands 'vmidt.q m700' make: *** [glLoadIdentity.o] Error 1
Code:psp-gcc -std=gnu99 -g -Wall -Wmissing-prototypes -Os -G0 -fsingle-precision-constant -I. -I /usr/local/pspdev/psp/include -I /usr/local/pspdev/psp/include funit-at-a-time -MD -MF .deps/[Filename].d -c [Filename].c
-
04-14-2006, 05:33 AM #171Developer

- Registriert seit
- Mar 2006
- Ort
- Isle of Wight
- Beiträge
- 491
- Points
- 12.360
- Level
- 72
- Downloads
- 0
- Uploads
- 0
Meh, I need help with blitting an image to the screen. Code:
It compiles successfully but when I view it on my PSP it does not show. Just a black screen. it doesnt crash by PSP though. I can go back to the eloader.Code:#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 MAX(X, Y) ((X) > (Y) ? (X) : (Y)) #define printf pspDebugScreenPrintf PSP_MODULE_INFO("Button Basher", 0, 1, 1); /* Exit callback */ int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } /* Callback thread */ int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } /* Sets up the callback thread and returns its thread id */ int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main() { char buffer[200]; Image* menubg; pspDebugScreenInit(); SetupCallbacks(); initGraphics(); sprintf(buffer, "menubg.png"); menubg = loadImage(buffer); if (!menubg) { //Image load failed printf("Image load failed! Please email [email protected]!\n"); } else { int x = 0; int y = 0; sceDisplayWaitVblankStart(); while (x < 480) { while (y < 272) { blitAlphaImageToScreen(0, 0, 480, 272, menubg, x, y); x = 0; y = 0; } flipScreen(); } } sceKernelSleepThread(); return 0; }
-
04-15-2006, 06:44 AM #172
- Registriert seit
- Feb 2006
- Beiträge
- 13
- Points
- 4.145
- Level
- 40
- Downloads
- 0
- Uploads
- 0
At first, you dont need this:
while (x < 480) {
while (y < 272) {
blitAlphaImageToScreen(0, 0, 480, 272, menubg, x, y);
x = 0;
y = 0;
}
flipScreen();
}
you just have to write:
blitAlphaImageToScreen(0, 0, 480, 272, menubg, x, y);
flipscreen();
you kopie the code, or?, try to understand why you dont need the 2 while sharpens.
and now to your problem, i think you need a larger buffer, so test it with 20000 or more ;)
-
04-15-2006, 07:08 AM #173Developer

- Registriert seit
- Mar 2006
- Ort
- Isle of Wight
- Beiträge
- 491
- Points
- 12.360
- Level
- 72
- Downloads
- 0
- Uploads
- 0
Nvm I fixed it
I somehow got yeldarbs MSN and he helped me
I just need to find a tut on how to make a menu now
-
04-15-2006, 12:51 PM #174words 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
Since im feeling nice today, i just throguh together a quick Simple Menu Tutorial. I uploaded it as a .txt since PSPU doesnt like C source files
Zitat von kozine

Anyway, i have included one of those copyright Comments at the top, so if you copy and paste, then youd have to include something about it. Instead just read it, get an idea of how it works, and then make your own. Very simple.
P.S. If something is wrong in it, forgive me since i just throguh it together to help some new devlopers out since i too had a hard time with a menu.
your welcome.
...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
-
04-15-2006, 12:52 PM #175Developer

- Registriert seit
- Mar 2006
- Ort
- Isle of Wight
- Beiträge
- 491
- Points
- 12.360
- Level
- 72
- Downloads
- 0
- Uploads
- 0
ty so much
I can carry on now XD
-
04-15-2006, 01:05 PM #176Developer

- Registriert seit
- Mar 2006
- Ort
- Isle of Wight
- Beiträge
- 491
- Points
- 12.360
- Level
- 72
- Downloads
- 0
- Uploads
- 0
Sorry for double post!
Im gettin eally annoyed with this oggplayer LIB. Here is a screenshot of my compiling error:

Code:
I would like it so the sound keeps repeating and never stops.Code:#include <pspdisplay.h> #include <pspctrl.h> #include <pspkernel.h> #include <pspdebug.h> #include <pspgu.h> #include <png.h> #include <stdio.h> #include "graphics.h" #include <stdlib.h> #include <malloc.h> #include <stdio.h> #include <stdarg.h> #include <string.h> #include <limits.h> #include <errno.h> #include <pspaudiolib.h> #include <pspaudio.h> #include <pspdisplay.h> #include <pspctrl.h> #include <pspkernel.h> #include <pspdebug.h> #include <psputils.h> #include <psptypes.h> #include <psppower.h> #include <pspiofilemgr.h> #include <png.h> #include <stdio.h> #include "graphics.h" //Ogg include #include "ogg/ivorbisfile.h" #include "oggplayer.h" #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) #define printf pspDebugScreenPrintf PSP_MODULE_INFO("Button Basher", 0, 1, 1); /* Exit callback */ int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } /* Callback thread */ int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } /* Sets up the callback thread and returns its thread id */ int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main() { char buffer[200]; Image* menubg; pspDebugScreenInit(); SetupCallbacks(); initGraphics(); pspAudioInit(); //Initialize OGG port OGG_Init(1); //Load OGG file OGG_Load("sounds/menu.ogg"); //Play the loaded file OGG_Play(); sprintf(buffer, "menubg.png"); menubg = loadImage(buffer); if (!menubg) { //Image load failed printf("Image load failed! Please email [email protected]!\n"); } else { int x = 0; int y = 0; sceDisplayWaitVblankStart(); blitAlphaImageToScreen(0, 0, 480, 272, menubg, x, y); } flipScreen(); sceKernelSleepThread(); return 0; }
-
04-15-2006, 06:40 PM #177words 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
Its noi doubt you either dont ahve the OGGlib installed/not including then OGGlib/do not have the OGG lib in the makefile. But o have it repeat and never stop, look at the .h file of it and a protoyp will be in there for something similar.

...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
-
04-16-2006, 01:32 PM #178QJ Gamer Green
- Registriert seit
- Jan 2006
- Beiträge
- 4.289
- Points
- 25.223
- Level
- 95
- Downloads
- 0
- Uploads
- 0
SG57, do you know SDL or a good tutorial of one? I'm interested in learning it, for menus mostly.
-
04-17-2006, 10:35 AM #179Mindless Fanboy
- Registriert seit
- Mar 2006
- Beiträge
- 1.907
- Points
- 17.218
- Level
- 83
- Downloads
- 0
- Uploads
- 0
how do i create barriers for a character? such as walls. how would i make a whole image impossible for a character to go inside? like a buildings walls. thank you!
-
04-20-2006, 11:25 AM #180QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
sorry unsure where else to post this but when i'm trying to get c to work i notice it is trying to dl from a website heres the full error
--15:23:54-- ftp://ftp.gnu.org/pub/gnu/binutils/b...-2.16.1.tar.gz
(try: 6) => `binutils-2.16.1.tar.gz'
Connecting to ftp.gnu.org|199.232.41.7| :21... failed: Connection timed out.
Retrying.
anyway around this would be much appreciated=-)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


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