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
|
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
|
ugine3d.vcxproj -> C:\Users\rabil\git\utad-programacion3d\project\x64\Debug\Practica3D.exe
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "../lib/glew/GL/glew.h"
|
#include "../lib/glew/GL/glew.h"
|
||||||
#include "../lib/glfw/glfw3.h"
|
#include "../lib/glfw/glfw3.h"
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
|
|
||||||
Buffer::Buffer(const std::vector<Vertex>& vertices, const std::vector<uint16_t>& indices)
|
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_);
|
glGenVertexArrays(1, &vao_);
|
||||||
glGenBuffers(1, &vbo_);
|
glGenBuffers(1, &vbo_);
|
||||||
|
|||||||
31
src/main.cpp
31
src/main.cpp
@@ -56,9 +56,9 @@ int main() {
|
|||||||
|
|
||||||
// Logic
|
// Logic
|
||||||
std::vector<Vertex> vertices = {
|
std::vector<Vertex> vertices = {
|
||||||
{{-0.5f, -0.5f, 0.0f}},
|
{{0.0f, 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}},
|
||||||
{{0.5f, -0.5f, 0.0f}},
|
{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}},
|
||||||
{{0.0f, 0.5f, 0.0f}}
|
{{0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}}
|
||||||
};
|
};
|
||||||
std::vector<uint16_t> indices = { 0, 1, 2 };
|
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 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
|
// main loop
|
||||||
double angle = 0;
|
double angle = 0.0;
|
||||||
double lastTime = glfwGetTime();
|
double lastTime = glfwGetTime();
|
||||||
while (!glfwWindowShouldClose(win) && !glfwGetKey(win, GLFW_KEY_ESCAPE)) {
|
while (!glfwWindowShouldClose(win) && !glfwGetKey(win, GLFW_KEY_ESCAPE)) {
|
||||||
// Delta
|
// Delta
|
||||||
double delta_time = glfwGetTime() - lastTime;
|
double delta_time = glfwGetTime() - lastTime;
|
||||||
|
lastTime = glfwGetTime();
|
||||||
|
|
||||||
// Reset window
|
// Reset window
|
||||||
int screenWidth, screenHeight;
|
int screenWidth, screenHeight;
|
||||||
glfwGetWindowSize(win, &screenWidth, &screenHeight);
|
glfwGetWindowSize(win, &screenWidth, &screenHeight);
|
||||||
glViewport(0, 0, 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);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
shader.Use();
|
shader.Use();
|
||||||
@@ -91,21 +93,22 @@ int main() {
|
|||||||
// Logic
|
// Logic
|
||||||
angle += 32.0 * delta_time;
|
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) {
|
||||||
model = glm::rotate(model, glm::radians(static_cast<float>(angle)), glm::vec3(0, 1, 0));
|
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;
|
glm::mat4 mvp = projection * view * model;
|
||||||
|
|
||||||
Shader::setMat4(shader.getLocation("mvp"), mvp);
|
Shader::setMat4(shader.getLocation("mvp"), mvp);
|
||||||
|
|
||||||
buffer.Draw(shader);
|
buffer.Draw(shader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Refresh screen
|
// Refresh screen
|
||||||
glfwSwapBuffers(win);
|
glfwSwapBuffers(win);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
// Delta
|
|
||||||
lastTime = glfwGetTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown
|
// 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)
|
uint32_t Shader::CompileShader(uint32_t type, const std::string& source_path)
|
||||||
{
|
{
|
||||||
std::string source = ReadShaderFile(source_path);
|
std::string source = ReadShaderFile(source_path);
|
||||||
|
//std::cout << "SHADER FILE: " << source << "\n";
|
||||||
if (source.empty())
|
if (source.empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user