PDA

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



foollove
04-09-2003, 09: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

for(i=0;i<TotalStripNum;i++)
{
glBegin(GL_TRIANGLE_STRIP);
for(j=0;j<MeshStripLength[i];j++)
{
///Why this works
glVertex3fv(MeshPArray[MeshStripIndex[i][j]]);
///Why this wrong
//glArrayElement(MeshStripIndex[i][j]);
}
glEnd();
}

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

foollove
04-09-2003, 11: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.

abrodersen
04-10-2003, 12:56 AM
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!

Anders

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


Mesh = new float*[CtrlNum*MeshNum];
for(i=0;i<CtrlNum*MeshNum;i++)
Mesh[i] = new float[3];

MeshStripIndex = new unsigned int*[CtrlNum-1];
for(i=0;i<CtrlNum-1;i++)
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

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

foollove
04-10-2003, 06: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];
for(i=0;i<CtrlNum*MeshNum;i++)
Mesh[i] = new float[3];

Why?
Can someone tell me?

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

Stebet
04-10-2003, 06: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!

rgpc
04-10-2003, 06: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.

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