Well, i get to this problem a lot, and while dynamic arrays sometimes solves the problem, it doesn't in this case.
I'm making app, that should read obj and render it, so to speak.
So, i have function "readVertexCount", which reads file (say, obj), and return number of vertices. Now, in my other function, where i create vertex buffer, i create array, and need to tell the size. So, i call this "readVertexCount" function, and it gives me number of vertices (int). I'm trying to use this as array size:
int vSize = getVertexCount("cube.txt");
CustomVertex vertices[vSize];
but, as you probably guessed, i get error, saying, that array cannot have variable size.
Ok so i understand why this happens, but i don't know how to "fix" it.
So, why i basicly want to do, is have a function that returns number of vertices, and then use this in creating an array for vertex buffer. And i don't want to use dynamic arrays
Well, i did try to use 'new', but problem was, that although it doesn't give me any error, it simply refuses to display mesh (like it didn't store values in array correctly).
I idid a like this:
CustomVertex* vertices;
vertices = new CustomVertex[fSize*3];
Maybe i did something wrong there....
b. sounds like solution that should work, but not sure if it's really ok, since it may not be the most optimized way.
Aha - when you said 'without using dynamic arrays' I thought you were excluding 'new', as an array created with new is often referred to as a dynamic array.
Using either new or a std::vector is almost certainly the way to go. Check out http://fredosaurus.com/notes-cpp/newdelete/50dynamalloc.html . There may be a problem in how you are populating the array with data from the file - we would need to see more code.
Not if you are using sizeof() to determine how many triangles to draw (or otherwise basing the number of triangles to render on the variable itself).
You should post the code for rendering the triangles.
Debug values for fSize and from where that number comes would not hurt.
L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
Hm, ok tnx guys. I'm posting here entire code, and do note, i'm a noob, so i'm probably doing many thigns wrong.
Also, just for info, i'm getting vSize and fSize from the txt file, where i "converter" obj file. I also tried to check the values with message box, and they are correct. So, for the moment, i put 36 as the fSize and vSize.(because if i use regular, static arrays with the size 36, it works)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DX 6 - working with meshes
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Set Mesh
/* Reads txt file, extract info about mesh and stores it into array */
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setMesh(string filename, CustomVertex* vertex)
{
int i = 0;
ifstream fin;
char input;
string s;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Get Number of Vertices
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getVertexCount(string filename)
{
ifstream fin;
char input;
int vCount;
string s;
fin.open("cube.txt");
fin.get(input);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Get Number of Vertices
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getFaceCount(string filename)
{
ifstream fin;
char input;
int vCount;
string s;
fin.open("cube.txt");
fin.get(input);