Skip to content

Instantly share code, notes, and snippets.

View terryjsmith's full-sized avatar

Terry Smith terryjsmith

View GitHub Profile
@terryjsmith
terryjsmith / rendersystem.cpp
Created October 7, 2014 00:28
Evolution render loop
void RenderSystem::Update(float elapsed) {
// Clear the screen
glClearColor(0.0, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Update our camera info
glm::mat4 view = glm::lookAt(m_camera->translation, m_camera->translation + m_camera->look, m_camera->up);
glm::mat4 projection = glm::perspective(glm::radians(m_camera->fov), m_camera->aspect, m_camera->fnear, m_camera->ffar);
// Loop through all of our renderables and render them
@terryjsmith
terryjsmith / camera.cpp
Created October 7, 2014 00:21
Evolution Camera implementation
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <camera.h>
Camera::Camera() {
translation = glm::vec3(0.0f, 0.0f, 0.0f);
@terryjsmith
terryjsmith / camera.h
Created October 7, 2014 00:14
Evolution Camera class
class Camera {
public:
Camera();
~Camera();
public:
// Change translation
void SetTranslation(float x, float y, float z);
void Move(float x, float y, float z);
@terryjsmith
terryjsmith / shaderloader.cpp
Created October 5, 2014 23:40
Evolution ShaderLoader Load
// Once we get here, it's time to figure out which attributes and uniforms we have
GLint activeAttribs = 0;
GLint activeUniforms = 0;
glGetProgramiv(p, GL_ACTIVE_ATTRIBUTES, &activeAttribs);
glGetProgramiv(p, GL_ACTIVE_UNIFORMS, &activeUniforms);
// Start with the uniform variables
for(int i = 0; i < activeUniforms; i++) {
int size = 0;
int length = 0;
@terryjsmith
terryjsmith / shaderprogram.cpp
Created October 5, 2014 23:24
Evolution ShaderProgram implementation
#include <shaderprogram.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <string.h>
#include <stdlib.h>
ShaderProgram::ShaderProgram() {
program = 0;
m_list = 0;
}
@terryjsmith
terryjsmith / shaderprogram.h
Created October 5, 2014 23:19
Evolution ShaderProgram class
struct ShaderVariable {
char* name;
int location;
bool uniform;
ShaderVariable* next;
};
class ShaderProgram {
public:
@terryjsmith
terryjsmith / main.cpp
Created September 28, 2014 20:30
Evolution 1.1 Main Loop
int main(int argc, char** argv) {
/* INITIALIZATION */
g_renderSystem = new RenderSystem();
g_renderSystem->Initialize();
g_renderSystem->CreateWindow(800, 600, "Evolution", false);
/* START CODE TO CREATE TRIANGLE - THIS WILL HAPPEN IN A LOADER LATER */
// Let's create our first renderable entity
@terryjsmith
terryjsmith / rendersystem.cpp
Created September 28, 2014 20:27
Evolution RenderSystem 1.1
void RenderSystem::Update(float elapsed) {
// Loop through all of our renderables and render them
for(int i = 0; i < m_bucketSize; i++) {
if(m_components[i]) {
// Cast to a Renderable we can use
Renderable* component = (Renderable*)m_components[i];
// Bind the vertex attribute object, which will bind the buffers and attributes for us
glBindVertexArray(component->vertexAttribObject);
@terryjsmith
terryjsmith / renderable.h
Created September 28, 2014 20:25
Evolution Renderable class v1.1
class Renderable : public Component {
public:
Renderable();
~Renderable();
public:
// Position in world space
glm::vec3 position;
// Local rotation
@terryjsmith
terryjsmith / error.cpp
Created September 28, 2014 19:58
Evolution Error implementation
Error::Error() {
}
Error::~Error() {
}
void Error::Create(unsigned short type, char *message) {
std::string output = "";