Commit cae11abe authored by Håkon Berg Borhaug's avatar Håkon Berg Borhaug
Browse files

Final commit

parent edb8bf1a
......@@ -22,6 +22,7 @@ bool keyPressed[30];
int mousePosX, mousePosY;
float moveX, moveY;
// Upgrade variables
int upgradeCoolDown = 100;
int timeSinceUpgrade = 0;
......@@ -153,14 +154,15 @@ void display()
timeSinceUpgrade++;
if(keyPressed[KEY_ID_W]==true) gm->getCam()->moveForward();
if(keyPressed[KEY_ID_A]==true) gm->getCam()->moveLeft();
if(keyPressed[KEY_ID_D]==true) gm->getCam()->moveRight();
if(keyPressed[KEY_ID_S]==true) gm->getCam()->moveBackward();
if(keyPressed[KEY_ID_SPACE]==true) gm->getCam()->moveUp();
if(keyPressed[KEY_ID_C]==true) gm->getCam()->moveDown();
if(keyPressed[KEY_ID_H]==true) gm->getCam()->rotateLeft();
if(keyPressed[KEY_ID_J]==true) gm->getCam()->rotateRight();
/* Debug controls */
// if(keyPressed[KEY_ID_W]==true) gm->getCam()->moveForward();
// if(keyPressed[KEY_ID_A]==true) gm->getCam()->moveLeft();
// if(keyPressed[KEY_ID_D]==true) gm->getCam()->moveRight();
// if(keyPressed[KEY_ID_S]==true) gm->getCam()->moveBackward();
// if(keyPressed[KEY_ID_SPACE]==true) gm->getCam()->moveUp();
// if(keyPressed[KEY_ID_C]==true) gm->getCam()->moveDown();
// if(keyPressed[KEY_ID_H]==true) gm->getCam()->rotateLeft();
// if(keyPressed[KEY_ID_J]==true) gm->getCam()->rotateRight();
if(keyPressed[KEY_ID_O]==true) gm->getCharacter()->moveLeft();
if(keyPressed[KEY_ID_P]==true) gm->getCharacter()->moveRight();
if(keyPressed[KEY_ID_U]==true) {
......
......@@ -15,7 +15,7 @@
#include "../../glm-master/glm/glm.hpp"
// 4 points with 2D position and 2D texture position
#define BB_POS_ARRAY_SIZE 4 * (3+2) //(2 + 2)
#define BB_POS_ARRAY_SIZE 4 * (3+2)
#define BB_IND_ARRAY_SIZE 4
class Billboard : public SceneObject
......
......@@ -23,7 +23,6 @@ class ScoreText : public SceneObject
void privateRender();
void privateUpdate();
private:
float pos_x;
float pos_y;
......
......@@ -21,8 +21,6 @@ public:
void Bind() const;
void Unbind() const;
// Set uniforms
void SetUniform1i(const std::string& name, int value);
void SetUniform3f(const std::string& name, float v0, float v1, float v2);
void SetUniform4f(const std::string& name, float v0, float v1, float v2, float v3);
......
13227
\ No newline at end of file
0
\ No newline at end of file
......@@ -8,6 +8,7 @@
Camera::Camera()
{
// Camera placement
auto translation = glm::translate(glm::mat4(1.0f), glm::vec3(-80.0f, -200.0f, -700.0f));
auto rotation = glm::rotate(glm::mat4(1.0f), glm::radians(45.0f), glm::vec3(0.0f,1.0f,0.0f));
matrix_ = translation * rotation;
......
......@@ -34,8 +34,6 @@ void Character::privateInit()
layout.Push<float>(3);
// 3 floats for normals
layout.Push<float>(3);
// 2 floats for texture position
// layout.Push<float>(2);
/* VERTEX ARRAY */
vao.AddBuffer(vbo, layout);
......@@ -49,12 +47,8 @@ void Character::privateInit()
shader.SetUniform3f("u_LightPosition", globalLightPosition_[0], globalLightPosition_[1], globalLightPosition_[2]);
shader.SetUniform3f("u_CameraPosition", viewMatrix_[3].x, viewMatrix_[3].y, viewMatrix_[3].z);
/* TEXTURE */
// texture.BindCubemap(textureSlot);
// shader.SetUniform1i("u_Texture", textureSlot);
/* UNBINDING */
// texture.UnbindCubemap();
vao.Unbind();
vbo.Unbind();
ibo.Unbind();
......@@ -95,11 +89,9 @@ void Character::privateInit()
void Character::privateRender()
{
// Shader implemetation
shader.Bind();
vao.Bind();
ibo.Bind();
// texture.BindCubemap(textureSlot);
shader.SetUniformMat4f("u_ViewMatrix", viewMatrix_);
shader.SetUniformMat4f("u_ProjectionMatrix", projMatrix_);
......@@ -109,7 +101,6 @@ void Character::privateRender()
GLCall(glDrawElements(GL_QUADS, ibo.GetCount(), GL_UNSIGNED_INT, nullptr));
// texture.UnbindCubemap();
ibo.Unbind();
vao.Unbind();
shader.Unbind();
......@@ -357,6 +348,8 @@ void Character::createNormalLineList()
vertexArray_[i].y + sharedNormalArray_[i].y * 10,
vertexArray_[i].z + sharedNormalArray_[i].z * 10);
}
// Corner normals
// for (size_t i = 0; i < vertexArray_.size() && i < normalArray_.size(); i++) {
// glVertex3f(vertexArray_[i].x,
// vertexArray_[i].y,
......@@ -438,9 +431,6 @@ void Character::setUpHBTextures()
void Character::privateUpdate()
{
// auto translation = glm::translate(glm::mat4(1.0f), glm::vec3(0.2f * speed_, 0.0f, 0.0f));
// auto rotation = glm::rotate(matrix_, 0.01f, glm::vec3(0.0f,1.0f,0.0f));
// matrix_ = translation * rotation;
}
......
#include "../include/GLErrorHandler.h"
// Empty the error "stack"
void GLClearError() {
while (glGetError() != GL_NO_ERROR) {
}
}
// Print error number, function, file and line number to console
bool GLLogCall(const char* function, const char* file, int line) {
while (GLenum error = glGetError()) {
std::cout << "OpenGL error: " << std::hex << error << "\nFunction: " << function << "\nFile: " << file << "\nLine: " << line << std::endl;
......
......@@ -78,6 +78,7 @@ void GameManager::privateInit()
scoreText_.reset(new ScoreText("Score: ", -0.95f, - 0.9f, 0.0f));
this->addSubObject(scoreText_);
// load highscore from file
std::ifstream infile("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/data/highscore.dat");
if (infile){
infile >> highscore_;
......@@ -85,7 +86,6 @@ void GameManager::privateInit()
else {
std::cout << "COULD NOT OPEN HIGHSCORE FILE!" << std::endl;
}
infile.close();
// Highscore text
......@@ -168,12 +168,13 @@ void GameManager::resetCharacterAfterCollision()
}
else {
gameoverBillboard_->setState(true);
scoreText_->setIncrement(0);
unsigned int score = scoreText_->getScore();
if (score > highscore_) {
// Overwrite current highscore with new highscore
std::ofstream outfile("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/data/highscore.dat", std::ios::trunc);
if (outfile){
outfile << score;
}
......@@ -183,8 +184,6 @@ void GameManager::resetCharacterAfterCollision()
outfile.close();
}
// exit(0);
}
character_->setState(characterStates::normal);
......
......@@ -6,8 +6,11 @@ IndexBuffer::IndexBuffer(const unsigned int* data, unsigned int count)
{
ASSERT(sizeof(unsigned int) == sizeof(GLuint));
// Create and bind buffer
GLCall(glGenBuffers(1, &m_RendererID));
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID));
// Allocate memory for buffer data
GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW));
}
......
......@@ -28,8 +28,6 @@ void Obstacle::privateInit()
layout.Push<float>(3);
// 3 floats for normals
layout.Push<float>(3);
// 2 floats for texture position
// layout.Push<float>(2);
/* VERTEX ARRAY */
vao.AddBuffer(vbo, layout);
......@@ -39,7 +37,6 @@ void Obstacle::privateInit()
/* SHADER */
shader.Bind();
// shader.SetUniform4f("u_Color", 0.0f, 0.0f, 1.0f, 1.0f);
shader.SetUniform3f("u_LightPosition", globalLightPosition_[0], globalLightPosition_[1], globalLightPosition_[2]);
shader.SetUniform3f("u_CameraPosition", viewMatrix_[3].x, viewMatrix_[3].y, viewMatrix_[3].z);
......@@ -47,7 +44,6 @@ void Obstacle::privateInit()
texture.BindCubemap(textureSlot);
shader.SetUniform1i("u_Texture", textureSlot);
/* UNBINDING */
texture.UnbindCubemap();
vao.Unbind();
......@@ -80,12 +76,13 @@ void Obstacle::privateUpdate()
glm::vec3 trans;
float resetDistance = 4000.0f;
// If outside of view, reset position with a random z-value within landscape
if (position_.x < - 1.5 * 200 * 3) {
trans = glm::vec3(resetDistance, tan(glm::radians(30.0f)) * resetDistance, -200.0f + float(rand() % 400));
translation_ = glm::translate(glm::mat4(1.0f), trans);
position_ = trans;
}
// if not, move diagonally down along landscape
else {
trans = glm::vec3(speed_, tan(glm::radians(30.0f)) * speed_, 0.0f);
translation_ = glm::translate(translation_, trans);
......
......@@ -66,6 +66,7 @@ void Plane::privateInit()
void Plane::privateRender()
{
// Shader implementation
shader.Bind();
vao.Bind();
ibo.Bind();
......@@ -84,6 +85,7 @@ void Plane::privateRender()
vao.Unbind();
shader.Unbind();
// Fixed function pipeline implementation
// // Draw filled polygons
// glColor3f(0.0f, 1.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
......@@ -145,9 +147,11 @@ void Plane::privateRender()
void Plane::privateUpdate()
{
// If outside of view, reset position
if (matrix_[3].x < - 1.5 * 200 * scaling) {
matrix_ = glm::translate(matrix_, glm::vec3(3.75f * 200 * scaling - 2, 0.0f, 0.0f));
}
// if not, move diagonally downwards
else {
matrix_ = glm::translate(matrix_, glm::vec3(-1.0f, 0.0f, 0.0f));
}
......
......@@ -33,6 +33,8 @@ void SceneObject::update(double fps)
this->privateUpdate();
for(std::vector<std::shared_ptr<SceneObject> >::iterator it = children_.begin();
it != children_.end(); it++) {
// Update each sceneobject's view matrix to be the camera position,
// which in this case is the gamemanager's model matrix
(*it)->viewMatrix_ = matrix_;
(*it)->update(fps);
}
......
......@@ -19,6 +19,7 @@ void ScoreText::privateRender() {
glEnable(GL_COLOR_MATERIAL);
glColor3f(1.0f, 1.0f, 1.0f);
// Save and reset matrices
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
......@@ -34,6 +35,7 @@ void ScoreText::privateRender() {
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, c);
}
// Reload matrices
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
......
......@@ -24,8 +24,6 @@ void Skybox::privateInit()
/* LAYOUT */
// 3 floats for world position
layout.Push<float>(3);
// 2 floats for texture position
// layout.Push<float>(2);
/* VERTEX ARRAY */
vao.AddBuffer(vbo, layout);
......@@ -35,7 +33,6 @@ void Skybox::privateInit()
/* SHADER */
shader.Bind();
// shader.SetUniform4f("u_Color", 0.0f, 0.0f, 1.0f, 1.0f);
/* TEXTURE */
texture.BindCubemap(textureSlot);
......
......@@ -19,6 +19,7 @@ void Text::privateRender() {
glEnable(GL_COLOR_MATERIAL);
glColor3f(1.0f, 1.0f, 1.0f);
// Save and reset matrices
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
......@@ -34,6 +35,7 @@ void Text::privateRender() {
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, c);
}
// Load matrices
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
......
......@@ -6,6 +6,7 @@ Texture::Texture(const std::string& filepath)
: m_FilePath(filepath), m_LocalBuffer(nullptr),
m_Width(0), m_Height(0), m_BPP(0)
{
// Load data from file into buffer
stbi_set_flip_vertically_on_load(1);
m_LocalBuffer = stbi_load(filepath.c_str(), &m_Width, &m_Height, &m_BPP, 4);
if (!m_LocalBuffer)
......@@ -13,14 +14,17 @@ Texture::Texture(const std::string& filepath)
std::cout << "FAILED TO LOAD TEXTURE FROM " << filepath <<"\nFAILURE REASON: "<< stbi_failure_reason() << std::endl;
}
// Create and bind texture
GLCall(glGenTextures(1, &m_RendererID));
GLCall(glBindTexture(GL_TEXTURE_2D, m_RendererID));
// Set texture parameteres
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
// Load buffer into texture
GLCall(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer));
GLCall(glBindTexture(GL_TEXTURE_2D, 0));
......@@ -33,10 +37,12 @@ Texture::Texture(const std::vector<std::string> faces)
: m_LocalBuffer(nullptr),
m_Width(0), m_Height(0), m_BPP(0)
{
// Create and bind texture
stbi_set_flip_vertically_on_load(0);
GLCall(glGenTextures(1, &m_RendererID));
GLCall(glBindTexture(GL_TEXTURE_CUBE_MAP, m_RendererID));
// Load data from file into buffer
for (unsigned int i = 0; i < faces.size(); i++) {
m_LocalBuffer = stbi_load(faces[i].c_str(), &m_Width, &m_Height, &m_BPP, 4);
if (!m_LocalBuffer)
......@@ -49,6 +55,7 @@ Texture::Texture(const std::vector<std::string> faces)
}
}
// Set texture parameteres
GLCall(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLCall(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCall(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
......
......@@ -19,6 +19,7 @@ void VertexArray::AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& la
const auto& elements = layout.GetElements();
unsigned int offset = 0;
// Set attribute pointers of elements in vertexbuffer in accordance to the layout
for (unsigned int i = 0; i < elements.size(); i++) {
const auto& element = elements[i];
GLCall(glEnableVertexAttribArray(i));
......
......@@ -2,8 +2,11 @@
#include "../include/GLErrorHandler.h"
VertexBuffer::VertexBuffer(const void* data, unsigned int size) {
// Create and bind buffer
GLCall(glGenBuffers(1, &m_RendererID));
GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_RendererID));
// Allocate memory for buffer data
GLCall(glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment