Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realize Cube and change access rights from privat to protected in Shape #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 83 additions & 7 deletions Shape3D/Shape3D_app/Shapes/Cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,92 @@ class Cube : public Shape
void Draw() override;

private:
float* vertices;
UINT VBO;
UINT VAO;
static std::unique_ptr<float> vertices;
static UINT VBO;
static UINT VAO;
static UINT countOfObjects = 0;
};

Cube::Cube()
Cube::Cube() :Shape()
{
}
if (!static_cast<bool>(vertices))
{
vertices = std::make_unique<float[]>(108);
vertices =
{
-0.5f; 0.5f; -0.5f;
0.5f; 0.5f; 0.5f;
-0.5f; 0.5f; 0.5f;
-0.5f; 0.5f; -0.5f;
0.5f; 0.5f; 0.5f;
0.5f; 0.5f; -0.5f;

0.5f; 0.5f; -0.5f;
0.5f; -0.5f; 0.5f;
0.5f; 0.5f; 0.5f;
0.5f; 0.5f; -0.5f;
0.5f; -0.5f; 0.5f;
0.5f; -0.5f; -0.5f;

-0.5f; 0.5f; 0.5f;
0.5f; -0.5f; 0.5f;
-0.5f; -0.5f; 0.5f;
-0.5f; 0.5f; 0.5f;
0.5f; -0.5f; 0.5f;
0.5f; 0.5f; 0.5f;

-0.5f; -0.5f; -0.5f;
-0.5f; 0.5f; 0.5f;
-0.5f; 0.5f; -0.5f;
-0.5f; -0.5f; -0.5f;
-0.5f; 0.5f; 0.5f;
-0.5f; -0.5f; 0.5f;

-0.5f; -0.5f; -0.5f;
0.5f; 0.5f; -0.5f;
-0.5f; 0.5f; -0.5f;
-0.5f; -0.5f; -0.5f;
0.5f; 0.5f; -0.5f;
0.5f; -0.5f; -0.5f;

0.5f; -0.5f; -0.5f;
-0.5f; -0.5f; 0.5f;
-0.5f; -0.5f; -0.5f;
0.5f; -0.5f; -0.5f;
-0.5f; -0.5f; 0.5f;
0.5f; -0.5f; 0.5f;
};
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices*), vertices*, GL_STATIC_DRAW);
}
countOfObjects++;
};

Cube::~Cube()
{
delete[] vertices;
}
countOfObjects--;
if (countOfObjects == 0)
{
std::get_deleter()(vertices);
}
}

void Cube::Draw()
{
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glScaled(this->scale, this->scale; this->scale);
glGenBuffers(1, &Cube::VBO);
glBindBuffer(GL_ARRAY_BUFFER, Cube::VBO);
glBufferData(GL_ARRAY_BUFFER, 432, Cube::vertices*, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, Cube::VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, 36);
glPopMatrix();
glEnableClientState(GL_VERTEX_ARRAY);
}
2 changes: 1 addition & 1 deletion Shape3D/Shape3D_app/Shapes/Shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Shape
void Move(glm::vec3);
void ChangeColor(glm::vec3);
void ChangeSize(float);
private:
protected:
glm::vec3 pos;
glm::vec3 color;
float scale;
Expand Down