I have a problem giving my std::vector to another class. I put data into the std::vector and put it into a class called "Mesh". And the "Mesh" comes into a "Model".
// Store the vertices
std::vector<float> positionVertices;
positionVertices.push_back(-0.5f);
positionVertices.push_back(-0.5f);
positionVertices.push_back( 0.5f);
positionVertices.push_back(-0.5f);
positionVertices.push_back(-0.5f);
positionVertices.push_back( 0.5f);
// Put them into a mesh and the mesh into a model
Mesh mesh = Mesh(positionVertices);
Model model = Model(mesh);
In the model class, I take the position vertices of the mesh back and convert it into a float[]. But it seems like that, that the way I allocate the std::vector is wrong, because when checking the std::vector in the model class, it has a size of 0.
// Store the vertices
float* dataPtr = &data[0];
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(float), dataPtr, GL_STATIC_DRAW);
How can I bring the data correctly into the other classes?
I'm also unsure about the way the constructor for the mesh class works. Mesh.h:
// Mesh.h
class Mesh
{
public:
std::vector<float> positionVertices;
Mesh(std::vector<float>);
~Mesh();
};
Mesh.cpp:
// Mesh.cpp
Mesh::Mesh(std::vector<float> positionVertices) : positionVertices(Mesh::positionVertices)
{
}
Model.h:
// Model.h
class Model
{
public:
Mesh mesh;
unsigned int vertexArray;
unsigned int vertexCount;
Model(Mesh);
~Model();
void storeData(std::vector<float> data, const unsigned int index, const unsigned int size);
};
Model.cpp:
// Model.cpp
Model::Model(Mesh mesh) : mesh(Model::mesh)
{ ... }