lighting setup
This commit is contained in:
parent
ccc1c76762
commit
16b674efc1
4 changed files with 85 additions and 90 deletions
|
|
@ -5,9 +5,8 @@
|
|||
|
||||
struct Vertex {
|
||||
float x, y, z; // position
|
||||
float r, g, b; // color
|
||||
float nX, nY, zY; // normal
|
||||
float u, v; // texcoord
|
||||
// = 8 floats = 32 bytes
|
||||
};
|
||||
|
||||
class Mesh
|
||||
|
|
@ -27,10 +26,6 @@ public:
|
|||
glGenVertexArrays(1, &VAO);
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenBuffers(1, &EBO);
|
||||
|
||||
std::cout << VAO << std::endl;
|
||||
std::cout << VBO << std::endl;
|
||||
std::cout << EBO << std::endl;
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
|
|
@ -40,13 +35,15 @@ public:
|
|||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW);
|
||||
|
||||
// position attribute
|
||||
// Position
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, x));
|
||||
glEnableVertexAttribArray(0);
|
||||
// color attribute
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, r));
|
||||
|
||||
// Normals
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, nX));
|
||||
glEnableVertexAttribArray(1);
|
||||
// texture coord attribute
|
||||
|
||||
// Texcoords
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, u));
|
||||
glEnableVertexAttribArray(2);
|
||||
}
|
||||
|
|
@ -58,9 +55,9 @@ public:
|
|||
|
||||
void Draw() const
|
||||
{
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
//glBindVertexArray(VAO);
|
||||
//glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(indexCount),
|
||||
// GL_UNSIGNED_INT, nullptr);
|
||||
//glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
glBindVertexArray(VAO);
|
||||
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(indexCount),
|
||||
GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue