Off topic C++ question, But its for use in OpenGL

Ok here is my issue.
I am working on a way to load my models from a .txt file into my program to render them. The problem is, I dont know how many models there will be, nor do i know how many verts apiece they will be when they are finished.

I would like to create a “for” loop to load my models into arrays, to be used by opengl to render with draw elements. Now obviously i can dynamicaly allocate arrays with the
int *Array = new int[NumberOfVerts]; Where the number of verts is the first thing read from the .txt file. So the not knowing how many verts to put into the array is solved. The problem is creating an unknown number of arrays themselves.

I would really like a way to dynamicaly create array names for the number of arrays needed. Something like this (obviously this dosnt work, or i would use it instead)…

for(int x=0; x<NumberOfArrays; x++)
{
int *Array(x) = new int[NumVerts];
}

so if x=4; i would wind up with
Array0;
Array1;
Array2;
Array3;

Anyone have ANY idea how one would so something like this. I have used sprintf before to do something similar with strings, but I dont think it will work with variables…Thank you so much in advance.

#include <vector.h>

typedef struct {
float x,y,z;
} vert;

typedef struct {
…model crap
vector<vert*> vertices;
} model;

main()
{
vector<model*> models;
model *amodel;
vert *avert;

for (while models)
{
amodel = new model();
… fill out model info
models.push(amodel);
for (verts in this model)
{
avert = new vert();
… fill out vert info
amodel.vertices.push(avert);
}
}
}

STL would work great for this, or create your own linked list.

[This message has been edited by nickels (edited 07-24-2002).]

That looks like it would work well, but with my current setup I would REALLY like to stick with everyday arrays. Mainly because im not familiar with STL, and switching over my current code (which is QUITE) long, could turn out to be a very very arduous task. Is there any other way to do this with plan old arrays??

Never mind; I think i found the answer. I will simply set a Max Number of possible items. Then create an array of pointers for that max number. Like this. int *Pointers[MaxNumber]; and allocate all i need with Pointer[x] = new int[Whatever];
So thank you for helping anyways.

Originally posted by dabeav:
That looks like it would work well, but with my current setup I would REALLY like to stick with everyday arrays. Mainly because im not familiar with STL, and switching over my current code (which is QUITE) long, could turn out to be a very very arduous task. Is there any other way to do this with plan old arrays??

Hi

well, when you dont try to use STL you won’t get familiar You don’t need to change all code at once. For example you can use nickels suggestions and fill all your data in a STL vector. When you are ready you just create some plain C arrays with the STL vectors size and fill them with the STL vectors data.

When I firstly came in contact with STL I thought it would be crazy, but now I couldn’t live without it

Bye
ScottManDeath
P.S. I hope I pulled someone to the light side of force ;D