Explain...why not -_-Zitat:
Zitat von psphacker12.
Printable View
Explain...why not -_-Zitat:
Zitat von psphacker12.
!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! !!!Zitat:
Zitat von hallo007
YOU GOT THE 2800th post on the 280th page !!!!!!!!!
Why cant you useZitat:
Zitat von hallo007
pspDebugScreenSetTextColo r();
... like normal people :P
-= Double Post =-
Thanks for spamming the C/C++ help thread.Zitat:
Zitat von psphacker12.
because i aint using pspDebugScreenPrintf
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...
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:
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 =-
http://forums.qj.net/showpost.php?p=...postcount=2645Zitat:
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:
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.
how do you declare a variabel that you can use in all .c files
(no constant)
for example
int pressedbutton=false;
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;
}
thnx :) , trying it out
i did always in the header file this
extern int pressedbutton=0;
and no source file:)
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?
Why do you need multi threading?Zitat:
Zitat von Mr305
I am aboout the complete reinstall the toolchain
how do i do it the best way for
-making eboots (ofcourse)
-making prx
-use fonts
-...
Need Simultaenous interaction of user control processing & aswell as background/enemy rendering.Zitat:
Zitat von yaustar
When I tried, When that happens[background rendering] the other doesn't respond [reponce to key pressess/analog movement]. :o
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.
Would you mind sharing how it is doen?Zitat:
Zitat von yaustar
In puesdo code:
begin game loop
- get user input
- process user input
- render
end game loop
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
}
Code:int main ()
{
bool gameOver = false;
while( !gameOver )
{
// Get pad data
if(pad.Buttons & PSP_CTRL_CROSS)
{
gameOver = true;
}
}
}
Fairly simple:Zitat:
Zitat von BlackShark
Code:if(pad.Buttons & PSP_CTRL_CROSS) {
sceKernelExitGame();
}
cool, that is fairly simple :P, thanks
yaustar - It seems gluLookAt has all glLoadIdentities point to where the camera is, which is where my person is. After removing the glLoadIdentity() from my cube function, it draws the cube just as i wanted.
Ok, now the only thing is, can I use glPush/PopMatrix to be able to translate, and still go back to 0,0,0 without calling glLoadIdentity, or after all drawing is done after translating to where i wanted and retranslating back negative whatever i had before... ahh its hard to explain. Can i do this:
Would the above draw 2 cubes at 10,4,10, or would it drawone cube at 10,4,10 and one at 0,0,0?Code:glPushMatrix();
DrawCube(10,4,10); // x,y,z are the arguments
glPopMatrix();
DrawCube(0,0,0);
If it does draw 2 cubesat 10,4,10, than can ido this to compensate:
Code:DrawCube(10,4,10);
DrawCube(-10,-4,-10);
Both of your code samples will work SG57.
I'd recommend using push/pop or using something like:
Code:glLoadIdentity();
DrawCube(10,4,10); // x,y,z are the arguments
glLoadIdentity();
DrawCube(0,0,0);
Thats just it though, it seems when using gluLookAt (im using it for my camera class, so i can move around, look around, etc.) it resest the view matrix to my camera, so calling glLoadIdentity() than drawcube(1,1,1), it draws my cube where my camera is + 1,1,1. But your saying hte pushing/popping of hte matrix will work? Either way, Id get it to work as reverse translating would be hte same as reloading the identity.
I have made a game. When the game is complete, i want to be able to restart the game. I am looking for a method to restart the application. Any ideas? Would calling the main loop work?
It has been a while since I used OpenGL, this *should work*Zitat:
Zitat von SG57
glLookAt
glPushMatrix
glTranslate
// Draw the first model
glPopMatrix
glPushMatrix
glTranslate
// Draw the second model
glPopMatrix
-= Double Post =-
No.Zitat:
Zitat von JaSo PsP
Code:bool exitFlag = false, resetFlag = false;
while( !exitFlag )
{
// Reinitialise the game
while( !resetFlag )
{
// Run the game
if( /* the reset condition is met */ )
{
resetFlag = true;
}
}
// Deinit the game
resetFlag = false;
}
Zitat:
Zitat von JaSo PsP
just some help from my part;Code:continue;
Or Use goto
Woah. Goto == bad. There is on one real reason to use goto in code and that is to get out of a REALLY nested loop/if statements. Goto in general confuses the compiler so it won't make the best optimisations and also VERY prone to spagetti code and is a maintenence nightmare. You don't need goto for something this simple.Zitat:
Zitat von Mr305
Continue just finishes the current loop immediately. It doesn't really reset anything.
yet again, this (i hope) should be a fairly simple question, how do you play sounds on the psp?
-= Double Post =-
O also, How do you make the "printTextScreen" text bigger, (is there a way?) or can you load true type fonts?
I was told goto and continue statments should be avoided at all costs. So, I didnt learn how to use them :P Im sure it's something like:
Im sure it's wrong, but from a logical point of view, thats how Id imagine it works... Its probably for hte best i dont learn them, else ill try to use them in situations where i have no other choice (that i know of).Code:constructor:
score = 0; life=100;
// basically run through whole code, from the start of 'main'
...
if(life<=0) { goto constructor; }
I can load and render MD2 models and there animations now very easily, ive been able to since last summer, but until now i could never get the rendering correct since when i translated my model, itd always move with the camera. This was good, but only for the characters model :P
Anyways... Ill post back here with another question/problem. One will most likely be collision, Ill be doing either bounding box collision in 3 dimensions, or sphere-sphere collision insomniac mentioned to me... Can anyone possibly paste the function for one of them? If not, thats fine, ill go googling around and find one, and port it to C/C++ if necessary.
BlackShark - How about you take the initiative and SEARCH. The SDK has audio samples. As for the printTextScreen, you CANT change hte font size, and you CAN load and display TTF fonts (which can be scaled in size and whatnot incode). Try searching for a change... FLIB i believe its called.
-= Double Post =-
ahhh... Ok, i need someone to look at my code. After changing all my macros to constants, and changing all things like 'macro*2' to there actual values) Now its all screwd up :-\ Ive tried changing them all back, but its still happening, meaning i havent changed everything back... Im sure theres just some bug that is making hte camera move out in the middle of nowwhere. I mean, it should atleast show the 200x200 grid that is around thecamera, but it doesnt... So, insomniac/yaustar (raphael probably won't want to help sincehe's away from his computer.... or he might not want to help period :() if you are feeling generous, could you help if i dont eventually get it tonight? As I said, it's probably a novice mistake, so it should stick out i hope (although it isnt sticking out for me...). Thanks alot if you canhelp, im just starting to find my models and whatnot, so having to stop and debug is kind of a let down :-\
-= Double Post =-
I know how much all of you were dying to help me with my problem [/sarcasm] but Ive fixed it. Turns out my little tweakings led to a push/popMatrix error, which led to unknown results which endep sending my camera flying randomly 8-|
Now, Im getting back to actual fun stuff... Time to render alot of MD2 models, animate each one by the same animation number, and see which one i like... Oh and my game im planning on creating, is a type of sword fighting survival game... You go into a room, you fight an enemy, if you win, you go to the next room and fight either: the same guy but with a different skin, or scaled bigger, or better health or better strength and whatnot. Or, a completely diferent model. I hope to have it after you get past every 5 rooms, you have a different weapon. I have a whole surplus of MD2 models, and weapons and all there animations, so given timethis will work. And best of all, the collision shouldnt be too difficult. If you wswing your sword and it collides with teh enemy (give or take a unit or 2) and the sword collides with the other model, it hurts them. The problem that is closest to me in code is the tesselation of the rooms walls. I know each room can be a skybox which i will be doing, but first i need to write the function that Raphael posted an example, im just procrastinating as i really dont want to do the math and work it out so all 6 faces of the room are drawn without culling :\ Id absolutly love if someone else did :D Save me the headache, but im a novice, so it might be best if i do it myself...
mm, im having trouble introducing a state system, what im trying to do is first define the state like...
bool gState = "menu";
then ill try to make loops that happen when in that state, like
while (gState == "menu") {
blaba bal
balb al bal
interger 1337 bla counterstrike bap
blaj baoi }
so fare i tried adding just those to but i get errors such as,
'bool' undeclared (first use in this function)
syntax error before 'gState'
'gState' undeclared (first use in this function)
any suggestions?
I suggest you read up on the bool data type (booleans are either true or false Also, Ill spare you the bash and just say, either include typedef.h or copy and paste:
into your code. But enumerators arent that necessary when you can simply use the integer data type, along with 2 macros (or const if you wish)Code:typedef enum _bool { FALSE, TRUE } bool;
or you can even go a step further:Code:#define true 1
#define false !true
int my_bool = false;
Anyawys, for your case, youd have to use C++ to compare strings using the == operator, else youll have to use strcmp or some other method .. But, i highly recommend using macros as they would take up 2 bytes or so (i think its 2 bytes for just a whole number), compared to the 2 bytes per-character if you were to use a string (i think it's 2 bytes per char.. or is it 4?) This is what im talking about:Code:#define true 1
#define false !true
#define bool int
bool my_bool = false;
Code:#define menu 1
int game_state = menu;
...
while(game_state == menu) { ... }
a boolean is generally a variable that is made to hold two states: TRUE or FALSE. You are trying to assign it a string. That won't work. Apart from that, there's no default bool type defined in GCC (you'd have to do it yourself through a typedef int bool;).
This will work because you are having constant strings in memory and assigning a pointer to the string to the variable gState. Don't get the idea that it actually copies the string "statex" into the variable gState, or that you can compare two strings with 'string1 == string2'. It only works because they are always different in this case, if the pointers are different.Code:char* gState = "state1";
while (gState=="state1")
{
...
// some condition
gState = "state2";
}
However, for your minds' sake, I would recommend you try to define states through integer values as most people do it.
@SG57: Try to come up with that yourself, really. It's not hard at all, you just need to concentrate on what you want to achieve (create a tesselated unit cube) and go through the single steps of my sample code and think up what it actually does, then change it so it fits your need. Most of the time you'll only need to swap around two of three coordinates in my code to get another cube face.Code:#define STATE1 0
#define STATE2 1
... more
int gState = STATE1;
while (gState==STATE1)
{
....
// The same
gState = STATE2;
}
hmm, I dont quite understand whats going on? How do I 'Deinit' the game?Zitat:
Zitat von yaustar
Ok, I rephrase that:
Code:bool exitFlag = false, resetFlag = false;
while( false == exitFlag )
{
// Initiialise the game. Allocate memory, set values correctly etc.
while( false == resetFlag )
{
// Run the game
if( /* the reset condition is met */ )
{
resetFlag = true;
}
}
// Clean up the game. Free any allocated memory, resest values etc
resetFlag = false;
}
Raphael - Didnt I say a variation of what you said ;) As for the tesselation (god i love that word... its just so... foreign to me...) I know, Ill probably just treat one value as a '1', and the other as 0. Than, ill compare your set of verticies to a cubes set, and replace all 1s with there respective values, and 0s with theres. Its hard to explain it, but I understand it, and I know i can do it myself, i just am procrastinating the headache I have a feeling ill get :(
Also, 10, ~1,000 poly, animated-textured MD2 models of a knight and his sword (so its 20 models, since tris + weapon), running at around 30 FPS. (sorry for the attactment, i cant upload it to my site at the moment) Thats promising :) That means i can have around 7,500 (im averaging) poly's for a decent game all rendered at once... Yay :)
Can someone tell me how exactly (and/or provide a sampleà to print a png on the screen using Gu ? i have one way to do it, but it's really dirtry coz it implies blitting the images then start gu and finally draw what gu has to draw, and then flip the screen. This causes an huge performance loss and I think it would be better to use Gu (less graphics bugs than the described "workaround" (we can see the screen flicker when an mp3 is played)), but I really ain't able to use Gu properly by unterstanding it's parameters. You'll understand why I ask :)
Basically, what I want to do is to draw a background under the "donut" gu example (celshading), already managed to print texte, but I don't undersand for png files.
DreamTeam - Simple; map your PNG texture onto a quad, and scale it so it fills the screen (or us an ortho view, but i dont know if you can z-order it so the torus is infront).
thank you very much! it works very well! :tup:Zitat:
Zitat von yaustar
7,500 isn't a lot really at 30 FPS. Once you add sound playback, collisions etc etc that'll drop dramatically.Zitat:
Zitat von SG57
That's 225,000 triangles per second.
For comparison I'm pushing around 20,000 triangles with 3 lights, full audio playback, collisions etc etc at around ~120 FPS.
That's 2,400,000 triangles per second - a big difference :)
Thank you SG57 and Raphael, very helpful :tup:
EDIT: nice screen there SG :)