Yet another question about Vertex Arrays...
How would I allocate the memory for the vertices?
Like this:
Vertex = new float[numVertex * numVertex * 3];
or this:
Vertex = new float*[numVertex * numVertex];
for (i = 0; i < numVertex * numVertex * 3; i++)
Vertex = new float[3];
What dimensions is the array supposed to be?
Like this:
Vertex = new float[numVertex * numVertex * 3];
Then, you use it like this:
int vertexNum;
float x;
float y;
float z;
...
Vertex[(3*vertexNum) ] = x;
Vertex[(3*vertexNum) + 1] = y;
Vertex[(3*vertexNum) + 2] = z;
...
I think
Vertex = new float[numVertex * numVertex * 3];
Then, you use it like this:
int vertexNum;
float x;
float y;
float z;
...
Vertex[(3*vertexNum) ] = x;
Vertex[(3*vertexNum) + 1] = y;
Vertex[(3*vertexNum) + 2] = z;
...
I think

PM Times change...
Excuse my poor english!
i think the best way to do that is like this:
struct Vertex
{
float x, y, z;
};
Then make a linked list of the struct. Im not sure how to define the list.
struct Vertex
{
float x, y, z;
};
Then make a linked list of the struct. Im not sure how to define the list.
But using a linked list is much slower than an array. And I am going to use it with glVertexPointer(), to use Vertex Arrays. So I don't think that I could do it that way...
But what I really want to know, is what kind of array glVertexPointer() takes as a parameter. A 2-dimensional one, or just a single-dimension array...? If I am using a one-dimensional array, and if I set the first parameter (the first parameter is size...) in glVertexPointer() to 3, do I need to change the stride?? I'm sorry if I'm not making sense...
I hope someone can help.
[edited by - James Trotter on February 21, 2003 4:44:23 PM]
But what I really want to know, is what kind of array glVertexPointer() takes as a parameter. A 2-dimensional one, or just a single-dimension array...? If I am using a one-dimensional array, and if I set the first parameter (the first parameter is size...) in glVertexPointer() to 3, do I need to change the stride?? I'm sorry if I'm not making sense...
I hope someone can help.
[edited by - James Trotter on February 21, 2003 4:44:23 PM]
I`m using something like this and works:
typedef struct{
float x,y,z;
}Vector3;
typedef struct{
vector Vert;
.....................
Vector3 *V;
}MODEL3DOBJECT;//this my personal 3d model file system....
void LoadTheModel()
{
//Loading all the stuff........in the Vert
M.V=new Vector3[numberOfVertices];
for(int y=0;yM.V[y]=M.Vert[y];
.....................
}
void Draw(){
//and just call it
glVertexPointer(3,GL_FLOAT,0,M.V);
}
/*Note:If you try to put directly the STL Vector it will probably make 1 variable from all the vector and that`s why I use the pointers...*/
typedef struct{
float x,y,z;
}Vector3;
typedef struct{
vector
.....................
Vector3 *V;
}MODEL3DOBJECT;//this my personal 3d model file system....
void LoadTheModel()
{
//Loading all the stuff........in the Vert
M.V=new Vector3[numberOfVertices];
for(int y=0;y
.....................
}
void Draw(){
//and just call it
glVertexPointer(3,GL_FLOAT,0,M.V);
}
/*Note:If you try to put directly the STL Vector it will probably make 1 variable from all the vector and that`s why I use the pointers...*/
Relative Games - My apps
you can''t use a linked list for vertex arrays, simple because the elements in a linked list are disjoint in memory. They arn''t continuous.
A vector would be a good bet for a vertex array system. You won''t have to worry about memory managment if you use one of those. And yes, using a stracture/class/template for your vertex types (interleaved) is the best bet for easy managment of vertex array/buffer data.
use of vertex arrays themselves aren''t what makes modern 3d cards ultra-efficient, it''s use of ''vertex buffers'' where vertex arrays are stored on the video cards own memory, or direclty in agp memory. This way you get a huge reductiuon in the cpu''s workload and the video card knows that the data is as is, unlike a pointer to system memory which could change at any moment. Hence things can be optimized enormously.
Extensions for this is nvidias VERTEX_ARRAY_RANGE or ati''s VERTEX_ARRAY_OBJECT, or soon to come, and about time, ARB_VERTEX_BUFFER_OBJECT.
| - Project-X - my mega project.. yup, still cracking along
- | - adDeath - an ad blocker I made - | - email me - |
A vector would be a good bet for a vertex array system. You won''t have to worry about memory managment if you use one of those. And yes, using a stracture/class/template for your vertex types (interleaved) is the best bet for easy managment of vertex array/buffer data.
use of vertex arrays themselves aren''t what makes modern 3d cards ultra-efficient, it''s use of ''vertex buffers'' where vertex arrays are stored on the video cards own memory, or direclty in agp memory. This way you get a huge reductiuon in the cpu''s workload and the video card knows that the data is as is, unlike a pointer to system memory which could change at any moment. Hence things can be optimized enormously.
Extensions for this is nvidias VERTEX_ARRAY_RANGE or ati''s VERTEX_ARRAY_OBJECT, or soon to come, and about time, ARB_VERTEX_BUFFER_OBJECT.
| - Project-X - my mega project.. yup, still cracking along

This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement