PDA

View Full Version : choose the right .h file.... (C++)



grodslukaren
05-30-2001, 01:05 PM
Hi,

Sorry if this isnīt a "real" OpenGL topic, but maybe somebody have done the same before...

I use a file generated by 3dexplorer (.cpp) to import a 3D-object into my OpenGL window. I changed the file to be a .h file and in the end of that file there is a function called Gen3DObjectList() that I use like:

m_uiDisplayListID = Gen3DObjectList();

The thing is that Iīd like to use the same OpenGL window to be able to import different 3D-objects that I import from the .h file via the function above.

But the .h-files have the same function Gen3DObjectList() so that makes things a mess....

Somebody got a clue??

royster
05-30-2001, 01:11 PM
I know what you mean.
I have the same problem and would love to know a solution.

At the moment the only thing I can think of is by creating a loader to just handle the data output option.

ffish
05-30-2001, 04:31 PM
This is a long shot - I don't have a compiler on this computer so I can't test it. I was thinking maybe you could do something like this:



namespace file1 {
#include "file1.h"
}
namespace file2 {
#include "file2.h"
}

Does that work? I'm guessing it won't. Otherwise, you could go into each .h file and wrap the whole file in a namespace. Then just call file1::Gen3DObjectList(), file2::Gen3DObjectList() ...

Hope that helps.

MrShoe
05-30-2001, 09:38 PM
Ummm, well, what I did, delete everything except the vertext, texture, normal arrays, and used them as you would any other arrays, but you must do it in the proper order, thats what the other array is there for.

grodslukaren
05-31-2001, 06:58 AM
Thanks for the answers.
Iīve tried to use namespace, I donīt know if Iīm doing something wrong, but I get a error message that Head is not a class nor a namespace when I do like:

... = Head::Gen3DObjectList();

But I had another idea, to change the name of the function Gen3DObjectList() to GenerateCabezaList() or something like that, I changed the name of the function in the .h file and the call to the function, but I just get the error message:
'GenerateCabezaList' : undeclared identifier
Error executing cl.exe.

Does that mean that Gen3DObjectList() is a kind of function that is already known??? Otherwise itīs quiet simple to just change the names of the functions and include all the desired files....

/grodslukaren

royster
05-31-2001, 11:04 AM
Thanks ffish!
That namespace trick worked a treat.
That makes things a lot simpler and easier.
I haven't used namespace before but I think it will become a very much used item in my game.
Thanks again.

grodslukaren
05-31-2001, 11:56 AM
yeah, Thanks a lot!!

I mixed my files in a stupied way, so it didnīt work... but now it does....

thanks again!!

ffish
05-31-2001, 04:22 PM
Glad it helped. That's actually what most C++ implementations do to wrap the C libraries in the std namespace. That's why you should now code like this in C++:



// The old way.
// #include <math.h>
// #include <stdio.h>
// etc ...

// The new way.
#include <cmath>
#include <cstdio>
// etc ...

I think from memory that files like cmath just look similar to this:



namespace std {
// Some stuff here.
#include <math.h>
// Some more stuff here.
}

but don't quote me on that. Again, I don't have a compiler on this computer (uni library) but if you're interested, have a look at some sample files on your computer, like $INCLUDE_PATH/cmath etc.