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; if i want to load two images, do i have to do this: ? Code: char buffer1[200]; Image* ourImage; sprintf(buffer, ...
-
07-10-2007, 08:44 AM #5431QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
if i want to load two images, do i have to do this: ?
or is there a better way?Code:char buffer1[200]; Image* ourImage; sprintf(buffer, "ourImage.png"); ourImage = loadImage(buffer); char buffer2[200]; Image* ourImage2; sprintf(buffer2, "ourImage2.png"); ourImage2 = loadImage(buffer2);
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
07-10-2007, 08:46 AM #5432QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
That buffer is pointless.
Code:Image* ourImage1 = loadImage("Image1.png"); Image* ourImage2 = loadImage("Image2.png");
-
07-10-2007, 09:08 AM #5433QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
thx this is shorter :)
-= Double Post =-
ok new one
how do you print variable with printTextScreen ?
i tried %d - doesnt work
i tried printing variable name - doesnt workGeändert von myschoo (07-10-2007 um 01:40 PM Uhr) Grund: Automerged Doublepost
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
07-10-2007, 05:26 PM #5434QJ Gamer Blue
- Registriert seit
- Feb 2007
- Ort
- Florida
- Beiträge
- 214
- Points
- 4.031
- Level
- 40
- Downloads
- 0
- Uploads
- 0
I started looking at LTE 2.2. Any tutorals out there?
-
07-10-2007, 07:36 PM #5435QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Nevermind I got it.
Geändert von Beat_Bob (07-10-2007 um 11:30 PM Uhr)
-
07-10-2007, 10:52 PM #5436QJ Gamer Green
- Registriert seit
- Sep 2006
- Ort
- Cape Town, South Africa
- Beiträge
- 714
- Points
- 5.795
- Level
- 49
- Downloads
- 0
- Uploads
- 0
@Beat_Bob: Put a semicolon after the struct definition to get it to compile. Although that code won't work because it'll just get stuck at the while(1) loop.
@myschoo: sprintf the variable into a different buffer and printTextScreen that buffer (unless there's an easier way).
-
07-11-2007, 01:04 AM #5437QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Any decent SDK should have some samples included.
Zitat von MrChaos
[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]
-
07-11-2007, 03:49 AM #5438
Hi
Can someone tell me how i can get the ".png" out of "image.png" ?
In lua it would be this:
Thanks in advanceCode:if string.sub("image.png", -4) == ".png" then fimage = Image.load("image.png") end
-
07-11-2007, 03:54 AM #5439It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
strrchr("image.png",'.')
Will give you the a char* starting from last instance of a period in a character string. The strings are linked, that is, so if you free "image.png" (assuming you're doing it allocated from the stack), it'll free the ".png", and if you modify the ".png", it'll modify the "image.png". Also, you can't directly free the ".png".pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-11-2007, 04:04 AM #5440
Thanks, i will try this
But are you sure that there is no code in C for string.sub() in LUA?
-
07-11-2007, 04:12 AM #5441It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
strncpy(to, from + strlen(from) - 5, 4);
Geändert von Archaemic (07-11-2007 um 04:13 AM Uhr) Grund: rm stray spacing
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-11-2007, 03:51 PM #5442QJ Gamer Green

- Registriert seit
- Oct 2006
- Ort
- Cd. Juarez Mexico -
- Beiträge
- 341
- Points
- 8.244
- Level
- 61
- Downloads
- 0
- Uploads
- 0
-
07-11-2007, 04:47 PM #5443It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Umm, there is no string.h. If it's C++, it's just string.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-11-2007, 05:26 PM #5444QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
There IS a string.h. You use it for strcmp, strcpy, etc...
The header he needs it stdlib.h.
-
07-11-2007, 05:32 PM #5445It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Ah, oh, you're right. I was in a C++ mindset after that topic about C++ strings.
Anyway, you don't want atoi anyway. That converts C strings to integers, not the other way around.pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-11-2007, 07:41 PM #5446words 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
Archaemic = He said itoa (Integer TO Ascii), not atoi (Ascii TO Integer)

...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
-
07-12-2007, 04:01 AM #5447It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Last time I checked, there is no itoa.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-12-2007, 04:39 AM #5448QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
http://www.cplusplus.com/reference/c...dlib/itoa.html
Zitat von Archaemic
It isn't standard though across all compilers.[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]
-
07-12-2007, 05:46 AM #5449QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Right then, i have no idea why i'm getting this error, but it's giving it me anyways.
I Get the following errors on compile:
Here are my includes:Code:main.o: In function `main': main.cpp:(.text+0xdc): undefined reference to `initGraphics()' main.cpp:(.text+0x12c): undefined reference to `flipScreen()'
And my Makefile:Code:#include <malloc.h> #include <pspkernel.h> #include <pspdisplay.h> #include <pspdebug.h> #include <stdio.h> #include <pspcallbacks.h> #include <pspgu.h> #include <pspgum.h> #include <psprtc.h> #include "Files/graphics.h"
Any ideas ?Code:#------------------- Makefile for 'Breakout' -------------------# TARGET = Breakout OBJS = main.o Files/font.o Files/graphics.o Files/framebuffer.o INCDIR = LIBDIR = LDFLAGS = LIBS = -lpspgum -lpspgu -lpsprtc -lm -lpng -lz -lm CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = Breakout PSPSDK = $(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
-
07-12-2007, 07:06 AM #5450QJ Gamer Green
- Registriert seit
- Feb 2006
- Ort
- www.ultimatetalkforums.com Games, RPG, quickchat and more!
- Beiträge
- 532
- Points
- 8.746
- Level
- 62
- Downloads
- 0
- Uploads
- 0
whats the easiest way to make a sidescroller with text liike
V
.
.
.
.
A[CENTER][COLOR=black][COLOR=black][URL="http://forums.qj.net/f-psp-firmware-discussion-253/t-psp-firmware-30-get-it-58053.html"][COLOR=cyan]would you upgrade?[/COLOR][/URL] [/COLOR][FONT=Times New Roman][COLOR=navy][URL="http://www.mindistortion.net/iwantyoursoul/?i_am=altunozara"]OMG ITS REAL![/URL][/COLOR][/FONT][COLOR=black] [URL="http://forums.qj.net/showthread.php?t=61756&page=1&pp=10"][COLOR=lime]Sony vs Nintendo[/COLOR][/URL][/COLOR][/COLOR][/CENTER]
[CENTER] [/CENTER]
[CENTER][URL="http://www.ultimatetalkforums.com"][IMG]http://i94.photobucket.com/albums/l82/Altunozara/userbar2.jpg[/IMG][/URL][/CENTER]
[CENTER][SIZE=3]i [/SIZE][URL="http://forums.qj.net/www.gamingwell.com"][SIZE=3]wonder what could be under this hyperlink..hmm[/SIZE][/URL][/CENTER]
[CENTER][SIZE=3][COLOR=green][B][I]Maniakc is awsome!!![/I][/B][/COLOR][/SIZE][/CENTER]
[CENTER][FONT=Arial Black][SIZE=3][COLOR=#660099][I][U][URL="http://forums.qj.net/member.php?u=58299"]The Brain Pwns!!![/URL][/U][/I][/COLOR][/SIZE][/FONT][/CENTER]
[COLOR=sienna]Creator of:[/COLOR][URL="http://forums.qj.net/f-psp-development-forum-11/t-release-go-go-go-beta-66652.html"][COLOR=sienna]GO GO GO![/COLOR][/URL]
-
07-12-2007, 08:44 AM #5451QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Shouldn't it be:Code:OBJS = main.o Files/font.o Files/graphics.o Files/framebuffer.o
IIRC, the .o files are created in the same directory as the Makefile regardless of where the source file is.Code:OBJS = main.o font.o graphics.o framebuffer.o
[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]
-
07-12-2007, 08:51 AM #5452It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
The objs line from PSPComic is such:
It works just fine, even though it compiles objects from subdirectories (and the o files do go in the zip folder after they're compiled).Code:OBJS = zip/ioapi.o zip/unzip.o pspcomic.o xmlfuncs.o rar.o
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-12-2007, 09:29 AM #5453Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
Archaemic is correct.
MiG: Wrap your #include of graphics.h in an extern C statement.
Code:extern "C" { #include "Files/graphics.h" }
Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
07-12-2007, 05:37 PM #5454QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Anyone know why this isnt working?
No errors or anything, its just that when I try to jump (when I press X) he doesnt do anything. I want him to go in the air and have gravity come down on him (when jumpspeed=5) thats when I want him to start coming down.Code:while(1) { sceCtrlPeekBufferPositive(&pad, 1); // Find out what the state of the control pad is // Change the position of the box if(pad.Buttons & PSP_CTRL_LEFT) { if(box.x>0) {box.x=box.x-3;} } else if(pad.Buttons & PSP_CTRL_RIGHT) { if(box.x<480-32) {box.x=box.x+3;} } if((pad.Buttons & PSP_CTRL_CROSS) && (box.state==0)) {box.state=1; box.jumpspeed=0;} if(box.state==1 && box.jumpspeed==0) { box.y=box.y-0.8; box.jumpspeed+=0.3;} if (box.state==1 && box.jumpspeed>3.5) {box.y=box.y-0.3;} if (box.state==1 && box.jumpspeed>=5); { box.state=2; } if (box.state==2) { box.jumpspeed=5; box.y+=0.8;} if (box.state==2 & box.y==230) {box.y=230; box.state=0; box.jumpspeed=0;}
Then when hes back on the ground (when hes at y: 230) it resets.
box.state (0 = ground, 1 = jumping, 2 = falling) just so you know.
Anyone?
-
07-12-2007, 06:27 PM #5455words 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
If you told us what graphics library your using, itd be much easier to make a specific example for it (graphics lib, oslib, sdl, gu, pspgl, lte, etc.)
Zitat von altunozara

...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
-
07-12-2007, 07:34 PM #5456QJ Gamer Platinum
- Registriert seit
- Dec 2005
- Ort
- h0000000rj
- Beiträge
- 12.867
- Points
- 57.528
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Indeed I do.
Zitat von Beat_Bob
Notice the part I bolded.Code:if((pad.Buttons & PSP_CTRL_CROSS) && (box.state==0)) {box.state=1; box.jumpspeed=0;} if(box.state==1 && box.jumpspeed==0) { box.y=box.y-0.8; box.jumpspeed+=0.3;}
In your code, if the box isn't moving and you press Cross, you set box.state to 1 and box.jumpspeed to 0. Then, immediately after, if box.state is 1 (it is) and box.jumpspeed is 0 (it is), you change box.jumpspeed to 0.3 . And, since none of your if statements catch anything but *exact* numbers, and more explicitly, since none of them handle the case where box.jumpspeed is 0.3, once you hit this point, your box state and box speed aren't going to change any more.
Instead of
tryCode:if(box.state==1 && box.jumpspeed==0)
and instead ofCode:if(box.state==1 && box.jumpspeed<3.5)
tryCode:if (box.state==1 && box.jumpspeed>3.5)
Gotta be sure that every possible code route is covered, so don't just check for explicit numbers for the box speed. Check for ranges instead, so that all possible box speeds will fall into one of your if statements.Code:if (box.state==1 && box.jumpspeed>=3.5 && box.jumpspeed < 5)
[I fail @ life]
-
07-12-2007, 08:02 PM #5457QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Didnt work. But I tried another way by converting a lua tutorial (just jumping, same method)
to this way:
Spoiler for while(1) loop:
Its weird. When I press X he jumps (incredibly fast....) and hes just stuck in the air then.
He wont fall back down. Why not? Ive made it so I can move left and right, and when im stuck in the air im able to move
left and right by the way, just so you know.Geändert von Beat_Bob (07-12-2007 um 08:38 PM Uhr)
-
07-12-2007, 08:42 PM #5458QJ Gamer Green

- Registriert seit
- Oct 2006
- Ort
- Cd. Juarez Mexico -
- Beiträge
- 341
- Points
- 8.244
- Level
- 61
- Downloads
- 0
- Uploads
- 0
-
07-13-2007, 12:15 AM #5459words 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
Nope.
But if you don't feel like using a non-standard function for some reason, you could always make your own or use a pre-existing example (look at the external links)
altunozara - The basic concept for vertical scrolling sentences, regardless of graphics library, is
You could easily make a structure for each character, to change each specific characters color, rotation, size, etc. on the fly for a neat effect.Code:const int SCR_HEIGHT = 272; // avoid magic numbers (yaustar's teachings through me i know... :-\) const int SCR_WIDTH = 480; const int CHAR_HEIGHT = 10; // in pixels const int CHAR_WIDTH = 8; int main() { int mainy = SCR_HEIGHT; // starting point char string[/* im too lazy to count the number of chars in the string */] = "SG57 was here..."; // string to scroll for(;;) { for(int i = 0; i < strlen(string); i++) screen_print(SCR_WIDTH/2-CHAR_WIDTH/2, mainy+i*CHAR_HEIGHT, string, #FFFFFF) mainy--; if(mainy < -(strlen(string)*CHAR_HEIGHT)) mainy = SCR_HEIGHT; // reset text to bottom of screen and continue scrolling, this could easily be a call to go back to main menu should you be making a credits screen or something vertical_sync(); flip_buffer(); } return 0; }
The above snippet needs optimization, but its a rough example and should push you into the right direction.
...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
-
07-13-2007, 12:18 AM #5460QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
That just broke "graphics.h", came up with all sorts of errors... i'll have a play.. see what's going off :)
Zitat von Insert_Witty_Name
EDIT - Seems like having the files in a seperate directory was causing the errors. :S
But now I have a new set of errors that don't even make sense
Geändert von MiG (07-13-2007 um 12:31 AM Uhr)


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