additional cleanup and preperations
This commit is contained in:
parent
e874dae218
commit
8ffca1f4d2
|
@ -61,6 +61,10 @@ void ProcessInput(GLFWwindow* window)
|
|||
cam.ProcessKeyboard(MovementDirection::LEFT, deltaTime);
|
||||
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
cam.ProcessKeyboard(MovementDirection::RIGHT, deltaTime);
|
||||
if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
cam.ProcessKeyboard(MovementDirection::UP, deltaTime);
|
||||
if(glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS)
|
||||
cam.ProcessKeyboard(MovementDirection::DOWN, deltaTime);
|
||||
}
|
||||
|
||||
void OnMouseMove(GLFWwindow* window, double xpos, double ypos)
|
||||
|
@ -142,28 +146,6 @@ int main()
|
|||
vec3(-1.3f, 1.0f, -1.5f)
|
||||
};
|
||||
|
||||
// VBO == all vertices; EBO == connection of vertices (faces) and is optional, although it is a bit more efficient than using VBOs, since it reuses vertices;
|
||||
// VAO == collection of VBOs/EBOs used for rendering
|
||||
GLuint vertexBufferObject, elementBufferObject, vertexArrayObject;
|
||||
glGenVertexArrays(1, &vertexArrayObject);
|
||||
glGenBuffers(1, &vertexBufferObject);
|
||||
glGenBuffers(1, &elementBufferObject);
|
||||
|
||||
glBindVertexArray(vertexArrayObject);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_container), vertices_container, GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferObject);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(faces), faces, GL_STATIC_DRAW);
|
||||
|
||||
// position attribute
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
// uv-coordinates (or more general the second vertex attribute which can be anything not just uv-coordinates)
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
glEnableVertexAttribArray(1);
|
||||
// I could unbind the VAO, but this is usually not needed because when creating a new VAO we need to bind that to change it anyway, so there shouldn't be a problem
|
||||
|
||||
std::string vertexPath = "shaders/default/default.vert";
|
||||
std::string fragmentPath = "shaders/default/default.frag";
|
||||
|
@ -211,10 +193,6 @@ int main()
|
|||
glfwPollEvents();
|
||||
}
|
||||
|
||||
// optional, as we are at the end of the program.
|
||||
glDeleteVertexArrays(1, &vertexArrayObject);
|
||||
glDeleteBuffers(1, &elementBufferObject);
|
||||
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
|
@ -51,6 +51,11 @@ namespace Nebulix
|
|||
{
|
||||
Init();
|
||||
}
|
||||
~GameObject()
|
||||
{
|
||||
glDeleteVertexArrays(1, &vertexArray);
|
||||
glDeleteBuffers(1, &vertexBuffer);
|
||||
}
|
||||
|
||||
// NOTE: This method will only call "Shader.Use()" but will not set any properties.
|
||||
// This is because I do not know the names and values of the properties. Most likely this will be possible after learning about materials
|
||||
|
@ -75,6 +80,9 @@ namespace Nebulix
|
|||
private:
|
||||
std::vector<float> vertices;
|
||||
|
||||
// VBO == all vertices (Vertex Buffer Object)
|
||||
// EBO == connection of vertices (faces) and is optional, although it is a bit more efficient than using VBOs, since it reuses vertices; (Element Buffer Object)
|
||||
// VAO == collection of VBOs/EBOs used for rendering (Vertex Array Object)
|
||||
GLuint vertexBuffer, vertexArray;
|
||||
std::vector<VertexAttribute> vertexAttributes;
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@ enum class MovementDirection
|
|||
FORWARD,
|
||||
BACKWARD,
|
||||
LEFT,
|
||||
RIGHT
|
||||
RIGHT,
|
||||
UP,
|
||||
DOWN
|
||||
};
|
||||
|
||||
// Default values
|
||||
|
@ -59,6 +61,10 @@ public:
|
|||
Position -= Right * velocity;
|
||||
if (direction == MovementDirection::RIGHT)
|
||||
Position += Right * velocity;
|
||||
if (direction == MovementDirection::UP)
|
||||
Position += Up * velocity;
|
||||
if (direction == MovementDirection::DOWN)
|
||||
Position -= Up * velocity;
|
||||
}
|
||||
|
||||
// processes input received from a mouse input system. Expects the offset value in both the x and y direction.
|
||||
|
|
Loading…
Reference in New Issue
Block a user