I'm writting opengl code on c++ and I create an own class of object. But for some reason it doesn't rendering. I think problem in vector, which I use as coordinates of vertex. And i 100% sure problem is not in shaders.
Here is a code:
source.cpp
//other shader code
GLobject obj(Points);
obj.SetBufferData(0, GL_ARRAY_BUFFER, 2, GL_FALSE);
glClearColor(0.3, 0.5, 0.7, 1);
while (!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(ShaderProgram);
obj.Draw(0, GL_ARRAY_BUFFER, GL_TRIANGLES, 2);
}
}
GLobject.cpp
#include "GLobject.h"
GLobject::GLobject(float points[])
{
glGenVertexArrays(1, &this->VAO);
glGenBuffers(1, &this->VBO);
for (int i = 0; i < sizeof(points); i++)
this->points.push_back(points[i]);
p = this->points.data();
}
GLobject::~GLobject()
{
}
void GLobject::SetBufferData(int index, GLenum btype, int size, GLenum normalize)
{
glBindVertexArray(this->VAO);
glBindBuffer(btype, this->VBO);
glVertexAttribPointer(index, size, GL_FLOAT, normalize, size*sizeof(float), (void*)0);
glBufferData(btype, sizeof(p), p, GL_STATIC_DRAW);
glBindVertexArray(0);
glBindBuffer(btype, 0);
}
void GLobject::Draw(int index, GLenum btype, GLenum dtype, int size) {
glBindVertexArray(this->VAO);
glBindBuffer(btype, this->VBO);
glEnableVertexAttribArray(index);
glDrawArrays(dtype, 0, sizeof(p) / size);
}
I'm be very happy if you help me.
P.S. I'm from Ukraine so my English may be bad.