Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Wavarian

glVertexPointer & Dynamic Arrays

This topic is 6151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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."

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!