View Full Version : Question: a short segment about Vertex Array.Thanks~~

04-09-2003, 08:39 PM
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).]

04-09-2003, 10:47 PM
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.

04-09-2003, 11:56 PM
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!


04-10-2003, 03:02 AM
The following doesn't work:
float *Mesh;
unsigned int *MeshStripIndex;

Mesh = new float*[CtrlNum*MeshNum];
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[CtrlNum*MeshNum][3];
unsigned int MeshStripIndex[CtrlNum-1][2*(MeshNum+1)];

Thank you for your attention. http://www.opengl.org/discussion_boards/ubb/smile.gif

04-10-2003, 04:35 AM
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.

04-10-2003, 05:09 AM
To rgpc:
Thanks a lot.
I tried float *Mesh =new float[CtrlNum*MeshNum*3], it works.
But I wonder why the following dont work.
float **Mesh;--->Mesh[i][j]
Mesh = new float*[CtrlNum*MeshNum];
Mesh[i] = new float[3];

Can someone tell me?

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

04-10-2003, 05:31 AM
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!

04-10-2003, 05:45 AM
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.

04-10-2003, 05:46 PM
Thanks all of you. http://www.opengl.org/discussion_boards/ubb/smile.gif