I''ve been doing OpenGL for about a week and C++ for about 2 weeks (talk about rushing it) but the prototypes thing is new to me.
In Nehe''s tutorials all his functions come before the main loop, (WinMain), but I presume that these functions could be put after it as long as I put a prototype for each above WinMain. So when you say put all the prototypes, do you mean just the prototypes of any functions in the second.cpp.
ie-will this work:
-Put my 3D engine in 1st.cpp
-Put my 3D fonts into my 2nd.cpp
-Make prototypes of all functions in 2nd.cpp and put them into a 3rd file with extension ''.h''
-Include this ''.h'' at top of 1st.cpp
Thanks for the help by the way.
Either I can't count or OpenGL can't count ! ! ! ! !
quote: Original post by PCI
I ain''t using numbers that go forever, i was trying to get 0.025
That''s the problem, though, 0.025 does go on forever in binary representation (which is the only representation your computer understands internally). Instead of 0.025, it stores it as 0.0249996 (approximately)
I''ve gotten into the practice of writing non-trivial answers as pages on my web site so here''s the link...
function prototypes and header files
Please notify me of any mistakes I may have made.
http://tannara.2y.net/
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
What about variables ?
Using just the OpenGL window, I took DrawGLscene into a second file and doing all the header things it worked,.....But when I tried it with my 3D world, putting DrawGLscene into a second file, it told me that the variables in DrawGLscene were undefined, (they are in the main file), so I copied all the variables into the 2nd file as well, but not it tells me that they can''t be defined twice? How do I do this when the same variables are required in 2 different files
eg- In WinMain is were I ''watch'' for key presses, when a key is pressed it alters a variable and this variable will be used in DrawGLscene to move the polygons.
Thanks for the help.
Using just the OpenGL window, I took DrawGLscene into a second file and doing all the header things it worked,.....But when I tried it with my 3D world, putting DrawGLscene into a second file, it told me that the variables in DrawGLscene were undefined, (they are in the main file), so I copied all the variables into the 2nd file as well, but not it tells me that they can''t be defined twice? How do I do this when the same variables are required in 2 different files
eg- In WinMain is were I ''watch'' for key presses, when a key is pressed it alters a variable and this variable will be used in DrawGLscene to move the polygons.
Thanks for the help.
Dunno how that''s supposed to be done. You could do this, though:
Now, elsewhere in the program, you can access the variable using:
Note that you don''t need an instance of the class!
class MyGlobals { public: static int MyVar;};int MyGlobals::MyVar = 0 // This MUST be declared also!!!
Now, elsewhere in the program, you can access the variable using:
MyGlobals::MyVar;
Note that you don''t need an instance of the class!
You can only define global variables once. So, if you''re declaring all your variable in main.cpp: eg.
int gdone;
float happystuff;
Then you want to access those variables in your other files, such as second.cpp, you use the extern keyword:
extern int gdone;
extern float happystuff;
This will instead of creating a whole new variable, simply say that gdone is defined somewhere else, and all should be good.
int gdone;
float happystuff;
Then you want to access those variables in your other files, such as second.cpp, you use the extern keyword:
extern int gdone;
extern float happystuff;
This will instead of creating a whole new variable, simply say that gdone is defined somewhere else, and all should be good.
In my previous comment, also note this. If you choose to give a variable an initial value when declaring it:
int gdone = false;
Then you CANNOT assign values to these variables in your other files by saying:
extern int gdone = true;
Simply because, what should gdone equal? true or false?
Nor can you assign a value to an extern if it ISN''T assigned a value when it''s first declared:
int gdone;
I recommend before working with OpenGL, that you familiarize yourself more with the basics of C/C++. Such as making simple ANSI programs that span between more than one cpp file. You''ll see that your OpenGL code will greatly improve in it''s design (which may not mean much to you now... but trust me, it will)
int gdone = false;
Then you CANNOT assign values to these variables in your other files by saying:
extern int gdone = true;
Simply because, what should gdone equal? true or false?
Nor can you assign a value to an extern if it ISN''T assigned a value when it''s first declared:
int gdone;
I recommend before working with OpenGL, that you familiarize yourself more with the basics of C/C++. Such as making simple ANSI programs that span between more than one cpp file. You''ll see that your OpenGL code will greatly improve in it''s design (which may not mean much to you now... but trust me, it will)
Try this:
if (alp <= 0.0) {cha = 0;}
if (alp >= 1.0) {cha = 1;}
if (cha == 0) {alp+=0.025;}
if (cha == 1) {alp-=0.025;}
This way it will work if the floating point numbers are a little off.
Zack
A moment enjoyed is not wasted.
-Gamers.com
if (alp <= 0.0) {cha = 0;}
if (alp >= 1.0) {cha = 1;}
if (cha == 0) {alp+=0.025;}
if (cha == 1) {alp-=0.025;}
This way it will work if the floating point numbers are a little off.
Zack
A moment enjoyed is not wasted.
-Gamers.com
A moment enjoyed is not wasted. -Gamers.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement