OpenMiner/source/states/GameState.cpp

65 lines
1.5 KiB
C++
Raw Normal View History

2014-12-15 16:47:30 +01:00
/*
* =====================================================================================
*
* Filename: GameState.cpp
*
2018-06-05 01:24:54 +02:00
* Description:
2014-12-15 16:47:30 +01:00
*
* Version: 1.0
* Created: 15/12/2014 03:51:55
* Revision: none
* Compiler: gcc
*
* Author: Quentin BAZIN, <quent42340@gmail.com>
2018-06-05 01:24:54 +02:00
* Company:
2014-12-15 16:47:30 +01:00
*
* =====================================================================================
*/
#define GLM_FORCE_RADIANS
#include <glm/gtc/matrix_transform.hpp>
#include "GameState.hpp"
2014-12-26 00:39:10 +01:00
GameState::GameState() : m_camera(Camera::getInstance()) {
2015-02-06 01:44:16 +01:00
m_shader.createProgram();
2018-06-05 01:24:54 +02:00
2015-02-06 01:44:16 +01:00
m_shader.addShader(GL_VERTEX_SHADER, "shaders/game.v.glsl");
m_shader.addShader(GL_FRAGMENT_SHADER, "shaders/color.f.glsl");
m_shader.addShader(GL_FRAGMENT_SHADER, "shaders/light.f.glsl");
m_shader.addShader(GL_FRAGMENT_SHADER, "shaders/fog.f.glsl");
m_shader.addShader(GL_FRAGMENT_SHADER, "shaders/game.f.glsl");
2018-06-05 01:24:54 +02:00
2015-02-06 01:44:16 +01:00
m_shader.linkProgram();
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
Shader::bind(&m_shader);
2018-06-05 01:24:54 +02:00
2014-12-26 00:39:10 +01:00
m_projectionMatrix = glm::perspective(45.0f, 640.0f / 480.0f, 0.1f, 1000.0f);
2014-12-18 07:02:48 +01:00
m_viewMatrix = m_camera.update();
2018-06-05 01:24:54 +02:00
2015-02-06 01:44:16 +01:00
m_shader.setUniform("u_projectionMatrix", m_projectionMatrix);
2018-06-05 01:24:54 +02:00
2014-12-18 07:02:48 +01:00
m_shader.setUniform("u_tex", 0);
2018-06-05 01:24:54 +02:00
2014-12-15 16:47:30 +01:00
Shader::bind(nullptr);
}
GameState::~GameState() {
}
void GameState::update() {
2014-12-18 07:02:48 +01:00
m_viewMatrix = m_camera.processInputs();
2014-12-15 16:47:30 +01:00
}
void GameState::draw() {
Shader::bind(&m_shader);
2018-06-05 01:24:54 +02:00
2014-12-29 02:57:29 +01:00
m_shader.setUniform("u_viewMatrix", m_viewMatrix);
2018-06-05 01:24:54 +02:00
2014-12-29 02:57:29 +01:00
//m_skybox.draw(m_shader);
2018-06-05 01:24:54 +02:00
2014-12-29 03:14:09 +01:00
m_world.draw(m_shader, m_projectionMatrix, m_viewMatrix);
2018-06-05 01:24:54 +02:00
2014-12-15 16:47:30 +01:00
Shader::bind(nullptr);
}