feat: practica1 done
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,2 @@
|
||||
main.cpp
|
||||
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
ugine3d.vcxproj -> C:\Users\rabil\git\utad-programacion3d\project\x64\Debug\Practica3D.exe
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "buffer.h"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include "../lib/glew/GL/glew.h"
|
||||
#include "../lib/glfw/glfw3.h"
|
||||
@@ -9,7 +10,7 @@
|
||||
|
||||
Buffer::Buffer(const std::vector<Vertex>& vertices, const std::vector<uint16_t>& indices)
|
||||
{
|
||||
index_count_ = indices.size();
|
||||
index_count_ = static_cast<GLsizei>(indices.size());
|
||||
|
||||
glGenVertexArrays(1, &vao_);
|
||||
glGenBuffers(1, &vbo_);
|
||||
|
||||
23
src/main.cpp
23
src/main.cpp
@@ -56,9 +56,9 @@ int main() {
|
||||
|
||||
// Logic
|
||||
std::vector<Vertex> vertices = {
|
||||
{{-0.5f, -0.5f, 0.0f}},
|
||||
{{0.5f, -0.5f, 0.0f}},
|
||||
{{0.0f, 0.5f, 0.0f}}
|
||||
{{0.0f, 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}},
|
||||
{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}},
|
||||
{{0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}}
|
||||
};
|
||||
std::vector<uint16_t> indices = { 0, 1, 2 };
|
||||
|
||||
@@ -69,21 +69,23 @@ int main() {
|
||||
}
|
||||
|
||||
glm::mat4 projection = glm::perspective(glm::radians(45.0f), static_cast<float>(SCREEN_WIDTH) / SCREEN_HEIGHT, 0.1f, 100.0f);
|
||||
glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(0, 0, 6));
|
||||
//glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(0, 0, 6));
|
||||
glm::mat4 view = glm::lookAt(glm::vec3(0, 0, 6), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
|
||||
|
||||
// main loop
|
||||
double angle = 0;
|
||||
double angle = 0.0;
|
||||
double lastTime = glfwGetTime();
|
||||
while (!glfwWindowShouldClose(win) && !glfwGetKey(win, GLFW_KEY_ESCAPE)) {
|
||||
// Delta
|
||||
double delta_time = glfwGetTime() - lastTime;
|
||||
lastTime = glfwGetTime();
|
||||
|
||||
// Reset window
|
||||
int screenWidth, screenHeight;
|
||||
glfwGetWindowSize(win, &screenWidth, &screenHeight);
|
||||
glViewport(0, 0, screenWidth, screenHeight);
|
||||
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
shader.Use();
|
||||
@@ -91,7 +93,9 @@ int main() {
|
||||
// Logic
|
||||
angle += 32.0 * delta_time;
|
||||
|
||||
glm::mat4 model = glm::translate(glm::mat4(1.0), glm::vec3(-3.0f + 0.0f * 3.0f, 0.0f, -0.0f * 3.0f));
|
||||
for (int row = 0; row < 3; ++row) {
|
||||
for (int col = 0; col < 3; ++col) {
|
||||
glm::mat4 model = glm::translate(glm::mat4(1.0), glm::vec3(-3.0f + static_cast<float>(col) * 3.0f, 0.0f, static_cast<float>(-row) * 3.0f));
|
||||
model = glm::rotate(model, glm::radians(static_cast<float>(angle)), glm::vec3(0, 1, 0));
|
||||
|
||||
glm::mat4 mvp = projection * view * model;
|
||||
@@ -99,13 +103,12 @@ int main() {
|
||||
Shader::setMat4(shader.getLocation("mvp"), mvp);
|
||||
|
||||
buffer.Draw(shader);
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh screen
|
||||
glfwSwapBuffers(win);
|
||||
glfwPollEvents();
|
||||
|
||||
// Delta
|
||||
lastTime = glfwGetTime();
|
||||
}
|
||||
|
||||
// Shutdown
|
||||
|
||||
@@ -112,6 +112,7 @@ std::string Shader::ReadShaderFile(const std::string& filename)
|
||||
uint32_t Shader::CompileShader(uint32_t type, const std::string& source_path)
|
||||
{
|
||||
std::string source = ReadShaderFile(source_path);
|
||||
//std::cout << "SHADER FILE: " << source << "\n";
|
||||
if (source.empty())
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user