Jump to content
  • Advertisement
Sign in to follow this  
Zakwayda

OpenGL vector to gl*Pointer()

This topic is 5176 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

Quick question. Like most people I have various arrays that I create and send to OpenGL, such as: Vector3* m_verts; m_verts = new Vector3[m_numverts]; glVertexPointer(3, GL_FLOAT, VECTOR3_STRIDE, (float*)m_verts); delete [] m_verts; And so on. (Obviously not that code in that sequence, but those are the different things you would do with the array.) I have always assumed that it would be impossible to use std::vectors in this case because a) perhaps the internal vector memory isn't gauranteed to be contiguous and b) there's no easy way to access the internal data of the vector directly. So does anyone use std::vectors in cases like this? Is there a way to do it (safely, and without hacks)?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by jyk
I have always assumed that it would be impossible to use std::vectors in this case because a) perhaps the internal vector memory isn't gauranteed to be contiguous and


I'm most certain that the latest c++ standard i.e 2003 states that std::vector must be implementated with contigous memory, it wasn't the case before then all you could do was hope your implementation did it.

Quote:
Original post by jyk
b) there's no easy way to access the internal data of the vector directly.

So does anyone use std::vectors in cases like this? Is there a way to do it (safely, and without hacks)?


just take the address of the first element e.g.


#include <vector>

struct foo {/* ... */};

int main() {

std::vector<foo> f;

/* ...stuff... */

//later on...
foo* foo_ptr = &f[0]; // or this: foo* foo_ptr = &f.front(); is another way.

/* ...stuff... */

return 0;

}


[Edited by - snk_kid on October 8, 2004 8:27:15 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!