prepared for obj stuff

This commit is contained in:
Your Name 2018-12-17 14:22:23 +01:00
parent 170ff0e456
commit 06d489e0fe
7 changed files with 128 additions and 11 deletions

View File

@ -43,6 +43,7 @@ include_directories(
set(SRCS
"src/AssetManager.cpp"
"src/Camera.cpp"
"src/Logger.cpp"
"src/Main.cpp"
"src/Model.cpp"

View File

@ -1,9 +1,9 @@
#version 330 core
layout(location = 0) in vec3 vert_pos;
uniform vec3 col;
/*uniform mat4 mvp;*/
uniform mat4 mvp;
out vec3 frag_col;
void main() {
gl_Position = /*mvp * */vec4(vert_pos, 1);
gl_Position = mvp * vec4(vert_pos, 1);
frag_col = col;
}

View File

@ -25,7 +25,6 @@
class AssetManager {
public:
AssetManager();
/*void loadOBJ(const std::string &path,
const std::string &name);*/

33
src/Camera.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net> All rights reserved.
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "Camera.hpp"
#include <iostream>
#include <cmath>
Camera::Camera() : pos(0.0f, 0.0f, 0.0f),
yaw(45.0f), angle(45.0f), dist(5.0f) { }

46
src/Camera.hpp Normal file
View File

@ -0,0 +1,46 @@
/*
* Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net> All rights reserved.
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#pragma once
#include <GL/gl.h>
#include <tuple>
#include <glm/gtc/matrix_transform.hpp>
class Camera {
public:
Camera();
inline glm::vec3 get_pos() {
return pos;
}
inline void setPosition(glm::vec3 _pos) {
this->pos = _pos;
}
private:
glm::vec3 pos;
float yaw;
float angle;
float dist; // distance from origin
};

View File

@ -65,9 +65,24 @@ System::System() : running(true) {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
shader = std::make_unique<Shader>(
/*shader = std::make_unique<Shader>(
"../assets/shaders/vertex_shader.glsl",
"../assets/shaders/fragment_shader.glsl");
"../assets/shaders/fragment_shader.glsl");*/
shaders.insert({"default", Shader(
"../assets/shaders/vertex_shader.glsl",
"../assets/shaders/fragment_shader.glsl")});
matrix_id = glGetUniformLocation(
shaders.at("default").getId(),
"mvp");
asset_mngr.loadModel(
"../assets/models/board.dae",
"board");
asset_mngr.loadModel(
"../assets/models/cube.dae",
"cube");
asset_mngr.loadModel(
"../assets/models/sphere.dae",
"sphere");
}
System::~System() {
@ -79,12 +94,33 @@ System::~System() {
void System::run() {
unsigned int lastTime = SDL_GetTicks();
cam.setPosition(glm::vec3(4,4,4));
while(running)
{
syncInputs();
glClear(GL_COLOR_BUFFER_BIT bitor GL_DEPTH_BUFFER_BIT);
shader->use();
shaders.at("default").use();
glm::mat4 mvp;
{
glm::mat4 proj = glm::perspective(glm::radians(45.0f),
static_cast<float>(WINDOW_WIDTH) / static_cast<float>(WINDOW_HEIGHT),
0.1f, 100.0f);
glm::mat4 view = glm::lookAt(
cam.get_pos(), // camera position
glm::vec3(0,0,0), // where the camera is looking
glm::vec3(0,1,0) // which way is vertically up
);
glm::mat4 mod = glm::mat4(1.0f); // identity matrix, object is at origin
mvp = proj * view * mod;
}
glUniformMatrix4fv(matrix_id, 1, GL_FALSE, &mvp[0][0]);
asset_mngr.getModel("board")->setColor(1,0,0);
asset_mngr.getModel("board")->draw(shaders.at("default"));
SDL_GL_SwapWindow(window);

View File

@ -20,12 +20,13 @@
#include "Logger.hpp"
#include "Shader.hpp"
#include "AssetManager.hpp"
#include <SDL2/SDL.h>
#include <memory>
#include <map>
#include <GL/glew.h>
#include <GL/gl.h>
#include "Camera.hpp"
class System {
public:
System();
@ -36,10 +37,11 @@ public:
private:
void syncInputs();
AssetManager asset_mngr;
SDL_Window *window;
SDL_GLContext glcontext;
std::unique_ptr<Shader> shader;
std::map<std::string, Shader> shaders;
Camera cam;
bool running;
GLuint matrix_id;
};