Linux support!
parent
ae961379b2
commit
077682cd18
|
@ -0,0 +1,5 @@
|
|||
cmake_minimum_required (VERSION 2.6)
|
||||
project (Rhubarb)
|
||||
|
||||
include_directories("Rhubarb/")
|
||||
subdirs("Rhubarb")
|
|
@ -0,0 +1,25 @@
|
|||
add_executable(Rhubarb
|
||||
Core/CCamera.cpp
|
||||
Core/CEngine.cpp
|
||||
Core/CEntity.cpp
|
||||
Core/CMesh.cpp
|
||||
Core/CModel.cpp
|
||||
Core/CTriangleMesh.cpp
|
||||
|
||||
Shaders/CDLShader.cpp
|
||||
Shaders/CFlatShader.cpp
|
||||
Shaders/CIdentityShader.cpp
|
||||
Shaders/CPhongShader.cpp
|
||||
Shaders/CShaderBase.cpp
|
||||
|
||||
Helpers/CMatrixManager.cpp
|
||||
Helpers/CObjReader.cpp
|
||||
Helpers/CShaderManager.cpp
|
||||
Helpers/CTextureManager.cpp
|
||||
Helpers/CTimer.cpp
|
||||
|
||||
Math/CMatrix44.cpp
|
||||
Math/CVector4.cpp
|
||||
|
||||
main.cpp)
|
||||
target_link_libraries(Rhubarb glut GLEW)
|
|
@ -20,7 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/GL.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include "Core/CEntity.h"
|
||||
#include "Math/CMatrix44.h"
|
||||
|
@ -39,4 +39,4 @@ namespace rb
|
|||
|
||||
void LookAt(CVector4 &Target);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -22,7 +22,13 @@ using namespace rb;
|
|||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
extern int __argc;
|
||||
extern char **__argv;
|
||||
#endif
|
||||
|
||||
CEngine *CEngine::Get(void)
|
||||
{
|
||||
|
@ -191,7 +197,9 @@ void CEngine::Error(std::string Message)
|
|||
void CEngine::Fatal(std::string Message)
|
||||
{
|
||||
std::cerr << "[e] " << Message;
|
||||
#ifdef _WIN32
|
||||
MessageBoxA(0, Message.c_str(), "Fatal error", 0);
|
||||
#endif
|
||||
//throw Exception::FatalException(Message);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -209,4 +217,4 @@ CEngine::~CEngine(void)
|
|||
|
||||
bool CEngine::m_Spawned = false;
|
||||
bool CEngine::m_Initialized = false;
|
||||
CEngine *CEngine::m_Singleton = 0;
|
||||
CEngine *CEngine::m_Singleton = 0;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
#define GLEW_STATIC
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/freeglut.h>
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/GL.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include "Math/CVector4.h"
|
||||
#include "Math/CMatrix44.h"
|
||||
|
@ -66,4 +66,4 @@ namespace rb
|
|||
private:
|
||||
GLfloat *m_TempMatrix;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ CModel::CModel(void)
|
|||
m_Mesh = 0;
|
||||
m_Shader = 0;
|
||||
|
||||
CEntity::CEntity();
|
||||
CEntity();
|
||||
|
||||
m_Shininess = 128.0f;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ void CModel::Load(std::string Filename)
|
|||
CEngine::Get()->GetManagers(&m_MatrixManager, 0, &m_TextureManager);
|
||||
|
||||
std::ifstream File;
|
||||
File.open(Filename, std::ios::in);
|
||||
File.open(Filename.c_str(), std::ios::in);
|
||||
|
||||
std::string Keyword;
|
||||
|
||||
|
@ -140,7 +140,8 @@ void CModel::Draw(void)
|
|||
m_MatrixManager->Push();
|
||||
m_MatrixManager->Multiply(GetMatrix());
|
||||
|
||||
m_Shader->Use(m_MatrixManager->GetMV(), m_MatrixManager->GetMVP(), CVector4(100.0f, 50.0f, 70.0f), m_Ambient, m_Diffuse, m_Shininess);
|
||||
CVector4 LightVector(100.0f, 50.0f, 70.0f);
|
||||
m_Shader->Use(m_MatrixManager->GetMV(), m_MatrixManager->GetMVP(), LightVector, m_Ambient, m_Diffuse, m_Shininess);
|
||||
|
||||
if (m_HasTexture)
|
||||
glBindTexture(GL_TEXTURE_2D, m_Texture);
|
||||
|
|
|
@ -154,6 +154,51 @@ void CTriangleMesh::ReadLists(GLushort *Indices, GLuint NumberIndices, GLfloat *
|
|||
m_IndexCount = NumberIndices;
|
||||
}
|
||||
|
||||
void CTriangleMesh::AddTriangle(CVector4 Vertices[3], CVector4 Normals[3], GLfloat TextureVertices[6])
|
||||
{
|
||||
for (GLuint i = 0; i < 3; i++)
|
||||
AddIndex(Vertices[i], Normals[i], &TextureVertices[i * 2]);
|
||||
}
|
||||
|
||||
void CTriangleMesh::AddIndex(CVector4 &Vertex, CVector4 &Normal, GLfloat NewTextureVertex[2])
|
||||
{
|
||||
GLfloat *NewVertex = Vertex.m_Data;
|
||||
|
||||
CVector4 NormalizedNormal;
|
||||
Normal.Normalize(NormalizedNormal);
|
||||
GLfloat *NewNormal = NormalizedNormal.m_Data;
|
||||
|
||||
//each vertex from current vertex list.
|
||||
GLuint j = 0;
|
||||
for (j = 0; j < m_VertexCount / 3; j++)
|
||||
{
|
||||
GLfloat *OldVertex = m_Vertices + j * 3;
|
||||
GLfloat *OldNormal = m_Normals + j * 3;
|
||||
GLfloat *OldTextureVertex = m_TextureVertices + j * 2;
|
||||
|
||||
if (CompareVectors(NewVertex, OldVertex) &&
|
||||
CompareVectors(NewNormal, OldNormal) &&
|
||||
CompareTextureVertices(NewTextureVertex, OldTextureVertex))
|
||||
{
|
||||
m_Indices[m_IndexCount] = j;
|
||||
m_IndexCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == m_VertexCount / 3 && m_VertexCount / 3 < m_Maximum)
|
||||
{
|
||||
//std::cout << "Adding vertex..." << std::endl;
|
||||
memcpy_s(m_Vertices + m_VertexCount, sizeof(GLfloat) * 3, NewVertex, sizeof(GLfloat) * 3);
|
||||
memcpy_s(m_Normals + m_VertexCount, sizeof(GLfloat) * 3, NewNormal, sizeof(GLfloat) * 3);
|
||||
memcpy_s(m_TextureVertices + (m_VertexCount / 3) * 2, sizeof(GLfloat) * 2, NewTextureVertex, sizeof(GLfloat) * 2);
|
||||
|
||||
m_Indices[m_IndexCount] = m_VertexCount / 3;
|
||||
m_IndexCount++;
|
||||
m_VertexCount += 3;
|
||||
}
|
||||
}
|
||||
|
||||
void CTriangleMesh::LoadFromObj(std::string File)
|
||||
{
|
||||
CObjReader Reader(File);
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/GL.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include "Core/Platform.h"
|
||||
#include "Math/CVector4.h"
|
||||
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
namespace rb
|
||||
{
|
||||
|
@ -36,50 +38,8 @@ namespace rb
|
|||
|
||||
//Automatic detection of duplicate vertices, immediate mode
|
||||
void Begin(GLint NumberVertices);
|
||||
|
||||
inline void AddIndex(CVector4 &Vertex, CVector4 &Normal, GLfloat NewTextureVertex[2])
|
||||
{
|
||||
GLfloat *NewVertex = Vertex.m_Data;
|
||||
|
||||
CVector4 NormalizedNormal;
|
||||
Normal.Normalize(NormalizedNormal);
|
||||
GLfloat *NewNormal = NormalizedNormal.m_Data;
|
||||
|
||||
//each vertex from current vertex list.
|
||||
GLuint j = 0;
|
||||
for (j = 0; j < m_VertexCount / 3; j++)
|
||||
{
|
||||
GLfloat *OldVertex = m_Vertices + j * 3;
|
||||
GLfloat *OldNormal = m_Normals + j * 3;
|
||||
GLfloat *OldTextureVertex = m_TextureVertices + j * 2;
|
||||
|
||||
if (CompareVectors(NewVertex, OldVertex) &&
|
||||
CompareVectors(NewNormal, OldNormal) &&
|
||||
CompareTextureVertices(NewTextureVertex, OldTextureVertex))
|
||||
{
|
||||
m_Indices[m_IndexCount] = j;
|
||||
m_IndexCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j == m_VertexCount / 3 && m_VertexCount / 3 < m_Maximum)
|
||||
{
|
||||
//std::cout << "Adding vertex..." << std::endl;
|
||||
memcpy_s(m_Vertices + m_VertexCount, sizeof(GLfloat) * 3, NewVertex, sizeof(GLfloat) * 3);
|
||||
memcpy_s(m_Normals + m_VertexCount, sizeof(GLfloat) * 3, NewNormal, sizeof(GLfloat) * 3);
|
||||
memcpy_s(m_TextureVertices + (m_VertexCount / 3) * 2, sizeof(GLfloat) * 2, NewTextureVertex, sizeof(GLfloat) * 2);
|
||||
|
||||
m_Indices[m_IndexCount] = m_VertexCount / 3;
|
||||
m_IndexCount++;
|
||||
m_VertexCount += 3;
|
||||
}
|
||||
}
|
||||
inline void CTriangleMesh::AddTriangle(CVector4 Vertices[3], CVector4 Normals[3], GLfloat TextureVertices[6])
|
||||
{
|
||||
for (GLuint i = 0; i < 3; i++)
|
||||
AddIndex(Vertices[i], Normals[i], &TextureVertices[i * 2]);
|
||||
}
|
||||
void AddIndex(CVector4 &Vertex, CVector4 &Normal, GLfloat NewTextureVertex[2]);
|
||||
void AddTriangle(CVector4 Vertices[3], CVector4 Normals[3], GLfloat TextureVertices[6]);
|
||||
void End(void);
|
||||
|
||||
//Direct index and vertex list
|
||||
|
@ -105,21 +65,21 @@ namespace rb
|
|||
GLuint m_NormalArray;
|
||||
GLuint m_TextureVertexArray;
|
||||
|
||||
inline bool CTriangleMesh::CompareVectors(GLfloat *VertexA, GLfloat *VertexB)
|
||||
inline bool CompareVectors(GLfloat *VertexA, GLfloat *VertexB)
|
||||
{
|
||||
const GLfloat Error = 0.0001f;
|
||||
if (abs(VertexA[0] - VertexB[0]) <= Error &&
|
||||
abs(VertexA[1] - VertexB[1]) <= Error &&
|
||||
abs(VertexA[2] - VertexB[2]) <= Error)
|
||||
if (std::abs(VertexA[0] - VertexB[0]) <= Error &&
|
||||
std::abs(VertexA[1] - VertexB[1]) <= Error &&
|
||||
std::abs(VertexA[2] - VertexB[2]) <= Error)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
inline bool CTriangleMesh::CompareTextureVertices(GLfloat *VertexA, GLfloat *VertexB)
|
||||
inline bool CompareTextureVertices(GLfloat *VertexA, GLfloat *VertexB)
|
||||
{
|
||||
const GLfloat Error = 0.0001f;
|
||||
if (abs(VertexA[0] - VertexB[0]) <= Error &&
|
||||
abs(VertexA[1] - VertexB[1]) <= Error)
|
||||
if (std::abs(VertexA[0] - VertexB[0]) <= Error &&
|
||||
std::abs(VertexA[1] - VertexB[1]) <= Error)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// Platform-specific stuff
|
||||
// (mostly dirty fixes to get this to play nice with gcc
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#define memcpy_s(a, b, c, d) memcpy(a, c, d)
|
||||
#define strncpy_s(a, b, c, d) strncpy(a, c, d)
|
||||
#endif
|
|
@ -20,6 +20,7 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Core/Platform.h"
|
||||
#include "Helpers/CMatrixManager.h"
|
||||
using namespace rb;
|
||||
|
||||
|
@ -95,7 +96,7 @@ void CMatrixManager::Pop(void)
|
|||
|
||||
bool CMatrixManager::CanAllocate(void)
|
||||
{
|
||||
return (((unsigned int)m_StackPointer - (unsigned int)m_StackBottom) <= m_MaxSize * 64 - 64);
|
||||
return ((m_StackPointer - m_StackBottom) <= m_MaxSize * 64 - 64);
|
||||
}
|
||||
|
||||
void CMatrixManager::Multiply(CMatrix44 &Matrix)
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/GL.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
@ -91,4 +91,4 @@ namespace rb
|
|||
|
||||
bool CanAllocate(void);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -38,7 +38,7 @@ void CObjReader::Read(CTriangleMesh &Target)
|
|||
{
|
||||
std::cout << "[i] Reading .obj file " << m_Filename << "..." << std::endl;
|
||||
std::ifstream File;
|
||||
File.open(m_Filename, std::ios::binary | std::ios::in);
|
||||
File.open(m_Filename.c_str(), std::ios::binary | std::ios::in);
|
||||
|
||||
if (!File.is_open())
|
||||
throw Exception::ObjReaderException("Can not open file.");
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <exception>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/GL.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include "Core/CTriangleMesh.h"
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "Helpers/CTextureManager.h"
|
||||
using namespace rb;
|
||||
|
||||
#include "Core/Platform.h"
|
||||
#include "Core/CEngine.h"
|
||||
|
||||
#include <fstream>
|
||||
|
@ -36,7 +37,7 @@ TTexture CTextureManager::GetTexture(std::string Name)
|
|||
return m_Textures[Name];
|
||||
|
||||
std::ifstream File;
|
||||
File.open(Name, std::ios::in | std::ios::binary);
|
||||
File.open(Name.c_str(), std::ios::in | std::ios::binary);
|
||||
|
||||
if (!File.is_open())
|
||||
throw Exception::TextureManagerException("Error opening texture file.");
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <exception>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/GL.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace rb
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ CTimer::CTimer(void)
|
|||
QueryPerformanceFrequency(&m_Frequency);
|
||||
QueryPerformanceCounter(&m_Last);
|
||||
#else
|
||||
gettimeofday(&m_LastCount, 0);
|
||||
gettimeofday(&m_Last, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
**
|
||||
************************************************************************/
|
||||
|
||||
#include "Core/Platform.h"
|
||||
#include "Math/CMatrix44.h"
|
||||
using namespace rb;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/GL.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace rb
|
||||
{
|
||||
|
|
|
@ -17,8 +17,20 @@
|
|||
**
|
||||
************************************************************************/
|
||||
|
||||
//Just include EVERYTHING
|
||||
// Use from client application ONLY
|
||||
// Just include EVERYTHING
|
||||
|
||||
#ifndef __RB_EXTERNAL_ARGS__
|
||||
#define __RB_EXTERNAL_ARGS__
|
||||
|
||||
int __argc;
|
||||
char **__argv;
|
||||
|
||||
#define RB_PARSE_ARGUMENTS(c, v) __argc = c; __argv = v;
|
||||
|
||||
#endif
|
||||
|
||||
#include "Core/Platform.h"
|
||||
#include "Core/CEngine.h"
|
||||
|
||||
#include "Core/CCamera.h"
|
||||
|
@ -36,4 +48,4 @@
|
|||
#include "Shaders/CFlatShader.h"
|
||||
#include "Shaders/CIdentityShader.h"
|
||||
#include "Shaders/CPhongShader.h"
|
||||
#include "Shaders/CShaderBase.h"
|
||||
#include "Shaders/CShaderBase.h"
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#pragma once
|
||||
#include "Shaders/CShaderBase.h"
|
||||
|
||||
#include "Core/Platform.h"
|
||||
#include "Math/CMatrix44.h"
|
||||
|
||||
namespace rb
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
**
|
||||
************************************************************************/
|
||||
|
||||
#include "Core/Platform.h"
|
||||
#include "Shaders/CIdentityShader.h"
|
||||
|
||||
#include <string>
|
||||
|
@ -24,7 +25,7 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/GL.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
using namespace rb;
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
************************************************************************/
|
||||
|
||||
#include "Shaders/CPhongShader.h"
|
||||
|
||||
#include "Core/Platform.h"
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ void CShaderBase::Initialize(void)
|
|||
glLinkProgram(m_Program);
|
||||
|
||||
GLint Test;
|
||||
glGetProgramiv(m_Program, GL_COMPILE_STATUS, &Test);
|
||||
glGetProgramiv(m_Program, GL_LINK_STATUS, &Test);
|
||||
|
||||
if (Test == GL_FALSE)
|
||||
{
|
||||
|
|
|
@ -45,16 +45,19 @@ bool fnRender(float DeltaTime)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
RB_PARSE_ARGUMENTS(argc, argv);
|
||||
g_Engine->Initialize(800, 600, "Rhubarb Demo");
|
||||
|
||||
Model.Load("Data/teapot.model");
|
||||
Text.Load("Data/text.model");
|
||||
|
||||
|
||||
Camera.SetPosition(0.0f, 20.0f, 45.0f);
|
||||
Camera.LookAt(rb::CVector4(0.0f, 5.0f, 0.0f));
|
||||
|
||||
rb::CVector4 LookTarget(0.0f, 5.0f, 0.0f);
|
||||
Camera.LookAt(LookTarget);
|
||||
|
||||
g_Engine->SetClearColor(0.05f, 0.05f, 0.05f);
|
||||
g_Engine->SetRenderFunction(fnRender);
|
||||
g_Engine->SetCamera(&Camera);
|
||||
g_Engine->Start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue