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

Fixed inclusion errors

parent de8c40d6
......@@ -27,34 +27,43 @@ endif(NOT OPENGL_FOUND)
set( INCLUDE
include/Landscape.hpp
include/Camera.hpp
include/Clock.hpp
include/FpsCounter.hpp
include/GameManager.hpp
include/Input.hpp
include/SceneObject.hpp
include/Camera.hpp
include/Clock.hpp
include/FpsCounter.hpp
include/GameManager.hpp
include/Input.hpp
include/SceneObject.hpp
include/Character.hpp
include/Utils.hpp
include/Snow.hpp
include/Text.hpp
include/Minimap.hpp
include/IndexBuffer.h
include/Shader.h
include/VertexArray.h
include/VertexBuffer.h
include/VertexBufferLayout.h
include/GLErrorHandler.h
include/stb_image.h
)
set( SRCS
src/Landscape.cpp
src/Camera.cpp
src/GameManager.cpp
src/SceneObject.cpp
src/Camera.cpp
src/GameManager.cpp
src/SceneObject.cpp
src/Character.cpp
src/Snow.cpp
src/Text.cpp
src/Minimap.cpp
src/IndexBuffer.cpp
src/Shader.cpp
src/VertexArray.cpp
src/VertexBuffer.cpp
src/GLErrorHandler.cpp
src/stb_image.cpp
app/main.cpp
......
#pragma once
#include <iostream>
#include <windows.h>
#include <GL/glew.h>
#include <iostream>
#define ASSERT(x) if (!(x)) __debugbreak();
#define GLCall(x) GLClearError();\
......
......@@ -2,9 +2,6 @@
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "SceneObject.hpp"
#include "Landscape.hpp"
#include "Character.hpp"
......@@ -13,6 +10,12 @@
#include "Text.hpp"
#include "Minimap.hpp"
#include <GL/gl.h>
#include <GL/glu.h>
class GameManager : public SceneObject
{
public:
......
#pragma once
class IndexBuffer {
private:
unsigned int m_RendererID;
unsigned int m_Count;
public:
IndexBuffer(const unsigned int* data, unsigned int count);
~IndexBuffer();
void Bind() const;
void Unbind() const;
inline unsigned int GetCount() const { return m_Count; }
};
#pragma once
#include "../include/VertexArray.h"
#include "../include/VertexBuffer.h"
#include "../include/VertexBufferLayout.h"
#include "../include/IndexBuffer.h"
#include <windows.h>
#include <GL/freeglut.h>
#include <GL/gl.h>
//#include <GL/gl.h>
#include <GL/glu.h>
#include "SceneObject.hpp"
......@@ -10,20 +15,58 @@
class Landscape : public SceneObject
{
public:
Landscape();
~Landscape();
public:
Landscape();
~Landscape();
protected:
protected:
virtual void privateInit();
virtual void privateRender();
virtual void privateUpdate();
virtual void privateRender();
virtual void privateUpdate();
private:
std::vector< glm::vec3 > vertexArray_; // Maybe two-dim vector and several arrays
private:
// vertex array
std::vector< glm::vec3 > vertexArray_;
// normal array.
std::vector< glm::vec3 > normalArray_;
// texture coord array
std::vector< glm::vec3 > textureArray_;
unsigned int positions_[3 * 4 * 3] = {
// Left plane
-100.0f, -50.0f, 50.0f,
0.0f, -50.0f, 50.0f,
0.0f, -50.0f, -50.0f,
-100.0f, -50.0f, -50.0f,
// Middle plane
0.0f, -50.0f, 50.0f,
100.0f, -50.0f, 50.0f,
100.0f, -50.0f, -50.0f,
0.0f, -50.0f, -50.0f,
// Right plane
100.0f, -50.0f, 50.0f,
200.0f, -50.0f, 50.0f,
200.0f, -50.0f, -50.0f,
100.0f, -50.0f, -50.0f,
// Background
-1000.0f, -1000.0f, -500.0f,
1000.0f, -1000.0f, -500.0f,
1000.0f, 1000.0f, -500.0f,
-1000.0f, 1000.0f, -500.0f
};
unsigned int indices_[4 * 3] = {
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11
};
VertexArray vao;
VertexBuffer vbo;
VertexBufferLayout layout;
IndexBuffer ibo;
};
#pragma once
#include <windows.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <iostream>
#include "SceneObject.hpp"
#include <GL/gl.h>
class Minimap : public SceneObject {
public:
......
#pragma once
#include <string>
#include <unordered_map>
#include "../../glm-master/glm/glm.hpp"
struct ShaderProgramSource {
std::string VertexSource;
std::string FragmentSource;
};
class Shader {
private:
std::string m_FilePath;
unsigned int m_RendererID;
std::unordered_map<std::string, int> m_UniformLocationCache;
public:
Shader(const std::string& filepath);
~Shader();
void Bind() const;
void Unbind() const;
// Set uniforms
void SetUniform1i(const std::string& name, int value);
void SetUniform4f(const std::string& name, float v0, float v1, float v2, float v3);
void SetUniformMat4f(const std::string& name, const glm::mat4& matrix);
private:
int GetUniformLocation(const std::string& name);
unsigned int CompileShader(unsigned int type, const std::string& source);
ShaderProgramSource ParseShader(const std::string& filepath);
unsigned int CreateShader(const std::string& vertexShaderCode, const std::string& fragmentShaderCode);
};
......@@ -2,7 +2,7 @@
#include <windows.h>
#include <GL/freeglut.h>
#include <GL/gl.h>
//#include <GL/gl.h>
#include <GL/glu.h>
#include "SceneObject.hpp"
......
#pragma once
#include <windows.h>
#include <GL/gl.h>
//#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <string>
......
#pragma once
#include "VertexBuffer.h"
class VertexBufferLayout;
class VertexArray {
private:
unsigned int m_RendererID;
public:
VertexArray();
~VertexArray();
void AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout);
void Bind() const;
void Unbind() const;
};
#pragma once
class VertexBuffer {
private:
unsigned int m_RendererID;
public:
VertexBuffer(const void* data, unsigned int size);
~VertexBuffer();
void Bind() const;
void Unbind() const;
};
#pragma once
#include <vector>
#include "../include/GLErrorHandler.h"
struct VertexBufferElement {
unsigned int type;
unsigned int count;
unsigned char normalized;
static unsigned int GetSizeOfType(unsigned int type) {
switch (type)
{
case GL_FLOAT:
return 4;
break;
case GL_UNSIGNED_INT:
return 4;
break;
case GL_UNSIGNED_BYTE:
return 1;
break;
default:
ASSERT(false);
return 0;
break;
}
}
};
class VertexBufferLayout {
private:
std::vector<VertexBufferElement> m_Elements;
unsigned int m_Stride;
public:
VertexBufferLayout()
: m_Stride(0) {}
template<typename T>
void Push(unsigned int count) {
//static_assert(false);
}
template<>
void Push<float>(unsigned int count) {
m_Elements.push_back({ GL_FLOAT, count, GL_FALSE });
m_Stride += VertexBufferElement::GetSizeOfType(GL_FLOAT) * count;
}
template<>
void Push<unsigned int>(unsigned int count) {
m_Elements.push_back({ GL_UNSIGNED_INT, count, GL_FALSE });
m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_INT) * count;
}
template<>
void Push<unsigned char>(unsigned int count) {
m_Elements.push_back({ GL_UNSIGNED_BYTE, count, GL_TRUE });
m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_BYTE) * count;
}
inline unsigned int GetStride() const { return m_Stride; }
inline const std::vector<VertexBufferElement> GetElements() const { return m_Elements; }
};
......@@ -4,7 +4,7 @@ void GLClearError() {
while (glGetError() != GL_NO_ERROR) {
}
};
}
bool GLLogCall(const char* function, const char* file, int line) {
while (GLenum error = glGetError()) {
......@@ -13,4 +13,4 @@ bool GLLogCall(const char* function, const char* file, int line) {
}
return true;
};
}
#include "../include/IndexBuffer.h"
#include "../include/GLErrorHandler.h"
IndexBuffer::IndexBuffer(const unsigned int* data, unsigned int count)
: m_Count(count)
{
ASSERT(sizeof(unsigned int) == sizeof(GLuint));
GLCall(glGenBuffers(1, &m_RendererID));
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID));
GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW));
}
IndexBuffer::~IndexBuffer()
{
GLCall(glDeleteBuffers(1, &m_RendererID));
}
void IndexBuffer::Bind() const
{
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID));
}
void IndexBuffer::Unbind() const
{
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
}
......@@ -33,66 +33,82 @@ void Landscape::privateInit()
vertexArray_.push_back(glm::vec3(1000.0f, -1000.0f, -500.0f));
vertexArray_.push_back(glm::vec3(1000.0f, 1000.0f, -500.0f));
vertexArray_.push_back(glm::vec3(-1000.0f, 1000.0f, -500.0f));
vbo = VertexBuffer(vertexArray_.data(), vertexArray_.size() * 3 * sizeof(float));
layout.Push<float>(3);
vao.AddBuffer(vbo, layout);
// 4 points in a quad, 3 quads in total
ibo = IndexBuffer(indices_, 4 * 3);
vao.Unbind();
vbo.Unbind();
ibo.Unbind();
}
void Landscape::privateRender()
{
// Draw filled polygons
glColor3f(0.0f, 1.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(0.0f, 0.0f, 1.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 4, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0f, 1.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 8, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(0.2f, 0.2f, 0.2f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 12, 4);
glDisableClientState(GL_VERTEX_ARRAY);
// Drawing wireframe of polygons
glEnable(GL_POLYGON_OFFSET_LINE);
glPolygonOffset(-1.0, -1.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 4, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 8, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
glDrawArrays(GL_QUADS, 12, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_POLYGON_OFFSET_LINE);
vao.Bind();
ibo.Bind();
GLCall(glDrawElements(GL_QUADS, ibo.GetCount(), GL_UNSIGNED_INT, nullptr));
// // Draw filled polygons
// glColor3f(0.0f, 1.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 0, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(0.0f, 0.0f, 1.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 4, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(1.0f, 1.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 8, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(0.2f, 0.2f, 0.2f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 12, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// // Drawing wireframe of polygons
// glEnable(GL_POLYGON_OFFSET_LINE);
// glPolygonOffset(-1.0, -1.0);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// glColor3f(1.0f, 0.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 0, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(1.0f, 0.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 4, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(1.0f, 0.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 8, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(1.0f, 0.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 12, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// glDisable(GL_POLYGON_OFFSET_LINE);
}
......
#include <windows.h>
#include "GL/glew.h"
#include <GL/glut.h>
#include <GL/gl.h>
//#include <windows.h>
//#include "GL/glew.h"
//#include <GL/glut.h>
//#include <GL/gl.h>
#include "../include/Minimap.hpp"
#include "../include/GLErrorHandler.h"
//#include "../include/GLErrorHandler.h"
//GLuint g_fbo; // frame buffer object
//GLuint g_pbo; // pixel buffer object
......
#include <windows.h>
#include "../include/SceneObject.hpp"
#include <windows.h>
#include <GL/gl.h>
#include "../../glm-master/glm/glm.hpp"
#include "../../glm-master/glm/gtc/type_ptr.hpp"
#include <GL/gl.h>
// NB! Check matrix mult and scoped_ptr
......
#include "../include/Shader.h"
#include "../include/GLErrorHandler.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
Shader::Shader(const std::string& filepath)
: m_FilePath(filepath), m_RendererID(0)
{
ShaderProgramSource source = ParseShader(filepath);
m_RendererID = CreateShader(source.VertexSource, source.FragmentSource);
}
Shader::~Shader()
{
GLCall(glDeleteProgram(m_RendererID));
}
void Shader::Bind() const
{
GLCall(glUseProgram(m_RendererID));
}
void Shader::Unbind() const
{
GLCall(glUseProgram(0));
}
void Shader::SetUniform1i(const std::string& name, int value)
{
GLCall(glUniform1i(GetUniformLocation(name), value));
}
void Shader::SetUniform4f(const std::string& name, float v0, float v1, float v2, float v3)
{
GLCall(glUniform4f(GetUniformLocation(name), v0, v1, v2, v3));
}
void Shader::SetUniformMat4f(const std::string& name, const glm::mat4& matrix)
{
GLCall(glUniformMatrix4fv(GetUniformLocation(name), 1, GL_FALSE, &matrix[0][0]));
}
int Shader::GetUniformLocation(const std::string& name)
{
if (m_UniformLocationCache.find(name) != m_UniformLocationCache.end()) {
return m_UniformLocationCache[name];
}
GLCall(int location = glGetUniformLocation(m_RendererID, name.c_str()));
if (location == -1) {
std::cout << "Warning: uniform " << name << " does not exist!" << std::endl;
}
m_UniformLocationCache[name] = location;
return location;
}