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 SG57 In the end, doesn't this mean I could end up with, say, 40 source files each relatively ...
-
02-15-2010, 01:48 PM #10051QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Yes, is that a problem? (Or you can stack multiple classes in one file if you *really* want to).
I would use a std::map myself which makes it easier to get components from the entity container. There is an issue that you can't have more then one instance of the same component in a map structure but that is easily solvable either by design or a code solution.I would love to see some C++ source code of this pattern, I think I've been following something of the sort all along (as in, couldn't one say using a 3D vector class to handle storing positions/velocities/orientations a composite pattern?)
A PPT of the same pattern: http://www.gdcvault.com/play/1911/Th...t_Architecture
[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]
-
04-03-2010, 11:00 AM #10052QJ Gamer Green
- Registriert seit
- May 2009
- Ort
- In your head.
- Beiträge
- 102
- Points
- 6.371
- Level
- 52
- Downloads
- 0
- Uploads
- 0
Hey guys, I was wondering, how do I underline text using C++? I am also using OSLib, so if their is a way to do it please help me xP
[spoiler=Quotes]
[COLOR="Red"]Before you criticize some one, walk a mile in there shoes, that way your a mile away and you have there shoes![/COLOR]
Friendship is like peeing on yourself: everyone can see it, but only you get the warm feeling that it brings.
[COLOR="Indigo"]The man who smiles when things go wrong has thought of someone to blame it on.[/COLOR][/spoiler]
[color=orange]Im just a dude who wants to figure out this freaking lua thing! LOL[/color]
-
04-05-2010, 07:18 AM #10053QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
Emm, you could simply use the OSlib to draw a line under your text.
-
04-11-2010, 01:16 PM #10054QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Error I got upon compiling:
make: *** No rule to make target `graphics.o', needed by `image.elf'. Stop.
Makefile:
main.c:Code:TARGET = image OBJS = main.o graphics.o framebuffer.o CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) LIBS = -lpspgu -lpng -lz -lm EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = Image PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
Code:#include <pspkernel.h> #include <pspdebug.h> #include <pspcallbacks.h> #include <pspctrl.h> #include "graphics.h" #define drawImage blitAlphaImageToScreen PSP_MODULE_INFO("Name Of Program",0,1,1); int main() { pspDebugScreenInit(); //pspDebugScreenClear(); SetupCallbacks(); initGraphics(); SceCtrlData pad; Image* background = loadImage("back.png"); drawImage(0,0,480,272,background,0,0); flipScreen(); sceKernelSleepThread(); return 0; }
-
04-11-2010, 02:28 PM #10055QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
It means your graphics.c (or .cpp) doesn't exist in the current directory, you should really learn the actual (Linux) C before skipping to the PSP.
-
04-11-2010, 06:43 PM #10056QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Whats the best way to make objects in C?
Like lets say I want to make two objects:
a player and a block
The player has these attributes:
- Can walk
- Jump (gravity)
- collides with blocks
- contains animations / a sprite
The block has these attributes:
- stays stationary
- is either jump through / not jump through
- contains a sprite
How would you do this? Since you can't use classes in C, and if Im not mistaken, the PSP SDK wont let you use C++
-
04-12-2010, 02:39 AM #10057QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
-
04-12-2010, 11:11 AM #10058QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
indeed, c++ is fully supported, in ur makefile, simply include -lstdc++ on your library line and your fine
also, you can use struct's in c, so that's how i'd go about it personally if i couldn't use c++(also generally you'll probably almost never find a situation where C is allowed, but c++ isn't, and vice versa1. 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
-
04-12-2010, 06:19 PM #10059QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Well I changed it to .cpp instead of .c, I also added that line on my makefile.
I get these errors after running 'make' :
main.cpp:Code:psp-g++ -I. -ID:/pspsdk/psp/sdk/include -O2 -G0 -Wall -I. -ID:/pspsdk/psp/sdk/i clude -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150 -c -o mai .o main.cpp main.cpp: In function 'int main()': main.cpp:18: warning: unused variable 'pad' psp-gcc -I. -ID:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150 -L -LD:/pspsdk/psp/sdk/lib main.o graphics.o framebuffer.o -lpspgu -lpng -lz -l -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o image.elf main.o: In function `main': main.cpp:(.text+0x74): undefined reference to `initGraphics()' main.cpp:(.text+0x80): undefined reference to `loadImage(char const*)' main.cpp:(.text+0xa0): undefined reference to `blitAlphaImageToScreen(int, int, int, int, Image*, int, int)' main.cpp:(.text+0xa8): undefined reference to `flipScreen()' collect2: ld returned 1 exit status make: *** [image.elf] Error 1
Makefile:Code:#include <pspkernel.h> #include <pspdebug.h> #include <pspcallbacks.h> #include <pspctrl.h> #include "graphics.h" // #define drawImage blitAlphaImageToScreen PSP_MODULE_INFO("Name Of Program",0,1,1); int main() { pspDebugScreenInit(); //pspDebugScreenClear(); SetupCallbacks(); initGraphics(); SceCtrlData pad; Image* background = loadImage("back.png"); drawImage(0,0,480,272,background,0,0); flipScreen(); sceKernelSleepThread(); return 0; }
Code:TARGET = image OBJS = main.o graphics.o framebuffer.o CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) LIBS = -lpspgu -lpng -lz -lm -lstdc++ EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = Image PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
-
04-12-2010, 06:26 PM #10060Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
you dont need -lstdc++ so you can compile an app using graphics.h
you should make sure you have libpng and libpspgu fallow this tut and you will have a working base code for it
Lesson 04 - Simple Image Processing.
-
04-12-2010, 06:48 PM #10061QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
I have graphics.h and graphics.c and framebuffer.c and framebuffer.h, I also have libpng installed.
And I removed that line from my Makefile (since you said it's not needed)
What's wrong with my code?
-
04-12-2010, 06:53 PM #10062Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
thats your problem the functions in your graphics.h and .c files are not being recognizedmain.o: In function `main':
main.cpp:(.text+0x74): undefined reference to `initGraphics()'
main.cpp:(.text+0x80): undefined reference to `loadImage(char const*)'
main.cpp:(.text+0xa0): undefined reference to `blitAlphaImageToScreen(i nt, int,
int, int, Image*, int, int)'
main.cpp:(.text+0xa8): undefined reference to `flipScreen()'
collect2: ld returned 1 exit status
make: *** [image.elf] Error 1
also change your main.cpp to just main.c and make sure are in the same folder as the makefile
-
04-12-2010, 06:54 PM #10063QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
But they're in the same directory as my main.cpp file..........
-
04-12-2010, 08:57 PM #10064QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Wonder why it isnt working
-
04-12-2010, 09:41 PM #10065QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
the extension has nothing to do with it
beat_bob, the error is because the program doesn't see those functions, your makefile looks good, so i'm not certain why it's complaining
hmm, i wonder, unlikly, but try:
i doubt it'll 100% work, but give that a shotCode:TARGET = image OBJS = framebuffer.o graphics.o main.o CFLAGS = -O2 -G0 -Wall CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) LIBS = -lpspgu -lpng -lz -lm -lstdc++ EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = Image PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
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
-
04-12-2010, 09:55 PM #10066words 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
GNU GCC recognizes .C, .cc, .cpp, .CPP, .c++, .cp, .cxx as C++ files and will use C++ compilation regardless of whether you invoke it through gcc (C) or g++ (C++).
Note the .C - that is a capital C, the case matters in GCC. .c is a C file whereas .C is a C++ file (if you let the compiler decide what it is compiling based of file extension that is).
Beat_Bob, you are compiling your main source file as C++ which is fine but you're including a C source file (graphics.h).
You need to either rename main.cpp to main.c to force the compiler to compile it as C (not C++ so it can include the graphics C source file)
OR
Tell the compiler in your C++ source code that you are including a C source file
I recommend just renaming main.cpp to main.c and removing -lstdc++ from your libs line. You are not programming in C++ (yet) and you're using a C graphics library.Code:extern "C" { #include "graphics.h" }
...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-13-2010, 12:14 PM #10067QJ Gamer Gold

- Registriert seit
- Nov 2008
- Ort
- CAD
- Beiträge
- 693
- Points
- 13.372
- Level
- 75
- Downloads
- 19
- Uploads
- 4
Does anyone know how to remove an image from the screen (not de-allocating it) without using flags?
-
04-13-2010, 12:27 PM #10068QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
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
-
04-13-2010, 03:40 PM #10069Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
he already had his makefile like that the order of the objects dont matter but after making changes just to be sure you should clean the source by typing "make clean" because its showing an error in the main.o file with the error code such as this from his earlier post
this could help get rid of those errors cause it tries to compile the main.o files already made to save time on compilingmain.o: In function `main':
main.cpp
.text+0x74): undefined reference to `initGraphics()'
main.cpp
.text+0x80): undefined reference to `loadImage(char const*)'
main.cpp
.text+0xa0): undefined reference to `blitAlphaImageToScreen(i nt, int,
int, int, Image*, int, int)'
main.cpp
.text+0xa8): undefined reference to `flipScreen()'
collect2: ld returned 1 exit status
make: *** [image.elf] Error 1
-
04-13-2010, 04:06 PM #10070QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
i was fairly certain changing the order wouldn't matter, i do agree a make clean may solve it, otherwise i don't see an issue with the makefile, i checked the graphics.h that he was linked to in another thread, it has the appropiate functions listed, and defined, so i'm not sure of the issue
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
-
04-13-2010, 05:03 PM #10071Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
-
04-13-2010, 05:48 PM #10072QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
I used SG57's method using extern C, and it worked!
Thanks!
-
04-13-2010, 06:31 PM #10073Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
-
04-13-2010, 07:40 PM #10074QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
i swear i've used c and cpp files without externing them, w/e
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
-
04-14-2010, 10:10 AM #10075QJ Gamer Green
- Registriert seit
- Jun 2009
- Beiträge
- 61
- Points
- 2.003
- Level
- 27
- Downloads
- 0
- Uploads
- 0
char/double ore string with printtextscreen
I was wondering how should i use a doucle (%d) with printtextscreen (graphics.h) like
Code:printf("%d", scePowerGetCpuClockFrequency());
-
04-14-2010, 11:10 AM #10076Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
because the way scePowerGetCpuClockFreque ncy(); was set up was to return the cpu to a buffer or t fill in the variable and %d is the variable that is being represented in the printf because we dont know what the CPU speed is so we find out what it is then return it to the variable
the way you should use it is by
A better way is to show both the CPU speed and the BUS speed and heres howCode:int CPUClock[17]; //buffer to save the info sprintf(CPUclock, "CPU: %d", scePowerGetCpuClockFrequency()); //Only prints out the CPU speed i.e. 333 or 222
Dont forget to add #include <psppower.h> to the main.c and or main.h if you have one for the cpu stuff and addCode:int CPUClock[17]; //buffer to save the info //this following line will print out the CPU and the BUS speed i.e. 333/166 or 222/111 sprintf(CPUclock, "CPU/BUS: %d/%d", scePowerGetCpuClockFrequency(), scePowerGetBusClockFrequency());
-lpsppower to the LIBS = line in your make file
hope i explained it clearly enough if it doesn't make any sense then ask another question and ill clarify itGeändert von lilmnm (04-14-2010 um 11:22 AM Uhr)
-
04-14-2010, 05:51 PM #10077words 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
lilmnm - Your CPUClock array of integers ought to be an array of characters.
and snprintf for buffer overflow protection :)Code:char CPUClock[17]; //buffer to save the info sprintf(CPUclock, "CPU: %d", scePowerGetCpuClockFrequency());
Code:char CPUClock[17]; //buffer to save the info //this following line will print out the CPU and the BUS speed i.e. 333/166 or 222/111 snprintf(CPUclock, 17, "CPU/BUS: %d/%d", scePowerGetCpuClockFrequency(), scePowerGetBusClockFrequency());

...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-14-2010, 05:57 PM #10078Developer
- Registriert seit
- Jul 2008
- Ort
- Grand Rapids! MI
- Beiträge
- 125
- Points
- 8.092
- Level
- 60
- Downloads
- 5
- Uploads
- 2
lol the buffer is big enough so there wouldnt be an over flow its basically the same way i have it set up in my DayPR and im not having any troubles with it but good add though its better to be safe then sorry i guess lol also i havent seen the snprintif function anywhere what file is it in in the SDK?
-
04-14-2010, 06:21 PM #10079QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Nevermind, works.
Geändert von Beat_Bob (04-14-2010 um 06:51 PM Uhr)
-
04-14-2010, 06:21 PM #10080words 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
lilmnm - It isn't part of the SDK, it is part of stdlib. Its not that it 'will' overflow, its just a good habit and to be consciously aware of what might happen.
Practical use: I used a 256 long buffer for a texture filepath that ended up being like 300 characters long after all was done with it from the relative sub-directories. I couldn't figure out 'why' it was failing to load until I realized it was cutting off the final few chars of the filename. If I hadn't of used snprintf, it would've been a buffer overflow with undefined behavior. Instead I simply printed the buffer out to the debug stream and sure enough I saw it was missing the last half of the filename. Then I simply upped the buffer to 400 in size.
...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


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