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; http://www.dcemu.co.uk/vbulletin/showthread.php?t=25564 Scroll down and click on the link in the PSP Libs part. Also make sur to downlaod the graphics.h ...
-
02-16-2007, 04:27 AM #2791
http://www.dcemu.co.uk/vbulletin/showthread.php?t=25564
Scroll down and click on the link in the PSP Libs part.
Also make sur to downlaod the graphics.h and framebuffer.h pack in the lesson, serched them for hours and they were in the lesson
-
02-16-2007, 11:58 AM #2792QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
lol, thanks, I actually dled the frambuffer.h and the graphics.h but i didn't use it till now, stupid me, so do i just put them in the same directory as the main.c right? Ill go get the libs now, thanks alot!
EDIT: do i need the framebuffer.c and Graphics.c that came with it? or are they just examples?
EDIT2: ok nvm, i found out I do need them :) afnd YAY, I handcoded my first C Program, no copy and paste job!Geändert von BlackShark (02-16-2007 um 01:10 PM Uhr)
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
02-16-2007, 01:16 PM #2793
.c and .h files must be in the same directory as your project (or can be in another directory, is the makefile is well done, but that's another story)
--------
Now for my problems : ^^
I'm experiencing PSPGL. I've been compiling and testing all the examples, and I have been modifying the celshading example, wich learnt me things like ^= (if anyone can give me precisions about that following code is welcome :
unsigned int flags = PSP_CTRL_CIRCLE | PSP_CTRL_CROSS | PSP_CTRL_SQUARE | PSP_CTRL_TRIANGLE;
flags ^= pad.Buttons;
It seems that it's like an "on/off" switch trigerred when you press the button.)
Now for the main prob :
I want to change the torus' color.
So i've fired up Paint.Net (only thing i have here) and picked up some red (#FF0000). the problem is that it shows up as blue.
The psp pallete seems to be inverted compared to that one.
I'm sure that there's something different between #FF0000 and 0xFF0000 , but how can i convert #COLOR to 0xCOLOR ?
-
02-16-2007, 01:32 PM #2794Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
strange prob
part in colors.cCode:dumpMenu.o: In function `setBlueTextColor': dumpMenu.c:(.text+0x0): multiple definition of `setBlueTextColor' colors.o:colors.c:(.text+0x0): first defined here
Code:int setBlueTextColor() { return(0xFF5555); }
use in dumpMenu.c
Code:printg(20,150," Dump flash1" ,setBlueTextColor() );
colors.h
Code:int setBlueTextColor();
i dont really understand this
-
02-16-2007, 01:44 PM #2795
When functions are called multiple time, it can think you are trying to define them when you have missed a ;
sometime i had that error with sceDisplayWaitvBlankStart
Just check your line ends , check all of your ;
BTW, you could change that with simply :
#define BlueTextColor 0xFF5555
printg(20,150," Dump flash1" ,BlueTextColor );
Don't know if that works, haven't tested it but there's no reason that it fails. I've already used that
-
02-16-2007, 02:27 PM #2796words 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
Dream_Team - I use PSPGL as my main graphics API for hte PSP, and you are corerct, the Hex value coloring system is inverted, so instead of hte reknown RGBA, it's ABGR (32-bit on both).
Ex:
Red - 0x000000FF
Green - 0x0000FF00
Blue - 0x00FF0000
Black - 0x00000000
White - 0x00FFFFFF
Also, I dont think your talking about PSPGL, as there is no torus example (that i know of) but I do know there is a GU torus example.
-= Double Post =-
DreamTeam - That would work (however I think that function requires a 32-bit color), also, that method is more efficient as macros are simply names of the code following them, that are replaced by the code following them during preprocessing, compared to a function.Geändert von SG57 (02-16-2007 um 02:30 PM Uhr) Grund: Automerged Doublepost

...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
-
02-16-2007, 05:10 PM #2797QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Beware of this 'trap'. Macros are not automatically faster as you can easily inline small functions and the compiler is most likely to do a better optimisation then you can by hand.
Zitat von SG57
Always assume the compiler can optimise better then you can unless you can prove otherwise (ie use a profiler).
Instead of #defines for literal values, use constants. Much easier to debug.[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]
-
02-16-2007, 06:04 PM #2798words 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
In his case, that would be better seeing as how it's a value:
But what if it were a function ;) Macros seem best there:Code:const blue = 0x00FF0000L
Also, this is automatically inlined when using C++ right?:Code:#define sayHello pspDebugScreenPrintf("Hello")
inlining confuses meCode:if ( blah == "blah" ) { blah = "no_blah"; } else if (blah == "no_blah") { blah = "blah"; }
What is the advantages of it? I know that 'inline' anything (functions, lines of code) might make the code faster, might make it slower. They might make the EBOOT larger, they might make it smaller. They might cause crashing, they might prevent crashing. And they might be totally irrelevant to speed . So what's the big deal? I mean, if there are soo many pros and cons, Im sure for every pro, there's a con, making it poitnless to inline in the first place... ahhh my head hurts... I need a crash course on the 'inline' keyword
When to use it, when it's effective, example of when it's effective, etc... yaustar, Raphael, Insomniac, etc. - your view and knowledge on the 'inline' keyword maybe? sorry for being real naieve on the matter, but googling doesnt give me a fully understandable definition 
Ive gone so far, but I know so little... embarassing
Geändert von SG57 (02-16-2007 um 06:20 PM 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
-
02-16-2007, 09:19 PM #2799likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
NEVER EVER #INCLUDE .C FILES!!!
Zitat von hallo007
-
02-16-2007, 11:38 PM #2800Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
what you think the colors.h is for
-
02-16-2007, 11:53 PM #2801QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Explain...why not -_-
Zitat von psphacker12.
[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
02-16-2007, 11:55 PM #2802likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! !!!
Zitat von hallo007
YOU GOT THE 2800th post on the 280th page !!!!!!!!!
-
02-16-2007, 11:58 PM #2803QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Why cant you use
Zitat von hallo007
pspDebugScreenSetTextColo r();
... like normal people :P
-= Double Post =-
Thanks for spamming the C/C++ help thread.
Zitat von psphacker12.
Geändert von Moca (02-16-2007 um 11:59 PM Uhr) Grund: Automerged Doublepost
[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
02-17-2007, 12:18 AM #2804Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
because i aint using pspDebugScreenPrintf
-
02-17-2007, 01:12 AM #2805words 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
Including .c files is kind of like appending whatever is in that file, to your code. I believe that unless you externally declare your function/prototype or variable:
it will complain of multiple references as it'd be 'seeing' the first definition of SetBlueColor, than see if re-declared as if you were trying to make another function with the same name... Im sure that's wrong but seeing it from a logical point of view, thats how I would imagine it...Code:extern long SetBlueColor();
However, its good practice to put common definitions in a header file which is #included by all your C source files. Note that this should only have definitions, not statements that actually generate code. So for example it should contain function prototypes, not function definitions. This will avoid the multiple function definition problems you had. Similarly, you can define variables that are to be used between source files as extern in the include file: this will allow all source filess to be aware that the variable exists and can be linked to, but only one of the source files should then declare the actual instance of the variable.
-= Double Post =-
Ok, time for me to havea question (also, raphael, yaustar or insomniac please read my 'inline' questions somewhere above this post, or in the last page depending on your posts-per-page viewing...).
Ok, I have a nice 3D world set up, and can walk around via symbol buttons, and look around via analog stick. So basically, it has a FPS control scheme. Ive just rendered a 3D gridded box as my little playing field until i decide to work on my sky box tesselation. Ive just applied boundaries so you can't walk outside the gridded box, and so now it's all working well. After adjusting my fovy to 90 rather than 45, the culling has reduced significantly and only little culling on hte grided box, but never an entire side is culled. Now, this presents me with a new problem now that I can draw new objects into the scene to create my world. To start, Ive drawn a simple cube. Only problem is, all my translation calls get messed up when moving the camera via walking around... Its hard to explain, so if youd like to help, and Id really like you to as Im a novice in 3D programming, ill send you my current build, and you can see just waht im talking about... Im sure it's a problem on my part, but right now im just testing around and seeing if there are other methods to fix it, other than supply definate set of verticies, compared to being able to translate a group...Geändert von SG57 (02-17-2007 um 05:14 AM Uhr) Grund: Automerged Doublepost

...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
-
02-17-2007, 05:16 AM #2806QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
First, you example of inlining above is not making use of the inline keyword. You are just writing literal values/magic number which has no effect on speed.
Zitat von SG57
Always prefer inlining over macros like these:Code:#define sayHello pspDebugScreenPrintf("Hello")
What this does is suggest to the compiler to do the same thing as a macro if it thinks it is faster to do so during optimisation.Code:inline void sayHello() { pspDebugScreenPrintf("Hello"); }
So if we use it here:
If the compiler doesn't think it be faster inilining the function, it will act like a function call, if it does, the compiled code will look like this effectively:Code:while (true) { sayHello(); }
The question is now why use inlined functions over macros. First, it lets the compiler decide on the optimisation and there generally your programs will be faster. Also it is a lot easier to debug, you can step into the inlined function in code during debugging and track each step whereas with macros, you have to resort to going into dissassembly since the text replacement is done before compile time. Also macros tend to be VERY error prone because of the nature of textual replacement.Code:while (true) { pspDebugScreenPrintf("Hello"); }
Inlined functions work best for small functions (several lines of code).
Macros generally should be avoided, unless you start using the advanced features or the standard #ifdefs, #ifndef, etc. The preprocessor is a lot more powerful then what you are currently using it for. Have a read:
http://gcc.gnu.org/onlinedocs/cpp/
For inlined functions, read Chapter 9 in Thinking in C++ Vol 1 (free ebook)
-= Double Post =-
C/C++ Programming Help Thread
Zitat von Moca
That's why.
-= Double Post =-
Right, this is going to ne a nutshell verison, the matrix system in OGL works on a stack base structure.
Zitat von SG57
PushMatrix
TranslateMatrix
DrawModel
PopMatrix
What this does is:
Push current matrix down on the stack
Applies Translation on the current matrix on the stack (ie the one you just pushed)
'Draw' the model
Pop the matrix off the stack
Because, it is a stack structure, its first in last out, so the last matrix to be popped is your translation matrix which gets applied to the model. So in 'reality' it would do is:
Draw the model
Translate it
If we had:
PushMatrix
TranslateMatrix
RotateMatrix
DrawModel
PopMatrix
This would rotate the model first then translate it.
PushMatrix
RotateMatrix
TranslateMatrix
DrawModel
PopMatrix
This would translate the model then rotate it round the current matrix.
If there is no matrix on the stack when you push it, it is the identity matrix (0, 0, 0) position with the standard axes.Geändert von yaustar (02-17-2007 um 05:58 AM Uhr) Grund: Automerged Doublepost
[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]
-
02-17-2007, 05:50 AM #2807Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
how do you declare a variabel that you can use in all .c files
(no constant)
for example
int pressedbutton=false;
-
02-17-2007, 05:56 AM #2808QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
In the header file
globals.h
In ONE source fileCode:#ifndef GLOBALS_H #define GLOBALS_H extern int pressedbutton; #endif // GLOBALS_H
globals.c
Then when you want to use it:Code:#include "globals.h" int pressedbutton = 0;
main.c
Code:#include "globals.h" int main( ) { pressbutton = 10; return 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]
-
02-17-2007, 05:59 AM #2809Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
thnx :) , trying it out
i did always in the header file this
extern int pressedbutton=0;
and no source file:)
-
02-17-2007, 07:02 AM #2810
Does anyone have an idea about Multithreading.
Tired of looping within loop within... so on.
Also sometimes it's impossible to do two different things at the same time!
Neither does sdk have any such samples!
Attach a small sample if possible....
Any help?
-
02-17-2007, 07:24 AM #2811QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Why do you need multi threading?
Zitat von Mr305
[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]
-
02-17-2007, 07:37 AM #2812Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
I am aboout the complete reinstall the toolchain
how do i do it the best way for
-making eboots (ofcourse)
-making prx
-use fonts
-...
-
02-17-2007, 07:40 AM #2813
Need Simultaenous interaction of user control processing & aswell as background/enemy rendering.
Zitat von yaustar
When I tried, When that happens[background rendering] the other doesn't respond [reponce to key pressess/analog movement]. :o
-
02-17-2007, 07:47 AM #2814QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You don't need multithreading for that. A single thread is more then enough. It is more likely that your code is the problem rather then lack of multi threading.
[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]
-
02-17-2007, 01:50 PM #2815
Would you mind sharing how it is doen?
Zitat von yaustar
-
02-17-2007, 02:05 PM #2816QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
In puesdo code:
begin game loop
- get user input
- process user input
- render
end game loop[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]
-
02-17-2007, 02:06 PM #2817QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Here should be a simple question,
how do you exit a program? like...
Code:if(pad.Buttons & PSP_CTRL_CROSS) { if(selComponent == 2 ) { *INSERT PSP EXIT FUNCTION HERE* } else if (selComponent == 1) { Blabla bla }NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
02-17-2007, 02:13 PM #2818QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Code:int main () { bool gameOver = false; while( !gameOver ) { // Get pad data if(pad.Buttons & PSP_CTRL_CROSS) { gameOver = true; } } }[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]
-
02-17-2007, 02:16 PM #2819
Fairly simple:
Zitat von BlackShark
Code:if(pad.Buttons & PSP_CTRL_CROSS) { sceKernelExitGame(); }
-
02-17-2007, 02:25 PM #2820QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
cool, that is fairly simple :P, thanks
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:


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