View Full Version : Import and interpret 3D files

10-02-2004, 03:20 PM
i have been working on a game for some days...
i programmed a interpreter for RTG and VRML files. Now i have a problem with dynamic arrays.
My program reads a line and saves the result into a array. When i declare the array i don't know the number of elements of the array. I have to use dynamic arrays but the should be more dimensional

So my question: does anybody know a interpreter of vrml 2.0 files or stuff like that.. i only need some short examples

sorry for my bad english
I hope y understand me....


10-02-2004, 04:32 PM
This hasnt anything to do with OpenGL.

You did not say what programming language you are using, nor which compiler. I assume you are talking about a modern C++ compiler, to solve your problem generate a STL vector that contains STL vectors as elements...

Simple eh?

In the future please just ask questions that are related to OpenGL and not basic coding.

10-03-2004, 05:06 AM
yes c++, in XCode and on MS Visual C++

thank you

Night Hacker
10-06-2004, 06:57 PM
Don't be sorry, since when does loading 3D objects have nothing to do with opengl?


You need to use structs. First you have one to define your vertex...

typedef struct
float x, y, z;

Then you have a struct for your object...

typedef struct
int verts;
VERTEX *points;

You create something to hold your object info...

OBJECT MyObject;

Somewhere in your code you will read in your object file, find out how many vertices it has and store that in:

MyObject->verts = NumberOfVertices

Then allocate space for those vertices with...

MyObject->points = (VERTEX*)malloc(sizeof(VERTEX)*MyObject->verts);

Once you do this you can store and access your objects vertex info like so:


...where i equals the vertex you want, and you tack on a .x, .y or .z.

If you wanted to do something with all the verts (like render them of course ;) ) you would use a loop like so:

for (i=0; i<MyObject->verts; i++) {
// do stuff with...
// MyObject->points[i].x
// MyObject->points[i].y
// MyObject->points[i].z

That's a very breif explanation, hope it helps.

10-15-2004, 12:52 PM
Thank you.. i solved the problem... but anther problem:
i also solved the problem with the texture mapping but does anybody know some tuts for UV mapping in opengl? How should i interpret the vrml/rtg to use the uv texture mapping?


10-16-2004, 05:05 AM
My problem is solved! sorry for the sensless posting...my texturcoordinates were in a wrong order (the texture was flipped)