Question: a short segment about Vertex Array.Thanks~~

I am embarassed with the follwoing problem. Can someone pick out the bug here. Thanks.
I have assigned this:
glVertexPointer(3, GL_FLOAT, 0, MeshPArray );
MeshPArray[i][3] stores the whole vertexes.
MeshStripIndex[i][j]] stores the index of each vertex in the triangle strips

///Why this works
///Why this wrong

[This message has been edited by foollove (edited 04-09-2003).]

Hi,everyone here,
sorry again.
Whether we can not use vertex array whose memory is allocated dynamicly.
Such as:
float **Mesh instead of
float Mesh[100][3].
In my program I found the traditional vertex array can not work if the vertex data is allocated by “new”.
Am I right?
Thanks a lot.

Did you remember to enable vertex arrays with glEnableClientState?

As with using vertex arrays with data allocated using ‘new’ I’ve never had any problems doing that, and I can’t see why it should be any different from using memory allocated in any other way!


The following doesn’t work:
float *Mesh;
unsigned int *MeshStripIndex;

Mesh = new float*[CtrlNumMeshNum];
Mesh[i] = new float[3];

MeshStripIndex = new unsigned int*[CtrlNum-1];
MeshStripIndex[i] = new unsigned int[2*(MeshNum+1)];

But if I define like this,it works,
float Mesh[CtrlNumMeshNum][3];
unsigned int MeshStripIndex[CtrlNum-1][2

Thank you for your attention.

You need to go and learn a bit of c++ I feel.

You are allocating an array of float pointers (Mesh = new float*[]) and most probably passing that array of pointers to Opengl.

You should be allocating your array using

float *Mesh;

Mesh = new float[CtrlNum * MeshNum * 3];

Or even better use typedef or class and create a custom type/class to hold your vertex data.

This is really, really basic c/c++ and is not really appropriate in this forum.

To rgpc:
Thanks a lot.
I tried float Mesh =new float[CtrlNumMeshNum3], it works.
But I wonder why the following dont work.
float *Mesh;—>Mesh[i][j]
Mesh = new float
Mesh[i] = new float[3];

Can someone tell me?

[This message has been edited by foollove (edited 04-10-2003).]

Well… what you were creating are multidimensional arrays. What that means is that you certainly can’t guarantee that all the data is in the same memory space.

For example: if you have a mesh of 30x30 vertices, you can’t guarantee that MeshIndex[1][0] comes right after MeshIndex[0][29]. Multidimensional arrays can be spread all over your memory space!

I already did. You are allocating an array of pointers and hanging your float[3]'s off that array. What you end up passing is not the array of floats that is expected, but you end up passing an array of pointers. They are two completely different things.

Thanks all of you.