Advertisement

glVertexPointer & Dynamic Arrays

Started by July 21, 2001 01:11 AM
4 comments, last by Wavarian 23 years, 7 months ago
Hey guys, is it possible to use dynamic arrays in the function call to glVertexPointer? - It seems that the answer is no since ive tried it.. What im forced to do is load all vertex data from an object into a static array and then load it - which is a pain & relatively slow. Yes im setting the sizes of the dynamic arrays at runtime when the program is first run. Just a simple question to those who have used dynamic arrays in the vertex array functions.. "You are just as irritating to me as an irrational term that accidentially creeps into your equation and cannot be factorized out."
What do you mean by dynamic arrays? Are you talking about pointer style arrays? They only truly dynamic arrays are based on the linked list type concept.
Advertisement
In delphi, we define dynamic arrays as:

var MyArray:Array of Array of Single;

and later in my code, i can set the size of this array by doing this:

SetLength(MyArray,4,3)

this sets MyArray to: MyArray[0..3,0..2] of Single

and a call to glVertexPointer doesnt work with it:

glVertexPointer(3,GL_FLOAT,0,@MyArray);

"You are just as irritating to me as an irrational term that accidentially creeps into your equation and cannot be factorized out."
Yep, you can use dynamic arrays with glVertexPointer().

When you call glVertexPointer() and specify your data, it only stores the pointer, all the vertex data is stored on the client side, ie in your apps memory space. This means that you can change the data in your array and the change will be reflected when you draw from that array with something like glDrawElements()

I''m not sure about Delphi, but in C++ dynamic arrays are done with the new operator eg:

float *fDynamicArray;

.
.
.

fDynamicArray = new float[NumberOfElements];

Now you can use the fDynamicArray like any normal array (up to the size you allocated for it, obviously)

Remember to call delete [] on any memory you allocate dynamically.

FatalXC
Hrmmm.. for the strangest reason, it works incorrectly with delphi''s dynamic arrays.. :/

"You are just as irritating to me as an irrational term that accidentially creeps into your equation and cannot be factorized out."
Did not the pascal like languages also store the length of the array? You should give a pointer to a memory block with the data. Something like this C code that gives you a pointer to the first element &myArray[0].

You must consult the delphi documentation about how dynamic arrays are implemented. It does not have to be the way you assume.

This topic is closed to new replies.

Advertisement