Commit 0ddcc4d3 authored by Robert Menzel's avatar Robert Menzel

first commit

parents
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
################################################################################
# Global Settings
################################################################################
# Name of the Project
PROJECT(ACGL)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/CompileOptions.txt)
# Specify dependencies
SET(NEED_ACGL_GLOBAL_EXTERN_DIR TRUE)
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/GlobalAndLocalExternACGL.txt)
# OpenGL Support
IF(NOT DEFINED OPENGL_SUPPORT)
IF(NOT DEFINED OPENGL_SUPPORT_CORE_4_0)
SET(OPENGL_SUPPORT_CORE_4_0 FALSE CACHE BOOL "")
ENDIF()
IF(NOT DEFINED OPENGL_SUPPORT_ES_2_1)
SET(OPENGL_SUPPORT_ES_2_1 FALSE CACHE BOOL "")
ENDIF()
IF(OPENGL_SUPPORT_CORE_4_0)
SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT_LIST} GL_CORE_4_0)
ENDIF()
IF(OPENGL_SUPPORT_ES_2_1)
SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT_LIST} GL_ES_2_1)
ENDIF()
ELSE()
SET(OPENGL_SUPPORT_LIST ${OPENGL_SUPPORT})
ENDIF()
FOREACH(OPENGL_SUPPORT ${OPENGL_SUPPORT_LIST} )
################################################################################
# Basic Configuration
################################################################################
# Name of the Project
PROJECT(AC${OPENGL_SUPPORT})
# Where to find the cmake finders?
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Target directory
SET(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib")
################################################################################
# Project Files
################################################################################
# Find all used files of certain file-types
FILE(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc")
# Add ACGL to the include path
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/include")
################################################################################
# External Libraries
################################################################################
# Qt
SET(QT_USE_QTOPENGL TRUE)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
SET(LIBRARIES ${LIBRARIES} ${QT_LIBRARIES})
# GLM
FIND_PACKAGE(GLM REQUIRED)
INCLUDE_DIRECTORIES(${GLM_INCLUDE_DIR})
# GLEW
FIND_PACKAGE(GLEW REQUIRED)
INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIR})
SET(LIBRARIES ${LIBRARIES} ${GLEW_LIBRARIES})
################################################################################
# Final Definition
################################################################################
# Define the Project, add all required sources and dependencies to it
ADD_LIBRARY(AC${OPENGL_SUPPORT}${COMPILE_POSTFIX} STATIC ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(AC${OPENGL_SUPPORT}${COMPILE_POSTFIX} ${LIBRARIES})
ENDFOREACH()
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_HH
#define ACGL_HH
/*
* Include this in all ACGL (header)-files. It will include stuff that is used in
* almost every file:
* the used datatypes
* macros and defines used at compile-time
* logging
*/
#include <ACGL/Base/CompileTimeSettings.hh>
#include <ACGL/Types.hh>
#include <ACGL/Utils/Log.hh>
namespace ACGL
{
void init(void);
};
#endif // ACGL_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef COMPILETIMESETTINGS_HH
#define COMPILETIMESETTINGS_HH
/*
* OpenGL error checking
*
* By default, only critical errors will get checked in release build
* and critical&common in debug build.
*
* This can get overwritten with a compile flag define:
* -DACGL_CHECK_NO_GL_ERRORS
* No error checking at all
* -DACGL_CHECK_CRITICAL_GL_ERRORS
* Places will get checked where errors like out of memory can occur.
* This will detect runtime errors which can happen even if the program
* is bug free.
* Switching this on shouldn't be a performance hit.
* -DACGL_CHECK_COMMON_GL_ERRORS
* Problems that happen more often while developing like typos in uniform
* names. All placed where strings are used to call OpenGL objects etc.
* -DACGL_CHECK_RARE_GL_ERRORS
* Most likely bugs in ACGL itself or wrong usage. If there are strange errors
* switch this on to find the reason more quickly. Even normal development
* should work without this. Results in a lot of glGetError!
*
* Note that all error levels also include the higher ones (COMMON also adds CRITICAL).
*/
#ifndef ACGL_CHECK_NO_GL_ERRORS
# ifndef ACGL_CHECK_CRITICAL_GL_ERRORS
# ifndef ACGL_CHECK_COMMON_GL_ERRORS
# ifndef ACGL_CHECK_RARE_GL_ERRORS
// if nothing is defined, use defaults:
# ifdef DEBUG
# define ACGL_CHECK_COMMON_GL_ERRORS
# else
# define ACGL_CHECK_CRITICAL_GL_ERRORS
# endif
# endif
# endif
# endif
#endif
// if rare is set, set also common:
#ifdef ACGL_CHECK_RARE_GL_ERRORS
# ifndef ACGL_CHECK_COMMON_GL_ERRORS
# define ACGL_CHECK_COMMON_GL_ERRORS
# endif
#endif
// if common is set, set also critical:
#ifdef ACGL_CHECK_COMMON_GL_ERRORS
# ifndef ACGL_CHECK_CRITICAL_GL_ERRORS
# define ACGL_CHECK_CRITICAL_GL_ERRORS
# endif
#endif
// if critical is set, NO must not be set:
#ifdef ACGL_CHECK_CRITICAL_GL_ERRORS
# ifdef ACGL_CHECK_NO_GL_ERRORS
# undef ACGL_CHECK_NO_GL_ERRORS
# endif
#endif
#endif // COMPILETIMESETTINGS_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_BASE_FRAMEWORKSETTINGS_HH
#define ACGL_BASE_FRAMEWORKSETTINGS_HH
#include <ACGL/Base/Singleton.hh>
#include <string>
namespace ACGL{
namespace Base{
class Settings : public Singleton<Settings>
{
friend class Singleton<Settings>;
// ==================================================================================================== \/
// ========================================================================= Constructors / Destructors \/
// ==================================================================================================== \/
protected:
//! Constructor is protected => singleton.
Settings()
: mResourcePath (""),
mTexturePath ("Texture/"),
mGeometryPath ("Geometry/"),
mShaderPath ("Shader/")
{}
public:
~Settings(){}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline void setResourcePath (const std::string &_path) { mResourcePath = _path; }
inline void setTexturePath (const std::string &_path) { mTexturePath = _path; }
inline void setGeometryPath (const std::string &_path) { mGeometryPath = _path; }
inline void setShaderPath (const std::string &_path) { mShaderPath = _path; }
inline const std::string& getResourcePath() const { return mResourcePath; }
inline const std::string& getTexturePath() const { return mTexturePath; }
inline const std::string& getGeometryPath() const { return mGeometryPath; }
inline const std::string& getShaderPath() const { return mShaderPath; }
inline const std::string getFullTexturePath() const { return mResourcePath + mTexturePath; }
inline const std::string getFullGeometryPath() const { return mResourcePath + mGeometryPath; }
inline const std::string getFullShaderPath() const { return mResourcePath + mShaderPath; }
// ==================================================================================================== \/
// ============================================================================================= FIELDS \/
// ==================================================================================================== \/
private:
std::string mResourcePath;
std::string mTexturePath;
std::string mGeometryPath;
std::string mShaderPath;
};
} // Base
} // ACGL
#endif // FRAMEWORKSETTINGS_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef SINGLETON_HH
#define SINGLETON_HH
#include <tr1/memory>
namespace ACGL{
namespace Base{
template<typename CLASS>
class Singleton
{
public:
virtual ~Singleton(void) {}
static std::tr1::shared_ptr<CLASS> the(void)
{
if(!spInstance)
spInstance.reset(new CLASS());
return(spInstance);
}
protected:
Singleton(void){}
private:
Singleton(const Singleton&){}
private:
static std::tr1::shared_ptr<CLASS> spInstance;
};
template<typename CLASS>
std::tr1::shared_ptr<CLASS> Singleton<CLASS>::spInstance = std::tr1::shared_ptr<CLASS>();
} // Base
} // ACGL
#endif
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_GL_HH
#define ACGL_GL_HH
/*
* This simple OpenGL wrapper is used to include OpenGL, GLU, GLUT and GLEW
* on different platforms.
*
* While these includes are located in a subdirectory of GL/ on most systems,
* Apple hides them on different locations.
*
* Robert Menzel
*/
/*
* defines, what we need.
* Change this if you like.
* You don't have to include GL extra, if you need GLUT etc...
*
* QT also includes Glu!
*
* USE_GLEW and USE_GLEW_LOCAL are mutual exclusive, define only one
* change GLEW_LOCAL_PATH if you use USE_GLEW_LOCAL!
*
*/
#define USE_GL
//#define USE_GLU
//#define USE_GLUT
#define USE_QT
#define USE_GLEW
//#define USE_GLEW_LOCAL
//#define GLEW_LOCAL_PATH <GL/glew.h>
// We can try to build against OpenGL core profile or compatibility (core means automatically
// 3.2 or higher). On MacOS X 10.7 Lion we can choose between 2.1 or 3.2 core, but 3.2
// compatibility is not an option.
//#define USE_OPENGL_CORE_PROFILE
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
#if (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR))
#if (TARGET_OS_IPHONE == 1)
#define PLATFORM_IOS
#define OPENGL_ES
#ifdef USE_QT
#undef USE_QT
#endif
#ifdef USE_GLEW
#undef USE_GLEW
#endif
#ifdef USE_GLEW_LOCAL
#undef USE_GLEW_LOCAL
#endif
#endif
#endif
/*
* No editing needed from here on!
*/
#ifdef USE_GLEW
#ifdef USE_GLEW_LOCAL
#error "OpenGLWrapper.hh: Don't include glew from your OS AND a local glew version..."
#endif
#endif
// we have allways to include glew first!
#ifdef USE_GLEW
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/glew.h>
#else
#include <GL/glew.h>
#endif
#endif // USE_GLEW
#ifdef USE_GLEW_LOCAL
#include GLEW_LOCAL_PATH
#endif // USE_GLEW_LOCAL
#ifdef USE_GL
#if defined(__APPLE__) || defined(MACOSX)
#ifdef OPENGL_ES
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#else
#ifdef USE_OPENGL_CORE_PROFILE
#include <GL3/gl3.h>
#else
#include <OpenGL/gl.h>
#endif
#endif
#else
#ifdef USE_OPENGL_CORE_PROFILE
#include <GL3/gl3.h>
#else
#include <GL/gl.h>
#endif
#endif
#endif // USE_GL
#ifdef USE_GLU
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
#endif
#endif // USE_GLU
#ifdef USE_GLUT
#if defined(__APPLE__) || defined(MACOSX)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#endif // USE_GLUT
#ifdef USE_QT
#include <QtOpenGL/qgl.h>
#endif // USE_QT
#endif // ACGL_GL_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_GLUTILS_CAMERA_HH
#define ACGL_GLUTILS_CAMERA_HH
#include <ACGL/Math/Math.hh>
namespace ACGL{
namespace GLUtils{
class Camera
{
public:
Camera(void)
: mRight (),
mUp (),
mForward (),
mWidth (800),
mHeight (600),
mFOV (75.0f),
mNear (0.1f),
mFar (10000.0f),
mPitch (0.0f),
mYaw (0.0f),
mRoll (0.0f),
mPosition (3.0f, 2.0f, 3.0f),
mTarget (0.0f, 0.0f, 0.0f)
{
updateLocalCoordinateSystemByTarget();
updateOrientationByLocalCoordinateSystem();
}
Camera(
int_t width,
int_t height,
float fov,
float near,
float far,
const glm::vec3& position,
const glm::vec3& target)
: mRight (),
mUp (),
mForward (),
mWidth (width),
mHeight (height),
mFOV (fov),
mNear (near),
mFar (far),
mPitch (0.0f),
mYaw (0.0f),
mRoll (0.0f),
mPosition (position),
mTarget (target)
{
updateLocalCoordinateSystemByTarget();
updateOrientationByLocalCoordinateSystem();
}
Camera(const Camera& other)
: mRight (other.mRight),
mUp (other.mUp),
mForward (other.mForward),
mWidth (other.mWidth),
mHeight (other.mHeight),
mFOV (other.mFOV),
mNear (other.mNear),
mFar (other.mFar),
mPitch (other.mPitch),
mYaw (other.mYaw),
mRoll (other.mRoll),
mPosition (other.mPosition),
mTarget (other.mTarget)
{
}
~Camera(void) {}
inline float getAspectRatio () const { return (float)mWidth / (float)mHeight; }
inline const glm::vec3& getUpDirection () const { return mUp; }
inline const glm::vec3& getRightDirection () const { return mRight; }
inline const glm::vec3& getForwardDirection () const { return mForward; }
inline int_t getWidth () const { return mWidth; }
inline int_t getHeight () const { return mHeight; }
inline float getFOV () const { return mFOV; }
inline float getNear () const { return mNear; }
inline float getFar () const { return mFar; }
inline float getPitch () const { return mPitch; }
inline float getYaw () const { return mYaw; }
inline float getRoll () const { return mRoll; }
inline const glm::vec3& getPosition () const { return mPosition; }
inline const glm::vec3& getTarget () const { return mTarget; }
inline void setWidth (int_t width) { mWidth = width; }
inline void setHeight (int_t height) { mHeight = height; }
inline void setFOV (float fov) { mFOV = fov; }
inline void setNear (float near) { mNear = near; }
inline void setFar (float far) { mFar = far; }
inline void setPitch (float pitch) { mPitch = pitch; }
inline void setYaw (float yaw) { mYaw = yaw; }
inline void setRoll (float roll) { mRoll = roll; }
inline void setPosition (const glm::vec3& position, bool moveTarget = true) { if(moveTarget) { mTarget += position - mPosition; } mPosition = position; }
inline void setTarget (const glm::vec3& target, bool movePosition = true) { if(movePosition) { mPosition += target - mTarget; } mTarget = target; }
inline void setPitchAroundTarget(float pitch)
{
mPitch = pitch;
updateLocalCoordinateSystemByOrientation();
mPosition = mTarget - glm::length(mTarget - mPosition) * mForward;
}
inline void setYawAroundTarget(float yaw)
{
mYaw = yaw;
updateLocalCoordinateSystemByOrientation();
mPosition = mTarget - glm::length(mTarget - mPosition) * mForward;
}
glm::mat4 getProjectionMatrix() const;
glm::mat4 getViewMatrix() const;
glm::mat4 getInverseViewMatrix() const;
void updateLocalCoordinateSystemByTarget(const glm::vec3& up = glm::vec3(0.0f, 1.0f, 0.0f));
void updateLocalCoordinateSystemByOrientation(bool moveTarget = true);
void updateOrientationByLocalCoordinateSystem();
private:
glm::vec3 mRight;
glm::vec3 mUp;
glm::vec3 mForward;
int_t mWidth;
int_t mHeight;
float mFOV;
float mNear;
float mFar;
float mPitch;
float mYaw;
float mRoll;
glm::vec3 mPosition;
glm::vec3 mTarget;
};
} // GLUtils
} // ACGL
#endif // ACGL_GLUTILS_CAMERA_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_GLUTILS_COORDINATESYSTEM_HH
#define ACGL_GLUTILS_COORDINATESYSTEM_HH
#include <ACGL/Math/Math.hh>
#include <ACGL/Types.hh>
#include <vector>
namespace ACGL{
namespace GLUtils{
class CoordinateSystem
{
public:
CoordinateSystem(int_t outerLines = 100, int_t innerRange = 2)
: mOuterLines(outerLines),
mInnerRange(innerRange),
mInnerLines((innerRange * 2 + 1) * 10),
mInterpolC(0.0f),
mOuterLinesCA(mOuterLines * 2),
mOuterLinesCB(mOuterLines * 2),
mInnerLinesCA(mInnerLines * 2),
mInnerLinesCB(mInnerLines * 2)
{}
~CoordinateSystem() {}
/*! Adjust the grid concerning the given absolut position */
template<int_t A, int_t B, int_t C>
void adjust(const glm::vec3& pos, const glm::vec3& forward);
inline int_t getOuterLines() const { return mOuterLines; }
inline int_t getInnerLines() const { return mInnerLines; }
inline float getInterpolC() const { return mInterpolC; }
inline const std::vector<glm::vec3>& getOuterLinesCA() const { return mOuterLinesCA; }
inline const std::vector<glm::vec3>& getOuterLinesCB() const { return mOuterLinesCB; }
inline const std::vector<glm::vec3>& getInnerLinesCA() const { return mInnerLinesCA; }
inline const std::vector<glm::vec3>& getInnerLinesCB() const { return mInnerLinesCB; }