PDA

View Full Version : separate creating and drawing of objects



akiradesu
11-24-2015, 08:24 AM
Hi. I would like to create a class for each model to make things more clear, which looks like this:

struct vertex {
__glm::vec3 position;
__glm::vec3 normal;
};

class triangle {
public:
__triangle() {
____// initialise vertices and indices

____compute_normals();

____vao = vbo = vio = -1;

____// bind data to buffers
____populate();
__}
__void draw() {
____// bind vbo and call glDrawElements()
__}
private:
__void populate() {
____// generate buffers and bind to them ...
__}
__void compute_normals() {}
protected:
__std::vector<vertex> vertices;
__std::vector<unsigned int> indices;

__GLint vbo, vio, vao;
};


Q1:
Can I create multiple objects (triangles, cubes, etc.) and
bind their data to GL_ARRAY_BUFFER separately with their own OBOs? How?

Q2:
When rendering multiple objects, how to pass their vertices to vertex shader?
Do I need to create the same number of vertex variables in the shader file?
And glVertexAttribPointer() needs an index of the attribute which cannot be
determined at compile time. Does that mean I still needs some globals (shader program)
in draw()?

akiradesu
11-24-2015, 08:28 AM
with their own OBOs? How?

Typo, should be VBOs.

akiradesu
11-24-2015, 08:35 PM
Solved. You can bind any number of VBOs to GL_BUFFER_ARRAY. The strategy above works well:)