Creating a model class

I’m trying to create a model class which would carry one VAO and 2 VBOs, but I’m not quite sure if it should have its vertices data saved for later usage. Something like for shape changing or idk :dejection:
By the way, how do I pass vertices as an argument? In my code its not working.
Here is my code:

	class LEOPModel {

		GLuint VAO_;
		GLuint VBO1, VBO2;

	public:

		LEOPModel() {

			glGenVertexArrays(1, &VAO_);

		}

		void insertVBO(GLfloat *vertices, GLfloat *vertices_2) {

			glGenBuffers(1, &VBO1);
			glGenBuffers(1, &VBO2);

			glBindVertexArray(VAO_);

			glBindBuffer(GL_ARRAY_BUFFER, VBO1);
			glEnableVertexAttribArray(0);
			glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *)0);
			glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
			//
			glBindBuffer(GL_ARRAY_BUFFER, VBO2);
			glEnableVertexAttribArray(1);
			glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *)0);
			glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_2), vertices_2, GL_STATIC_DRAW);

			glBindVertexArray(0);

		}

		void draw() {
			
			glBindVertexArray(VAO_);

			glDrawArrays(GL_TRIANGLES, 0, 6);

			glBindVertexArray(0);

		}

		GLuint getVBO(int at) {

			return VBO1;
		}

	};

thanks.

Applying the [var]sizeof[/var] operator to a pointer returns the size of the pointer (typically 4 or 8), not the data it points to. You’ll need to pass the array length as a parameter, or use a std::vector.

But it’s not working.


	le_opengl::LEOPModel model;
	model.insertVBO(colors_, sizeof(colors_), shape_, sizeof(shape_));

void insertVBO(GLfloat *vertices, int size, GLfloat *vertices_2, int size_2) {

			glGenBuffers(1, &VBO1);
			glGenBuffers(1, &VBO2);

			glBindVertexArray(VAO_);

			glBindBuffer(GL_ARRAY_BUFFER, VBO1);
			glEnableVertexAttribArray(0);
			glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *)0);
			glBufferData(GL_ARRAY_BUFFER, size, &vertices, GL_STATIC_DRAW);
			//
			glBindBuffer(GL_ARRAY_BUFFER, VBO2);
			glEnableVertexAttribArray(1);
			glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *)0);
			glBufferData(GL_ARRAY_BUFFER, size_2, vertices_2, GL_STATIC_DRAW);

			glBindVertexArray(0);

		}

[QUOTE=Cofyka;1290433]But it’s not working.


	le_opengl::LEOPModel model;
	model.insertVBO(colors_, sizeof(colors_), shape_, sizeof(shape_));

[/QUOTE]
What are colors_ and shape_?

Static variables.

GLfloat shape_[3 * 6]{

	-0.5f, 0.5f, 0.0f,
	0.5f, -0.5f, 0.0f,
	-0.5f, -0.5f, 0.0f,

	0.5f, 0.5f, 0.0f,
	0.5f, -0.5f, 0.0f,
	-0.5f, 0.5f, 0.0f

};

GLfloat colors_[3 * 6]{

	0.5f, 0.0f, 0.0f,
	0.0f, 0.0f, 0.0f,
	0.0f, 0.0f, 0.0f,

	1.0f, 0.0f, 0.0f,
	0.0f, 0.0f, 0.0f,
	0.5f, 0.0f, 0.0f

};

Another issue which I missed last time:

The “&” shouldn’t be there; you want the value of the pointer, not its address. For an array, it doesn’t matter (an array used as a value “decays” to a pointer to its first element); for a pointer, it matters.

The second call is correct:

I noticed that after but still results are the same.