From 306bb687414f54177eb37ab7cd744e491c397c31 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Tue, 23 Dec 2025 12:55:48 -0700 Subject: Inline submodules. Slox and Glox are not used anywhere else anymore --- .gitmodules | 6 - glox | 1 - glox/Makefile | 66 +++++ glox/README.txt | 39 +++ glox/compat/glox/GloxLightSource.hpp | 95 +++++++ glox/compat/glox/GloxLightSourceManager.hpp | 50 ++++ glox/compat/glox/objects/GloxCube.hpp | 56 ++++ glox/compat/glox/objects/GloxSphere.hpp | 20 ++ glox/compat/glox/objects/GloxTexturedCube.hpp | 125 +++++++++ glox/compat/glox/objects/GloxTexturedSphere.hpp | 52 ++++ glox/compat/glox/objects/examples/GloxCylinder.hpp | 83 ++++++ glox/genmake.sh | 77 ++++++ glox/glox/GloxColor.hpp | 112 ++++++++ glox/glox/GloxCommon.hpp | 73 +++++ glox/glox/GloxDebug.hpp | 74 +++++ glox/glox/GloxFirstPersonPerspective.hpp | 64 +++++ glox/glox/GloxLookAtPerspective.hpp | 62 +++++ glox/glox/GloxNormal.hpp | 138 ++++++++++ glox/glox/GloxObject.hpp | 29 ++ glox/glox/GloxPerspective.hpp | 51 ++++ glox/glox/GloxPlottable.hpp | 23 ++ glox/glox/GloxPoint.hpp | 231 ++++++++++++++++ glox/glox/GloxPointCollection.hpp | 103 +++++++ glox/glox/GloxPointNormal.hpp | 73 +++++ glox/glox/GloxPointNormalTexture.hpp | 50 ++++ glox/glox/GloxProgram.hpp | 86 ++++++ glox/glox/GloxQuadStrip.hpp | 61 +++++ glox/glox/GloxRenderable.hpp | 19 ++ glox/glox/GloxRotation.hpp | 39 +++ glox/glox/GloxScopedAttributes.hpp | 38 +++ glox/glox/GloxScopedBegin.hpp | 30 +++ glox/glox/GloxScopedRotation.hpp | 32 +++ glox/glox/GloxScopedTranslation.hpp | 31 +++ glox/glox/GloxShader.hpp | 47 ++++ glox/glox/GloxStandardProjection.hpp | 60 +++++ glox/glox/GloxState.hpp | 75 ++++++ glox/glox/GloxTexture.hpp | 29 ++ glox/glox/GloxTextureFactory.hpp | 48 ++++ glox/glox/GloxTextureRepeat.hpp | 59 ++++ glox/glox/GloxVector3.hpp | 86 ++++++ glox/glox/GloxVector4.hpp | 60 +++++ glox/glox/GloxVectorizable.hpp | 33 +++ glox/glox/GloxViewport.hpp | 37 +++ glox/glox/src/GloxCube.cpp | 82 ++++++ glox/glox/src/GloxCylinder.cpp | 56 ++++ glox/glox/src/GloxFirstPersonPerspective.cpp | 31 +++ glox/glox/src/GloxLightSource.cpp | 48 ++++ glox/glox/src/GloxLightSourceManager.cpp | 44 +++ glox/glox/src/GloxProgram.cpp | 89 ++++++ glox/glox/src/GloxShader.cpp | 71 +++++ glox/glox/src/GloxTextureFactory.cpp | 142 ++++++++++ glox/glox/src/GloxTexturedCube.cpp | 175 ++++++++++++ glox/glox/src/GloxTexturedSphere.cpp | 52 ++++ slox | 1 - slox/Makefile | 32 +++ slox/README.md | 6 + slox/genmake.sh | 78 ++++++ slox/slox/SloxApplication.hpp | 60 +++++ slox/slox/SloxCommon.hpp | 12 + slox/slox/SloxRawEventHandler.hpp | 57 ++++ slox/slox/SloxTextureFactory.hpp | 54 ++++ slox/slox/events/SloxFunctionQuitListener.hpp | 35 +++ slox/slox/events/SloxKeyListener.hpp | 29 ++ slox/slox/events/SloxMouseMotionListener.hpp | 25 ++ slox/slox/events/SloxQuitListener.hpp | 25 ++ slox/slox/events/SloxResizeListener.hpp | 21 ++ slox/slox/loader/SloxModelObject.hpp | 34 +++ slox/slox/loader/SloxObjectLoader.hpp | 106 ++++++++ slox/slox/loader/SloxObjectMaterial.hpp | 95 +++++++ slox/slox/loader/private_db/SloxObjectLoader.cpp | 300 +++++++++++++++++++++ slox/slox/private_db/SloxApplication.cpp | 38 +++ slox/slox/private_db/SloxRawEventHandler.cpp | 43 +++ slox/slox/private_db/SloxTextureFactory.cpp | 178 ++++++++++++ 73 files changed, 4634 insertions(+), 8 deletions(-) delete mode 160000 glox create mode 100644 glox/Makefile create mode 100644 glox/README.txt create mode 100644 glox/compat/glox/GloxLightSource.hpp create mode 100644 glox/compat/glox/GloxLightSourceManager.hpp create mode 100644 glox/compat/glox/objects/GloxCube.hpp create mode 100644 glox/compat/glox/objects/GloxSphere.hpp create mode 100644 glox/compat/glox/objects/GloxTexturedCube.hpp create mode 100644 glox/compat/glox/objects/GloxTexturedSphere.hpp create mode 100644 glox/compat/glox/objects/examples/GloxCylinder.hpp create mode 100755 glox/genmake.sh create mode 100644 glox/glox/GloxColor.hpp create mode 100644 glox/glox/GloxCommon.hpp create mode 100644 glox/glox/GloxDebug.hpp create mode 100644 glox/glox/GloxFirstPersonPerspective.hpp create mode 100644 glox/glox/GloxLookAtPerspective.hpp create mode 100644 glox/glox/GloxNormal.hpp create mode 100644 glox/glox/GloxObject.hpp create mode 100644 glox/glox/GloxPerspective.hpp create mode 100644 glox/glox/GloxPlottable.hpp create mode 100644 glox/glox/GloxPoint.hpp create mode 100644 glox/glox/GloxPointCollection.hpp create mode 100644 glox/glox/GloxPointNormal.hpp create mode 100644 glox/glox/GloxPointNormalTexture.hpp create mode 100644 glox/glox/GloxProgram.hpp create mode 100644 glox/glox/GloxQuadStrip.hpp create mode 100644 glox/glox/GloxRenderable.hpp create mode 100644 glox/glox/GloxRotation.hpp create mode 100644 glox/glox/GloxScopedAttributes.hpp create mode 100644 glox/glox/GloxScopedBegin.hpp create mode 100644 glox/glox/GloxScopedRotation.hpp create mode 100644 glox/glox/GloxScopedTranslation.hpp create mode 100644 glox/glox/GloxShader.hpp create mode 100644 glox/glox/GloxStandardProjection.hpp create mode 100644 glox/glox/GloxState.hpp create mode 100644 glox/glox/GloxTexture.hpp create mode 100644 glox/glox/GloxTextureFactory.hpp create mode 100644 glox/glox/GloxTextureRepeat.hpp create mode 100644 glox/glox/GloxVector3.hpp create mode 100644 glox/glox/GloxVector4.hpp create mode 100644 glox/glox/GloxVectorizable.hpp create mode 100644 glox/glox/GloxViewport.hpp create mode 100644 glox/glox/src/GloxCube.cpp create mode 100644 glox/glox/src/GloxCylinder.cpp create mode 100644 glox/glox/src/GloxFirstPersonPerspective.cpp create mode 100644 glox/glox/src/GloxLightSource.cpp create mode 100644 glox/glox/src/GloxLightSourceManager.cpp create mode 100644 glox/glox/src/GloxProgram.cpp create mode 100644 glox/glox/src/GloxShader.cpp create mode 100644 glox/glox/src/GloxTextureFactory.cpp create mode 100644 glox/glox/src/GloxTexturedCube.cpp create mode 100644 glox/glox/src/GloxTexturedSphere.cpp delete mode 160000 slox create mode 100644 slox/Makefile create mode 100644 slox/README.md create mode 100755 slox/genmake.sh create mode 100644 slox/slox/SloxApplication.hpp create mode 100644 slox/slox/SloxCommon.hpp create mode 100644 slox/slox/SloxRawEventHandler.hpp create mode 100644 slox/slox/SloxTextureFactory.hpp create mode 100644 slox/slox/events/SloxFunctionQuitListener.hpp create mode 100644 slox/slox/events/SloxKeyListener.hpp create mode 100644 slox/slox/events/SloxMouseMotionListener.hpp create mode 100644 slox/slox/events/SloxQuitListener.hpp create mode 100644 slox/slox/events/SloxResizeListener.hpp create mode 100644 slox/slox/loader/SloxModelObject.hpp create mode 100644 slox/slox/loader/SloxObjectLoader.hpp create mode 100644 slox/slox/loader/SloxObjectMaterial.hpp create mode 100644 slox/slox/loader/private_db/SloxObjectLoader.cpp create mode 100644 slox/slox/private_db/SloxApplication.cpp create mode 100644 slox/slox/private_db/SloxRawEventHandler.cpp create mode 100644 slox/slox/private_db/SloxTextureFactory.cpp diff --git a/.gitmodules b/.gitmodules index f1226c5..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "glox"] - path = glox - url = git@github.com:joshuarahm/glox.git -[submodule "slox"] - path = slox - url = git@github.com:joshuarahm/slox.git diff --git a/glox b/glox deleted file mode 160000 index f095e4f..0000000 --- a/glox +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f095e4f1231278a2e5937500dfc72d393c3ed453 diff --git a/glox/Makefile b/glox/Makefile new file mode 100644 index 0000000..262a94b --- /dev/null +++ b/glox/Makefile @@ -0,0 +1,66 @@ +CPPC?=g++ +AR?=ar +OPTFLAGS?=-g3 -ggdb +CFLAGS= -Wall -Wextra -Icompat -I. $(OPTFLAGS) -D DEBUG_LEVEL_TRACE -Islox -Iglox +LDFLAGS= +OBJECTS=obs/GloxCube.o obs/GloxFirstPersonPerspective.o obs/GloxTexturedCube.o obs/GloxShader.o obs/GloxCylinder.o obs/GloxProgram.o obs/GloxLightSource.o obs/GloxTexturedSphere.o obs/GloxLightSourceManager.o obs/GloxTextureFactory.o +BINARY=libglox.a +all: setup $(OBJECTS) + $(AR) -r $(BINARY) $(OBJECTS) + +setup: + mkdir -p obs/ + +clean: + - rm -rf obs $(BINARY) + +obs/GloxCube.o: ./glox/src/GloxCube.cpp \ + glox/GloxScopedBegin.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxFirstPersonPerspective.o: ./glox/src/GloxFirstPersonPerspective.cpp \ + glox/GloxCommon.hpp \ + glox/GloxFirstPersonPerspective.hpp \ + glox/GloxState.hpp \ + glox/GloxDebug.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxTexturedCube.o: ./glox/src/GloxTexturedCube.cpp \ + glox/GloxScopedBegin.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxShader.o: ./glox/src/GloxShader.cpp \ + glox/GloxShader.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxCylinder.o: ./glox/src/GloxCylinder.cpp \ + glox/GloxDebug.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxProgram.o: ./glox/src/GloxProgram.cpp \ + glox/GloxProgram.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxLightSource.o: ./glox/src/GloxLightSource.cpp \ + glox/GloxDebug.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxTexturedSphere.o: ./glox/src/GloxTexturedSphere.cpp \ + glox/GloxCommon.hpp \ + glox/GloxPoint.hpp \ + glox/GloxNormal.hpp \ + glox/GloxPointNormalTexture.hpp \ + glox/GloxScopedAttributes.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxLightSourceManager.o: ./glox/src/GloxLightSourceManager.cpp \ + glox/GloxState.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + +obs/GloxTextureFactory.o: ./glox/src/GloxTextureFactory.cpp \ + glox/GloxTextureFactory.hpp \ + glox/GloxTexture.hpp \ + glox/GloxCommon.hpp \ + glox/GloxDebug.hpp + $(CPPC) $(CFLAGS) -o $@ -c $< + diff --git a/glox/README.txt b/glox/README.txt new file mode 100644 index 0000000..895b44c --- /dev/null +++ b/glox/README.txt @@ -0,0 +1,39 @@ +LibGlox - GL Object eXtension +----------------------------- + +LibGlox is an extension to OpenGL which wraps the +API in a friendlier, object-oriented framework which +abstracts away much of the OpenGL state machine to +make it harder to shoot yourself in the foot. + +Much of library is inlined, which means that the performance +hit from the abstraction layer is minimal. + +In order to build LibGlox, you must first generate the Makfile; this +is easy, just run ./genmake.sh from terminal then run make. + +This will produce a static library to statically link against, unfortunately +as of now, there is no shared library :-( It should, however, be trivial to change +the makefile to build one. + + +Developer Stuff +--------------- + +There are 3 main types of "drawable" objects in Glox. + +The first class is Plottable (GloxPlottable) objects. These +objects will simply and dumbly plot, they effect the OpenGL state +machine minimally; mostly restricted to points and normals. +However; plottable objects are very dependent +on the state of the state machine before they plot. Examples +of plottable objects are GloxPoint and GloxNormal. + +The second class is Renderable (GloxRenderable) objects. These +objects will change the state of the GL state machine. Examples +of renderable objects are GloxPerspective and GloxColor. + +Finally, the third class is full blown objects (GloxObjects) they are +similar to plottable, however they should not depend on the +original state of the StateMachine and ideally should restore +the StateMachine to the state it was in if possible diff --git a/glox/compat/glox/GloxLightSource.hpp b/glox/compat/glox/GloxLightSource.hpp new file mode 100644 index 0000000..59331f9 --- /dev/null +++ b/glox/compat/glox/GloxLightSource.hpp @@ -0,0 +1,95 @@ +#ifndef GLOXLIGHT_HPP_ +#define GLOXLIGHT_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * GloxLight.hpp: + */ + +#include "glox/GloxPoint.hpp" +#include "glox/GloxColor.hpp" +#include "glox/GloxRenderable.hpp" + +#include + +namespace glox { + +class GloxLightSource { +public: + /* Create a new light source using the light_id + * that is to be used in OpenGl */ + inline GloxLightSource( GLenum light_id ) : + m_light( light_id ) {} + + /* Sets the color of this light + * source */; + void setColor( const GloxColor& color ); + + /* Sets the position of a point */ + void setPosition( const GloxPoint<>& position, bool directional=false ) { + m_pos = position; + this->directional = directional; + } + + inline const GloxPointf& getPosition() { return m_pos ; } + + /* Sets whether this light is + * enabled or not */ + inline void setEnabled( bool enabled ) { + this->enabled = enabled; + } + + /* True if this light is enabled */ + inline bool isEnabled() const { + return this->enabled; + } + + inline void setAmbient( const GloxColor& color ) { + this->ambient = color; + } + + inline void setDiffuse( const GloxColor& color ) { + this->diffuse = color; + } + + inline void setSpecular( const GloxColor& color ) { + this->specular = color; + } + + inline void setLightModelAttribute( GLenum attr, float value ) { + lightModelsAttrs[attr] = value; + } + + inline void setLightModelAttribute( GLenum attr, const GloxColor& color ) { + lightModelsAttrs_vectors[attr] = color; + } + + /* Reder this light source */ + void render() const ; + +private: + typedef std::map M_lm_map_t; + typedef std::map< GLenum,GloxColor > M_lm_map_vec_t; + + GLenum m_light; + + GloxPoint<> m_pos; + bool directional; + + /* The index of this light source */ + int index; + bool enabled; + + /* Colors for different attributes */ + GloxColor ambient; + GloxColor diffuse; + GloxColor specular; + + M_lm_map_t lightModelsAttrs; + M_lm_map_vec_t lightModelsAttrs_vectors; +}; + +} + +#endif /* GLOXLIGHT_HPP_ */ diff --git a/glox/compat/glox/GloxLightSourceManager.hpp b/glox/compat/glox/GloxLightSourceManager.hpp new file mode 100644 index 0000000..27037c5 --- /dev/null +++ b/glox/compat/glox/GloxLightSourceManager.hpp @@ -0,0 +1,50 @@ +#ifndef GLOXLIGHTSOURCEMANAGER_HPP_ +#define GLOXLIGHTSOURCEMANAGER_HPP_ + +#define GLOX_MAX_NUM_LIGHTS 8 + +/* + * Author: jrahm + * created: 2013/10/23 + * GloxLightSourceManager.hpp: + */ + +#include "glox/GloxCommon.hpp" +#include "glox/GloxLightSource.hpp" +#include "glox/GloxRenderable.hpp" + +namespace glox { + +/* Since there are a finite number of light + * sources in OpenGL, they must be managed + * and allocated through this GloxLightSourceManager + */ +class GloxLightSourceManager : public GloxRenderable { +public: + inline GloxLightSourceManager() { + /* Initialize the arry of LightSources to + * NULL */ + for( size_t i = 0; i < GLOX_MAX_NUM_LIGHTS; ++ i ) { + m_sources[i] = NULL; + } + } + + /* Renders the lighting for this GloxLightSourceManager. + * This will render the scene with the lights in this + * manager and only the lights in this manager */ + void render() const ; + + /* Returns the light source with + * the ID `id'. Valid ID's are + * 0-7. An invalid id will return + * NULL. */ + GloxLightSource* getLightSource( int id ) ; + +private: + /* The sources of light */ + GloxLightSource* m_sources[ GLOX_MAX_NUM_LIGHTS ]; +}; + +} + +#endif /* GLOXLIGHTSOURCEMANAGER_HPP_ */ diff --git a/glox/compat/glox/objects/GloxCube.hpp b/glox/compat/glox/objects/GloxCube.hpp new file mode 100644 index 0000000..f0e8f51 --- /dev/null +++ b/glox/compat/glox/objects/GloxCube.hpp @@ -0,0 +1,56 @@ +#ifndef GLOXCUBE_HPP_ +#define GLOXCUBE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/28 + * GloxCube.hpp: This header contains the header for a cube class. + * This cube class does not have textures. For a textured cube, use + * GloxTexturedCube in GloxTexturedCube.hpp + */ + +#include "glox/GloxCommon.hpp" +#include "glox/GloxNormal.hpp" +#include "glox/GloxPoint.hpp" +#include "glox/GloxObject.hpp" +#include "glox/GloxColor.hpp" +#include "glox/GloxPointCollection.hpp" +#include "glox/GloxScopedAttributes.hpp" + +namespace glox { + +class GloxCube : public GloxObject { +public: + /* Creates a new cube with the size + * `size`. The size is the length of + * each side of the cube */ + GloxCube( float x, float y, float z, const GloxColor& color ); + + inline GloxCube( const GloxCube& other ) { + m_disp_list = other.m_disp_list ; + m_color = other.m_color; + } + + /* Draw this cube */ + void draw() const ; + + /* Sets the color of this cube */ + inline void setColor( const GloxColor& color ) { + m_color = color; + } + + /* Returns the color of this cube */ + inline const GloxColor& getColor() const { + return m_color; + } + +private: + int m_disp_list ; + /* The color of this cube */ + GloxColor m_color; +}; + +} + +#endif /* GLOXCUBE_HPP_ */ + diff --git a/glox/compat/glox/objects/GloxSphere.hpp b/glox/compat/glox/objects/GloxSphere.hpp new file mode 100644 index 0000000..cd1a97a --- /dev/null +++ b/glox/compat/glox/objects/GloxSphere.hpp @@ -0,0 +1,20 @@ +#ifndef GLOXSPHERE_HPP_ +#define GLOXSPHERE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * GloxSphere.hpp: Better implemenation of + * the Sphere.hpp + */ + +#include "glox/GloxObject" + +class GloxSphere : public GloxObject { +public: + GloxSphere( float radius, float res=2 ); + + void setTexture( const GloxTexture* texture ); +} + +#endif /* GLOXSPHERE_HPP_ */ diff --git a/glox/compat/glox/objects/GloxTexturedCube.hpp b/glox/compat/glox/objects/GloxTexturedCube.hpp new file mode 100644 index 0000000..c162fde --- /dev/null +++ b/glox/compat/glox/objects/GloxTexturedCube.hpp @@ -0,0 +1,125 @@ +#ifndef GLOXTEXTUREDCUBE_HPP_ +#define GLOXTEXTUREDCUBE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/28 + * GloxTexturedCube.hpp: This header contains the header for a cube class. + * This cube class does not have textures. For a textured cube, use + * GloxTexturedCube in GloxTexturedCube.hpp + */ + +#include "glox/GloxCommon.hpp" +#include "glox/GloxNormal.hpp" +#include "glox/GloxPoint.hpp" +#include "glox/GloxObject.hpp" +#include "glox/GloxColor.hpp" +#include "glox/GloxPointCollection.hpp" +#include "glox/GloxScopedAttributes.hpp" +#include "glox/GloxTextureRepeat.hpp" +#include "glox/GloxPointNormalTexture.hpp" +#include "glox/GloxDebug.hpp" + +namespace glox { + +class GloxTexturedCube : public GloxObject { +public: + /* Creates a new cube with the size + * `size`. The size is the length of + * each side of the cube */ + GloxTexturedCube( float size, const GloxColor& color, + const GloxTextureRepeat& topTex = GloxTextureRepeat(NULL), + const GloxTextureRepeat& botTex = GloxTextureRepeat(NULL), + const GloxTextureRepeat& frontTex = GloxTextureRepeat(NULL), + const GloxTextureRepeat& backTex = GloxTextureRepeat(NULL), + const GloxTextureRepeat& leftTex = GloxTextureRepeat(NULL), + const GloxTextureRepeat& rightTex = GloxTextureRepeat(NULL) ); + + /* Draw this cube */ + void draw() const ; + + /* Sets the color of this cube */ + inline void setColor( const GloxColor& color ) { + m_color = color; + } + + /* Returns the color of this cube */ + inline const GloxColor& getColor() const { + return m_color; + } + + inline void setTopTexture( const GloxTextureRepeat& top_tex ) { + m_top_tex = top_tex; + update_top(); + } + + inline void setBottomTexture( const GloxTextureRepeat& tex ) { + m_bottom_tex = tex; + update_bottom(); + } + + inline void setFrontTexture( const GloxTextureRepeat& tex ) { + m_front_tex = tex; + update_front(); + } + + inline void setBackTexture( const GloxTextureRepeat& tex ) { + m_back_tex = tex; + update_back(); + } + + inline void setRightTexture( const GloxTextureRepeat& tex ) { + m_right_tex = tex; + update_right(); + } + + inline void setLeftTexture( const GloxTextureRepeat& tex ) { + m_left_tex = tex; + update_left(); + } + +private: + void update_top(); + void update_bottom(); + void update_front(); + void update_back(); + void update_right(); + void update_left(); + + /* A typedef to make my life easier */ + typedef GloxPointCollection< GloxPointNormalTexture > _M_Square; + + inline void plot_with( const _M_Square& face, const GloxTextureRepeat& tex ) const; + + /* +/- y axis */ + _M_Square m_top; + _M_Square m_bottom; + + /* -/+ z axis */ + _M_Square m_front; + _M_Square m_back; + + /* -/+ x axis */ + _M_Square m_left; + _M_Square m_right; + + /* The textures for the various faces of + * the cube */ + GloxTextureRepeat m_top_tex; + GloxTextureRepeat m_bottom_tex; + GloxTextureRepeat m_front_tex; + GloxTextureRepeat m_back_tex; + GloxTextureRepeat m_left_tex; + GloxTextureRepeat m_right_tex; + + /* The color of this cube */ + GloxColor m_color; + + + float m_half; +}; + +} + +#endif /* GLOXTEXTUREDCUBE_HPP_ */ + diff --git a/glox/compat/glox/objects/GloxTexturedSphere.hpp b/glox/compat/glox/objects/GloxTexturedSphere.hpp new file mode 100644 index 0000000..d7a17e8 --- /dev/null +++ b/glox/compat/glox/objects/GloxTexturedSphere.hpp @@ -0,0 +1,52 @@ +#ifndef GLOXTEXTUREDSPHERE_HPP_ +#define GLOXTEXTUREDSPHERE_HPP_ + +/* + * Author: jrahm + * created: 2013/11/07 + * GloxTexturedSphere.hpp: + */ + +#include "glox/GloxTexture.hpp" +#include "glox/GloxObject.hpp" + +namespace glox { + +/* A sphere that has a texture mapped to it. + * The texture is mapped using a mercader projection + */ +class GloxTexturedSphere : public GloxObject { +public: + /* Create a new GloxTexturedSphere + * radius: the radius of the sphere + * res: the resolution of the sphere. Should + * be a factor of 360 + * */ + GloxTexturedSphere( float radius, float res, const GloxTexture& texture ); + + /* Draw this sphere */ + void draw() const; + + /* Returns teh radius of the sphere */ + inline float getRadius() const { return m_radius; } + + /* Set the radius of this sphere */ + inline void setRadius( float radius ) { m_radius = radius; } + + /* Returns the texture */ + inline const GloxTexture& getTexture() const { return m_texture; } + +private: + /* The texture of the sphere */ + GloxTexture m_texture; + + /* The radius */ + float m_radius; + + /* The display list of this sphere */ + int m_disp_list; +}; + +} + +#endif /* GLOXTEXTUREDSPHERE_HPP_ */ diff --git a/glox/compat/glox/objects/examples/GloxCylinder.hpp b/glox/compat/glox/objects/examples/GloxCylinder.hpp new file mode 100644 index 0000000..7436f8e --- /dev/null +++ b/glox/compat/glox/objects/examples/GloxCylinder.hpp @@ -0,0 +1,83 @@ +#ifndef GLOXCYLINDER_HPP_ +#define GLOXCYLINDER_HPP_ + +/* + * Author: jrahm + * created: 2013/10/24 + * GloxCylinder.hpp: + */ + +#include "glox/GloxObject.hpp" +#include "glox/GloxPointNormalTexture.hpp" + +#include "glox/GloxTexture.hpp" +#include "glox/GloxQuadStrip.hpp" + +#include "glox/GloxScopedTranslation.hpp" +#include "glox/GloxColor.hpp" + +#include "glox/GloxPoint.hpp" + +#ifndef COMPILING_CYLINDER +#warn "Do Not Use This Class, it is broken!" +#endif + +namespace glox { + +/* This is an example object that draws + * a cylinder. This object supports lighting + * and texturing */ +class GloxCylinder : public GloxObject { +public: + /* Creates a cylinder with the radius r and the height + * h. th_res specifies the radial resolution of this + * cylinder */ + GloxCylinder( const GloxPoint& pos, float r, float h, + float th_res=6, const GloxTexture* texture=NULL, bool normals=true, float rep=1, float repy=1 ); + + /* Get the position of this + * Cylinder */ + inline const GloxPoint& getPosition() const { + return m_position; + } + + /* Sets the position of this Cylinder */ + inline void setPosition( const GloxPoint& new_pos ) { + m_position = new_pos; + } + + inline void draw() const { + if( m_texture ) { + glEnable(GL_TEXTURE_2D); + m_texture->bind(); + } else { + glDisable(GL_TEXTURE_2D); + } + /* Color of the tree without a texture */ + static const GloxColor brown( 139, 69, 19 ); + /* Translate to the position of + * this object */ + GloxScopedTranslation trans( m_position ); + + /* Set the OpenGL state machine to + * use brown as the color */ + m_body.plot(); + glDisable(GL_TEXTURE_2D); + } + +private: + /* The position of this cylinder */ + GloxPoint m_position; + + /* the cylinder is basically just a quad + * strip. This object supports lighting, + * so the components are PointNormals */ + GloxQuadStrip< GloxPointNormalTexture > m_body; + + /* the texture used for ths cylinder */ + const GloxTexture* m_texture; +}; + +}; + +#endif /* GLOXCYLINDER_HPP_ */ diff --git a/glox/genmake.sh b/glox/genmake.sh new file mode 100755 index 0000000..3bf4b89 --- /dev/null +++ b/glox/genmake.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# Makefile for the GL Object eXtensions library + +# This bash file is used to generate the makefile +# to produce the library for the graphics library + +cd $(dirname $0) + +BINARY_NAME="libglox.a" + +obs=() +src=() + +function generate_depends { + # get the dependencies of the dependencies + next=$(cat $1 | gawk 'match($0, /#include "(.*)"/, m) { print m[1] }') + deps=$1 + for i in $next ; do + for canidate in $(generate_depends $i) ; do + if [[ ! $deps =~ $i ]] && [[ -e $i ]] ; then + deps="$deps \\$(echo -ne '\n ')$i" + fi + done + if [[ $? -ne 0 ]] ; then + echo "Failed to generate depends">&2 + return 1; + fi + done + echo "$deps" +} + +# Iterate through and find the +# c++ source files +for i in $(find . | egrep '.*\.c(pp|xx)?$') ; do + # add this file to the list of + # sources + echo "Generating from source file: $i" + deps="$(generate_depends $i)" + + # add the resulting object file to + # the objects + src[$cnt]=$deps + obs+=("obs/`basename $i | sed 's/\.c\(pp\|xx\)\?$/.o/g'`") + cnt=$[cnt + 1] +done + +# remove the Makefile if it exists +rm -f Makefile || true + +# open Makefile +exec 3<> Makefile + +# some commonly used files to generate +echo 'CPPC?=g++'>&3 +echo 'AR?=ar'>&3 +echo 'OPTFLAGS?=-g3 -ggdb'>&3 +echo "CFLAGS=$CFLAGS -Wall -Wextra -Icompat -I. "'$(OPTFLAGS)'" -D DEBUG_LEVEL_TRACE -Islox -Iglox">&3 +echo "LDFLAGS=$LDFLAGS">&3 +echo 'OBJECTS='${obs[@]}>&3 +echo 'BINARY='$BINARY_NAME>&3 + +# Add all, setup and clean rules +echo -e 'all: setup $(OBJECTS)\n\t$(AR) -r $(BINARY) $(OBJECTS)\n'>&3 +echo -e 'setup:\n\tmkdir -p obs/\n'>&3 +echo -e 'clean:\n\t- rm -rf obs $(BINARY)\n'>&3 + +# iterate through all of the objects and +# add a rule for the binary +for ((i=0;i<${#obs[@]};i++)) ; do + echo "Object file: ${obs[$i]}" + # add a rule for the new binary + echo -e "${obs[$i]}: ${src[$i]}\n\t"'$(CPPC) $(CFLAGS) -o $@ -c $<\n'>&3 +done + +# close Makefile +exec 3>&- diff --git a/glox/glox/GloxColor.hpp b/glox/glox/GloxColor.hpp new file mode 100644 index 0000000..11775d8 --- /dev/null +++ b/glox/glox/GloxColor.hpp @@ -0,0 +1,112 @@ +#ifndef GLOXCOLOR_HPP_ +#define GLOXCOLOR_HPP_ + +/* + * Author: jrahm + * created: 2013/10/23 + * GloxColor.hpp: + */ + +#include "glox/GloxCommon.hpp" +#include "glox/GloxRenderable.hpp" +#include "glox/GloxVectorizable.hpp" + +#include +#include + +namespace glox { + +/* This is a color class, it is for + * convinience */ +class GloxColor : public GloxRenderable,GloxVectorizable,GloxVectorizable { +public: + /* Creates a new color that is defined + * from the float values for r, g, b. The + * default value is an opaque black color */ + inline GloxColor( uint8_t r=0, uint8_t g=0, uint8_t b=0, uint8_t a=255 ) : + r( r ), g( g ), b( b ), a( a ) {} + + inline GloxColor( const GloxColor& color ) : + r( color.r ), g( color.g ), b( color.b ), a( color.a ) {} + + + + /* Get the components of this + * color */ + inline uint8_t getR() const { return r; } + inline uint8_t getG() const { return g; } + inline uint8_t getB() const { return b; } + inline uint8_t getA() const { return a; } + + inline void render() const { + if( a < 255 ) { + glColor4ub( r, g, b, a ); + } else { + glColor3ub( r, g, b ); + } + } + + + inline void scale( float f ) { scale2( f ); } + inline void scale( uint8_t f ) { scale2( f ); } + + virtual int toVector( float* arr, size_t len ) const { + if( len < 3 ) return -1; + arr[0] = r / 255.0; + arr[1] = g / 255.0; + arr[2] = b / 255.0; + if( len > 3 ) { + arr[3] = a / 255.0; + return 4; + } + return 3; + } + + virtual int toVector( uint8_t* arr, size_t len ) const { + if( len < 3 ) return -1; + arr[0] = r; + arr[1] = g; + arr[2] = b; + if( len > 3 ) { + arr[3] = a; + return 4; + } + return 3; + } + + inline GloxColor operator*( float value ) const { + GloxColor ret( * this ); + ret.scale2( value ); + return ret; + } + + inline std::string toString( ) const { + char buf[ 32 ]; + snprintf( buf, 32, "( %d, %d, %d, %d )\n", r, g, b, a ); + return std::string( buf ); + } + + inline GloxColor operator*( int value ) const { return (*this) * ((float)value); } + +private: + template + inline void scale2( NumT f ) { + int r1 = (int)(f * r); + int g1 = (int)(f * r); + int b1 = (int)(f * r); + int a1 = (int)(f * r); + r = r1 & 0xFF; + g = g1 & 0xFF; + b = b1 & 0xFF; + a = a1 & 0xFF; + } + + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +}; + +} + +#endif /* GLOXCOLOR_HPP_ */ diff --git a/glox/glox/GloxCommon.hpp b/glox/glox/GloxCommon.hpp new file mode 100644 index 0000000..77b1e82 --- /dev/null +++ b/glox/glox/GloxCommon.hpp @@ -0,0 +1,73 @@ +#ifndef GLOXCOMMON_HPP_ +#define GLOXCOMMON_HPP_ + +#include +#include +#include +#include +#include + +/* Include the OpenGL stuff */ + +#ifdef NO_USE_GLEW +#include +#else +#include +#endif + +/* + * Author: jrahm + * created: 2013/10/23 + * GloxCommon.hpp: + */ + +namespace glox { + #define GloxWith( en, code ) \ + { glBegin( en ) ; \ + code ;\ + glEnd(); } + + #define GloxEnableFor( en, code ) \ + { glEnable( en ) ; code ; glDisable( en ); } + + #define GloxDisableFor( en, code ) \ + { glDisable( en ) ; code ; glEnable( en ) ; } + + #define GloxWithTranslation( point, code ) \ + { \ + glox::GloxState::pushMatrix(); \ + glox::GloxState::translate( (point) ); \ + code; \ + glox::GloxState::popMatrix(); \ + } + #define GloxScale( amt, code ) \ + { \ + glox::GloxState::pushMatrix(); \ + glScalef( amt,amt,amt ); \ + code; \ + glox::GloxState::popMatrix(); \ + } + + typedef long long Glox64; + typedef unsigned long long Glox64u; + typedef int Glox32; + typedef unsigned int Glox32u; + typedef unsigned char Glox8u; + typedef signed char Glox8; + typedef unsigned short Glox16u; + typedef signed short Glox16; + + inline double GloxCos( double th ) { + return cos(3.1415927/180*(th)); + } + + inline double GloxSin( double th ) { + return sin(3.1415927/180*(th)); + } + + #define GloxToDegrees( th ) \ + ((180 * (th)) / 3.14159927) + +}; + +#endif /* GLOXCOMMON_HPP_ */ diff --git a/glox/glox/GloxDebug.hpp b/glox/glox/GloxDebug.hpp new file mode 100644 index 0000000..8b3f964 --- /dev/null +++ b/glox/glox/GloxDebug.hpp @@ -0,0 +1,74 @@ +#ifndef GLOXDEBUG_HPP_ +#define GLOXDEBUG_HPP_ + +/* + * Author: jrahm + * created: 2013/10/24 + * GloxDebug.hpp: + */ + +extern FILE* log_file; + +#ifdef DEBUG_LEVEL_TRACE +#define DEBUG_LEVEL 6 +#endif +#ifdef DEBUG_LEVEL_DEBUG +#define DEBUG_LEVEL 5 +#endif +#ifdef DEBUG_LEVEL_INFO +#define DEBUG_LEVEL 4 +#endif +#ifdef DEBUG_LEVEL_WARN +#define DEBUG_LEVEL 3 +#endif +#ifdef DEBUG_LEVEL_ERROR +#define DEBUG_LEVEL 2 +#endif +#ifdef DEBUG_LEVEL_FATAL +#define DEBUG_LEVEL 1 +#endif +#ifdef DEBUG_LEVEL_SILENT +#define DEBUG_LEVEL 0 +#endif + +#ifndef DEBUG_LEVEL +#define DEBUG_LEVEL 4 +#endif + +#if DEBUG_LEVEL > 5 +#define GloxTrace( category, fmt, ... ) if(1){ printf("[TRACE] (%s) - " fmt, category, ##__VA_ARGS__ ); } +#else +#define GloxTrace( category, fmt, ... ) +#endif + +#if DEBUG_LEVEL > 4 +#define GloxDebug( category, fmt, ... ) if(1){ printf("[DEBUG] (%s) - " fmt, category, ##__VA_ARGS__ ); } +#else +#define GloxDebug( category, fmt, ... ) +#endif + +#if DEBUG_LEVEL > 3 +#define GloxInfo( category, fmt, ... ) if(1){ printf("[INFO] (%s) - " fmt, category, ##__VA_ARGS__ ); } +#else +#define GloxInfo ( category, fmt, ... ) +#endif + +#if DEBUG_LEVEL > 2 +#define GloxWarn( category, fmt, ... ) if(1){ printf("[WARN] (%s) - " fmt, category, ##__VA_ARGS__ ); } +#else +#define GloxWarn( category, fmt, ... ) +#endif + +#if DEBUG_LEVEL > 1 +#define GloxError( category, fmt, ... ) if(1){ printf("[ERROR] (%s) - " fmt, category, ##__VA_ARGS__ ); } +#else +#define GloxError( category, fmt, ... ) +#endif + +#if DEBUG_LEVEL > 0 +#define GloxFatal( category, fmt, ... ) if(1){ printf("[FATAL] (%s) - " fmt, category, ##__VA_ARGS__ ); } +#else +#define GloxFatal( category, fmt, ... ) +#endif + +#endif /* GLOXDEBUG_HPP_ */ diff --git a/glox/glox/GloxFirstPersonPerspective.hpp b/glox/glox/GloxFirstPersonPerspective.hpp new file mode 100644 index 0000000..6effa3a --- /dev/null +++ b/glox/glox/GloxFirstPersonPerspective.hpp @@ -0,0 +1,64 @@ +#ifndef GLOXFIRSTPERSONPERSPECTIVE_HPP_ +#define GLOXFIRSTPERSONPERSPECTIVE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/29 + * GloxFirstPersonPerspective.hpp: + */ + +#include "glox/GloxPerspective.hpp" +#include "glox/GloxPoint.hpp" +#include "glox/GloxStandardProjection.hpp" +#include "glox/GloxVector3.hpp" + +namespace glox { + +class GloxFirstPersonPerspective : public GloxStandardProjection { +public: + inline GloxFirstPersonPerspective( + const GloxPoint<>& pos=GloxPoint<>(), + float roll=0, float pitch=0, float yaw=0, + float fov=50.0, float asp=1.8, float znear=0.1, float zfar=500.0 ) : + GloxStandardProjection( pos, fov, asp, znear, zfar ), + m_yaw( yaw ), m_pitch( pitch ), m_roll( roll ) {} + + inline void setYaw( float yaw ) { + m_yaw = yaw; + } + + inline void setPitch( float pitch ) { + m_pitch = pitch; + } + + inline void setRoll( float roll ) { + m_roll = roll; + } + + inline float getYaw() const { return m_yaw; } + inline float getPitch() const { return m_pitch; } + inline float getRoll() const { return m_roll; } + + /* adds a vector of rotations, expressed in + * terms or roll, pitch and yaw */ + inline void addRotationVector( const GloxVector3& vec ) { + m_roll += vec.get0(); + m_pitch += GloxCos( m_roll )*vec.get1() + GloxSin( m_roll )*vec.get2(); + m_yaw += GloxSin( m_roll )*vec.get1() + GloxCos( m_roll ) * vec.get2(); + } + + virtual void render() const; + + inline GloxPoint<> forward( float rad ) { + return GloxPoint<>::fromSpherical( rad, m_yaw, m_pitch ) + this->getPosition(); + } +private: + /* Rotations */ + float m_yaw; /* Horizontal rotation */ + float m_pitch; /* Up or down */ + float m_roll; +}; + +} + +#endif /* GLOXFIRSTPERSONPERSPECTIVE_HPP_ */ diff --git a/glox/glox/GloxLookAtPerspective.hpp b/glox/glox/GloxLookAtPerspective.hpp new file mode 100644 index 0000000..67d197b --- /dev/null +++ b/glox/glox/GloxLookAtPerspective.hpp @@ -0,0 +1,62 @@ +#ifndef GLOXLOOKATPERSPECTIVE_HPP_ +#define GLOXLOOKATPERSPECTIVE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/24 + * GloxLookAtPerspective.hpp: + */ + +#include + +#include "glox/GloxPerspective.hpp" +#include "glox/GloxState.hpp" +#include "glox/GloxStandardProjection.hpp" +#include "glox/GloxDebug.hpp" + +namespace glox { + +/* This is a projection which is a thin + * layer around gluLookAt */ +class GloxLookAtPerspective : public GloxStandardProjection { +public: + inline GloxLookAtPerspective( const GloxPoint<>& pos=GloxPoint<>(), + const GloxPoint<>& lookAt=GloxPoint<>(), const GloxPoint<>& upVec=GloxPoint<>( 0.0f, 1.0f, 0.0f ), + float fov=50.0, float asp=1.8, float zn=0.1, float zfar=500.0) : + GloxStandardProjection( pos, fov, asp, zn, zfar ), + m_LookAtPoint( lookAt ), m_UpVector( upVec ) {} + + inline virtual void render() const { +// GloxTrace( "GloxLookAtPerspective", "gluLookAt: %s %s %s\n", +// getPosition().toString().c_str(), m_LookAtPoint.toString().c_str(), +// m_UpVector.toString().c_str() ); + + gluLookAt( getPosition().getX(), getPosition().getY(), getPosition().getZ(), + m_LookAtPoint.getX(), m_LookAtPoint.getY(), m_LookAtPoint.getZ(), + m_UpVector.getX() , m_UpVector.getY() , m_UpVector.getZ() ); + } + + inline void setLookAtPoint( const GloxPoint<>& point ) { + m_LookAtPoint = point; + } + + inline const GloxPoint<>& getLookAtPoint() { + return m_LookAtPoint; + } + + inline void setUpVector( const GloxPoint<>& point ) { + m_UpVector = point; + } + + inline const GloxPoint<>& getUpVector() { + return m_UpVector; + } + +private: + GloxPoint<> m_LookAtPoint; + GloxPoint<> m_UpVector; +}; + +} + +#endif /* GLOXLOOKATPERSPECTIVE_HPP_ */ diff --git a/glox/glox/GloxNormal.hpp b/glox/glox/GloxNormal.hpp new file mode 100644 index 0000000..18fb709 --- /dev/null +++ b/glox/glox/GloxNormal.hpp @@ -0,0 +1,138 @@ +#ifndef GLOXNORMAL_HPP_ +#define GLOXNORMAL_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * GloxNormal.hpp: + */ + +#include "glox/GloxPlottable.hpp" + +#include +#include + +namespace glox { + +/* Type that the GloxNormal holds, + * defaults to an integer */ +template + +/* A normal in 3D space. This class + * implements Plottable which provides + * the `plot` function which calles + * glVertex on the components */ +class GloxNormal : public GloxPlottable { +public: + /* Creates a new GloxNormal from the components + * specified */ + inline GloxNormal( const NumT& x=0, const NumT& y=0, const NumT& z=0 ): + x(x), y(y), z(z) {} + + /* Copies the glox normal other */ + inline GloxNormal( const GloxNormal& other ) : + x(other.x), y(other.y), z(other.z) {} + + /* Returns the X componet of this + * normal */ + inline const NumT& getX() const { + return x; + } + + /* Returns the Y component of this + * normal */ + inline const NumT& getY() const { + return y; + } + + /* Returns the Z component of this + * normal */ + inline const NumT& getZ() const { + return z; + } + + /* Sets the X component of this + * normal */ + inline void setX( const NumT& x ) { + this->x = x; + } + + /* Sets the Y component of this normal */ + inline void setY( const NumT& y ) { + this->y = y; + } + + /* Sets the Z component of this + * normal */ + inline void setZ( const NumT& z ) { + this->z = z; + } + + /* Copy the normal `normal` into this + * normal */ + inline const GloxNormal& operator=( const GloxNormal& normal ) { + this->x = normal.x; + this->y = normal.y; + this->z = normal.z; + + return * this; + } + + /* Add the components of `normal` to this */ + inline GloxNormal& operator+=( const GloxNormal& normal ) { + this->x += normal.x; + this->y += normal.y; + this->z += normal.z; + + return * this; + } + + /* Returns a new GloxNormal that is the sum + * of this and `normal` */ + inline GloxNormal operator+( const GloxNormal& normal ) const { + GloxNormal ret; + ret += normal; + return ret; + } + + inline std::string toString() const { + std::stringstream stream; + stream << "( " << x << ", " << y << ", " << z << " )"; + return stream.str(); + } + + /* Plot this normal. This function depends on the + * number provided */ + inline void plot( ) const; + + /* Does exactly the same thing that plot does, but + * sometimes it is better to be more explicit about + * what plot is actually doing */ + inline void glNormal() const { plot() ; } +private: + NumT x; + NumT y; + NumT z; +}; + +/* Implementations of the plot functions for + * different template arguments */ +template <> +inline void GloxNormal::plot() const { + glNormal3i( this->getX(), this->getY(), this->getZ() ); +} +template <> +inline void GloxNormal::plot() const { + glNormal3f( this->getX(), this->getY(), this->getZ() ); +} +template <> +inline void GloxNormal::plot() const { + glNormal3s( this->getX(), this->getY(), this->getZ() ); +} +template +inline void GloxNormal::plot() const { + glNormal3d( this->getX(), this->getY(), this->getZ() ); +} + +} +#endif /* GLOXNORMAL_HPP_ */ diff --git a/glox/glox/GloxObject.hpp b/glox/glox/GloxObject.hpp new file mode 100644 index 0000000..3a9ef6e --- /dev/null +++ b/glox/glox/GloxObject.hpp @@ -0,0 +1,29 @@ +#ifndef GLOXOBJECT_HPP_ +#define GLOXOBJECT_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * GloxObject.hpp: + */ + +namespace glox { + +/* Similar to Plottable, but more strict. + * This object knows how to draw itself and that + * is all. + * + * An object should be all-inclusive, that is, + * unlike Plottable, GloxObject implies that + * the Object itself will only depend on the + * transformations of the OpenGL state machine + */ +class GloxObject { +public: + /* Draws this object */ + virtual void draw() const = 0; +}; + +} + +#endif /* GLOXOBJECT_HPP_ */ diff --git a/glox/glox/GloxPerspective.hpp b/glox/glox/GloxPerspective.hpp new file mode 100644 index 0000000..c22631e --- /dev/null +++ b/glox/glox/GloxPerspective.hpp @@ -0,0 +1,51 @@ +#ifndef GLOXPERSPECTIVE_HPP_ +#define GLOXPERSPECTIVE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/24 + * GloxPerspective.hpp: + */ + +#include "glox/GloxRenderable.hpp" +#include "glox/GloxPoint.hpp" + +namespace glox { + +/* This is an interface which describes + * what makes a camera perspective. The + * render() function will render the world + * from this perspective */ +class GloxPerspective : public GloxRenderable { +public: + /* Create a new Perspective at the location + * 'pos' */ + inline GloxPerspective( const GloxPoint<>& pos ) : + m_position( pos ) {} + + /* set the position of the perspective */ + inline void setPosition( const GloxPoint<>& pos ) { + m_position = pos; + } + + /* Returns the position of the Perspective */ + inline const GloxPoint<>& getPosition() const { + return m_position; + } + + /* This is called everytime the display + * function is called */ + virtual void render() const = 0; + + /* This renders a projection. This + * should be called if parameters + * change */ + virtual void project() const = 0; + +private: + GloxPoint<> m_position; +}; + +} + +#endif /* GLOXPERSPECTIVE_HPP_ */ diff --git a/glox/glox/GloxPlottable.hpp b/glox/glox/GloxPlottable.hpp new file mode 100644 index 0000000..15d5560 --- /dev/null +++ b/glox/glox/GloxPlottable.hpp @@ -0,0 +1,23 @@ +#ifndef PLOTTABLE_HPP_ +#define PLOTTABLE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * PointType.hpp: Holds the interface for al P + */ + +namespace glox { + +/* A plottable object is an object which + * can plot itself */ +class GloxPlottable { +public: + /* Plot this object on the + * space */ + virtual void plot() const = 0; +}; + +} + +#endif /* PLOTTABLE_HPP_ */ diff --git a/glox/glox/GloxPoint.hpp b/glox/glox/GloxPoint.hpp new file mode 100644 index 0000000..866d6ab --- /dev/null +++ b/glox/glox/GloxPoint.hpp @@ -0,0 +1,231 @@ +#ifndef GLOXPOINT_HPP_ +#define GLOXPOINT_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * GloxPoint.hpp: + */ + +#include "glox/GloxCommon.hpp" +#include "glox/GloxPlottable.hpp" +#include "glox/GloxVectorizable.hpp" +#include "glox/GloxVector4.hpp" + +#include +#include +#include + +#include + +namespace glox { + +/* Type that the GloxPoint holds, + * defaults to an integer */ +template + +/* A point in 3D space. This class + * implements Plottable which provides + * the `plot` function which calles + * glVertex on the components */ +class GloxPoint : public GloxPlottable,GloxVectorizable { +public: + inline static GloxPoint<> fromSpherical( NumT r, NumT th, NumT ph ) { + // double Ex = -2*dim*Sin(th)*Cos(ph); + // double Ey = +2*dim *Sin(ph); + // double Ez = +2*dim*Cos(th)*Cos(ph); + return GloxPoint<>( -r * GloxSin( th ) * GloxCos( ph ), + r * GloxSin( ph ), + r * GloxCos( th ) * GloxCos( ph ) ) ; + } + + inline static GloxPoint<> fromSpherical( const GloxVector4& vec ) { + return fromSpherical( vec.getX(), vec.getY(), vec.getZ() ); + } + + /* Creates a new GloxPoint from the components + * specified */ + inline GloxPoint( const NumT& x=0, const NumT& y=0, const NumT& z=0 ): + x(x), y(y), z(z) {} + + /* Copies the glox point other */ + inline GloxPoint( const GloxPoint& other ) : + x(other.x), y(other.y), z(other.z) {} + + /* Returns the X componet of this + * point */ + inline const NumT& getX() const { + return x; + } + + /* Returns the Y component of this + * point */ + inline const NumT& getY() const { + return y; + } + + /* Returns the Z component of this + * point */ + inline const NumT& getZ() const { + return z; + } + + /* Sets the X component of this + * point */ + inline void setX( const NumT& x ) { + this->x = x; + } + + /* Sets the Y component of this point */ + inline void setY( const NumT& y ) { + this->y = y; + } + + /* Sets the Z component of this + * point */ + inline void setZ( const NumT& z ) { + this->z = z; + } + + inline float getMagnitude() const { + return sqrt( x * x + y * y + z * z ) ; + } + + /* Copy the point `point` into this + * point */ + inline const GloxPoint& operator=( const GloxPoint& point ) { + this->x = point.x; + this->y = point.y; + this->z = point.z; + + return * this; + } + + /* Add the components of `point` to this */ + inline GloxPoint& operator+=( const GloxPoint& point ) { + this->x += point.x; + this->y += point.y; + this->z += point.z; + + return * this; + } + + /* Add the components of `point` to this */ + inline GloxPoint& operator-=( const GloxPoint& point ) { + this->x -= point.x; + this->y -= point.y; + this->z -= point.z; + + return * this; + } + + /* Returns a new GloxPoint that is the sum + * of this and `point` */ + inline GloxPoint operator+( const GloxPoint& point ) const { + GloxPoint ret = *this; + ret += point; + return ret; + } + + /* Returns a new GloxPoint that is the sum + * of this and `point` */ + inline GloxPoint operator-( const GloxPoint& point ) const { + GloxPoint ret = *this; + ret -= point; + return ret; + } + + inline GloxPoint& operator*=( NumT scalar ) { + x *= scalar; + y *= scalar; + z *= scalar; + return * this; + } + + inline GloxPoint operator*(NumT scalar) const { + GloxPoint ret = * this; + ret *= scalar; + return ret; + } + + inline NumT dot( const GloxPoint& other ) { + GloxPoint<> tmp1 = *this; + GloxPoint<> tmp2 = other; + + // std::cout << "Orig: " << this->toString() << ", " << other.toString() << std::endl; + tmp1.normalize(); + tmp2.normalize(); + + // std::cout << "Norm: " << this->toString() << ", " << other.toString() << std::endl;; + return tmp1.x * tmp2.x + + tmp1.y * tmp2.y + + tmp1.z * tmp2.z ; + } + + inline GloxPoint cross( const GloxPoint& other ) { + return GloxPoint( + y * other.z - z * other.y + , z * other.x - x * other.z + , x * other.y - y * other.x + ); + } + + inline void normalize() { + float mag = getMagnitude(); + + x = x / mag; + y = y / mag; + z = z / mag; + } + + inline std::string toString() const { + std::stringstream stream; + stream << "( " << x << ", " << y << ", " << z << " )"; + return stream.str(); + } + + virtual inline void scale( NumT amt ) { + x *= amt; y *= amt; z *= amt; + } + + int toVector( NumT* arr, size_t len ) const { + if( len < 3 ) return -1; + arr[0] = x; + arr[1] = y; + arr[2] = z; + return 3; + } + + /* Plot this point. This function depends on the + * number provided */ + inline void plot( ) const; +private: + NumT x; + NumT y; + NumT z; +}; + +typedef GloxPoint<> GloxPointf; + +/* Implementations of the plot functions for + * different template arguments */ +template <> +inline void GloxPoint::plot() const { + glVertex3i( this->getX(), this->getY(), this->getZ() ); +} +template <> +inline void GloxPoint::plot() const { + glVertex3f( this->getX(), this->getY(), this->getZ() ); +} +template <> +inline void GloxPoint::plot() const { + glVertex3s( this->getX(), this->getY(), this->getZ() ); +} +template +inline void GloxPoint::plot() const { + glVertex3d( this->getX(), this->getY(), this->getZ() ); +} + +} + +#endif /* GLOXPOINT_HPP_ */ diff --git a/glox/glox/GloxPointCollection.hpp b/glox/glox/GloxPointCollection.hpp new file mode 100644 index 0000000..f6a209a --- /dev/null +++ b/glox/glox/GloxPointCollection.hpp @@ -0,0 +1,103 @@ +#ifndef GLOXPOINTCOLLECTION_HPP_ +#define GLOXPOINTCOLLECTION_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * GloxPointCollection.hpp: + */ + +#include "glox/GloxPlottable.hpp" +#include "glox/GloxPoint.hpp" +#include "glox/GloxDebug.hpp" + +#include +#include +#include + +namespace glox { + +template < class PlottableT=GloxPoint > + +/* GloxPointCollection: a collection of Plottable that + * may be plotted in bulk */ +class GloxPointCollection : public GloxPlottable { +public: + /* Shorter vector term */ + typedef std::vector< PlottableT > m_Vec_t; + typedef typename m_Vec_t::iterator iterator; + typedef typename m_Vec_t::const_iterator const_iterator; + + /* Constructs a new GloxPointCollection with + * no Points */ + inline GloxPointCollection( ) { + // Nothing here for now + } + + /* Creates a new GloxPointCollection with the + * initial starting points `points` + */ + inline GloxPointCollection( const m_Vec_t& points ) { + this->points = points; + } + + /* Iterate through the vector of Plottable + * and call their plot functions */ + virtual void plot() const { + // GloxTrace( "GloxPointCollection", "plot(): this = %s\n", this->toString().c_str() ); + + for( const_iterator itr = this->begin(); itr != this->end(); ++ itr ) { + (*itr).plot(); + } + } + + /* Appends a point to this collection */ + virtual void add( const PlottableT& point ) { + this->points.push_back( point ); + } + + /* Returns an iterator for this + * GloxPointCollection */ + inline iterator begin() { + return points.begin(); + } + + /* Returns then end of the iterator */ + inline iterator end() { + return points.end(); + } + + inline void clear() { + points.clear(); + } + + /* Returns an iterator for this + * GloxPointCollection */ + inline const_iterator begin() const { + return points.begin(); + } + + /* Returns then end of the const_iterator */ + inline const_iterator end() const { + return points.end(); + } + + inline std::string toString() const { + std::stringstream stream; + stream << "[ "; + for( const_iterator itr = this->begin(); itr != this->end(); ++ itr ) { + stream << (*itr).toString() << ", "; + } + stream << "]"; + return stream.str(); + } + +private: + + /* The points to plot */ + m_Vec_t points; +}; + +}; + +#endif /* GLOXPOINTCOLLECTION_HPP_ */ diff --git a/glox/glox/GloxPointNormal.hpp b/glox/glox/GloxPointNormal.hpp new file mode 100644 index 0000000..256db75 --- /dev/null +++ b/glox/glox/GloxPointNormal.hpp @@ -0,0 +1,73 @@ +#ifndef GLOXPOINTNORMAL_HPP_ +#define GLOXPOINTNORMAL_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * GloxPointNormal.hpp: + */ + +#include "glox/GloxPlottable.hpp" +#include "glox/GloxPoint.hpp" +#include "glox/GloxNormal.hpp" + +#include +#include + +namespace glox { + +/* The number type used by both + * the point and the normal to use */ +template + +/* A class that couples a point with a normal. This + * is a useful wrapper over both a glVertex and glNormal + * functions */ +class GloxPointNormal : public GloxPlottable{ +public: + /* Creates a new point at the + * origin with no normal */ + GloxPointNormal( ) : + m_point(), m_normal() {} + + /* Creates a new GloxPointNormal at the point `point` + * and with the normal `normal` */ + GloxPointNormal( const GloxPoint& point, const GloxNormal& normal ) : + m_point( point ), m_normal( normal ) {} + + /* Plots a point and sets the + * normal for that point */ + inline void plot( ) const { + m_normal.plot(); + m_point.plot(); + } + + inline void setPoint( const GloxPoint& point ) { + m_point = point; + } + + inline void setNormal( const GloxNormal& normal ) { + m_normal = normal; + } + + inline const GloxPoint& getPoint () { + return m_point; + } + + inline const GloxNormal& getNormal() { + return m_normal; + } + + inline const std::string toString() const { + std::stringstream ret; + ret << "GloxPointNormal{ " << m_point.toString() << ", " << m_normal.toString() << " }" ; + return ret.str(); + } +private: + GloxPoint m_point; + GloxNormal m_normal; +}; + +} + +#endif /* GLOXPOINTNORMAL_HPP_ */ diff --git a/glox/glox/GloxPointNormalTexture.hpp b/glox/glox/GloxPointNormalTexture.hpp new file mode 100644 index 0000000..6bed16f --- /dev/null +++ b/glox/glox/GloxPointNormalTexture.hpp @@ -0,0 +1,50 @@ +#ifndef GLOXPOINTNORMALTEXTURE_HPP_ +#define GLOXPOINTNORMALTEXTURE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/24 + * GloxPointNormalTexture.hpp: + */ + +#include "glox/GloxPlottable.hpp" +#include "glox/GloxPointNormal.hpp" +#include "glox/GloxTexture.hpp" +#include "glox/GloxPoint.hpp" + +namespace glox { + +/* + * An aggregation of all of the following: + * A point, + * that points normal, + * the mapping of a texture to + * that point + */ +class GloxPointNormalTexture : public GloxPlottable { +public: + inline GloxPointNormalTexture( const GloxPointNormal<>& pointNormal, const GloxPoint<>& texPoint ) : + m_PointNormal( pointNormal ), m_TextureMap( texPoint ) { + } + + inline GloxPointNormalTexture( const GloxPoint<>& point, const GloxNormal<>& normal, const GloxPoint<>& texPoint ) : + m_PointNormal( point, normal ), m_TextureMap( texPoint ) {} + + inline void plot() const { + glTexCoord2f( m_TextureMap.getX(), m_TextureMap.getY() ); + m_PointNormal.plot(); + } + + inline const GloxPointNormal<>& getPointNormal() const { return m_PointNormal; } + inline const GloxPoint<>& getTexturePoint() const { return m_TextureMap; } + + inline GloxPointNormal<>& getPointNormal() { return m_PointNormal; } + inline GloxPoint<>& getTexturePoint() { return m_TextureMap; } +private: + GloxPointNormal<> m_PointNormal; + GloxPoint<> m_TextureMap; +}; + +} + +#endif /* GLOXPOINTNORMALTEXTURE_HPP_ */ diff --git a/glox/glox/GloxProgram.hpp b/glox/glox/GloxProgram.hpp new file mode 100644 index 0000000..e10f7ca --- /dev/null +++ b/glox/glox/GloxProgram.hpp @@ -0,0 +1,86 @@ +#ifndef GLOXPROGRAM_HPP_ +#define GLOXPROGRAM_HPP_ + +/* + * Author: jrahm + * created: 2013/12/09 + * GloxProgram.hpp: + */ + +#include "glox/GloxCommon.hpp" +#include "glox/GloxShader.hpp" +#include "glox/GloxVector3.hpp" +#include "glox/GloxVector4.hpp" +#include "glox/GloxPoint.hpp" + +#include + +namespace glox { + +class GloxProgram { +public: + GloxProgram( ) ; + + unsigned int getId() { + return id ; + } + + int attachShader( const GloxShader& shader ) ; + + int attachShaderFromFile( const char* filename, GLenum type ) ; + + int getUniformLocation( const char* uniform ) ; + + inline void setUniformFloat( int uniform, float fl ) { + glUniform1f( uniform, fl ) ; + } + + inline void setUniformInteger( int uniform, float i ) { + glUniform1f( uniform, i ) ; + } + + template + inline void setUniformVector3( int uniform, const Vectorizable3& point ) { + glUniform3f( uniform, point.getX(), point.getY(), point.getZ() ) ; + } + + template + inline void setUniformVector4( int uniform, const Vectorizable4& point ) { + float arr[4] ; + point.toVector( arr, 4 ) ; + glUniform4fv( uniform, 1, arr ) ; + } + + template + inline void setUniformVector3FromList( int uniform, const std::vector& vecs ) { + int len = vecs.size() * 3 ; + float* arr = new float[len] ; + + for ( size_t i = 0; i < vecs.size() ; ++ i ) { + vecs[i].toVector( arr + (i * 3), 3 ) ; + } + } + + template + inline void setUniformVector4FromList( int uniform, const std::vector& vecs ) { + int len = vecs.size() * 4 ; + float* arr = new float[len] ; + + for ( size_t i = 0; i < vecs.size() ; ++ i ) { + vecs[i].toVector( arr + (i * 3), 3 ) ; + } + }; + + void render() const ; + + int link(); + + static void unloadPrograms() ; +private: + + unsigned int id ; +}; + +} + +#endif /* GLOXPROGRAM_HPP_ */ diff --git a/glox/glox/GloxQuadStrip.hpp b/glox/glox/GloxQuadStrip.hpp new file mode 100644 index 0000000..6eb283e --- /dev/null +++ b/glox/glox/GloxQuadStrip.hpp @@ -0,0 +1,61 @@ +#ifndef QUADSTRIP_HPP_ +#define QUADSTRIP_HPP_ + +/* + * Author: jrahm + * created: 2013/10/22 + * QuadStrip.hpp: + */ + +#include +#include + +#include "glox/GloxPointCollection.hpp" + +namespace glox { + +template > + +/* This class represents a quad strip + * for OpenGL. This will draw a collection + * of points using GL_QUAD_STRIP + * + * This class extends Plottable wich + * means that it may be plotted, but + * that it IS dependent on state + * of the OpenGL machine */ +class GloxQuadStrip : public GloxPlottable { +public: + inline GloxQuadStrip() : + points() {} + /* Creates a new GloxQuadStrip with the points + * given as a vector as it's initial points */ + inline GloxQuadStrip( const std::vector< PlottableT >& points ) : + points( points ) {} + + /* Creates a new GloxQuadStrip with the points + * given as a collection of points */ + inline GloxQuadStrip( const GloxPointCollection& collection ) : + points( collection ) {} + + /* Plots the points as a GL_QUAD_STRIP */ + inline virtual void plot() const { + glBegin( GL_QUAD_STRIP ); + points.plot(); + glEnd(); + } + + /* Appends a point to the collection + * of points to plot */ + inline void addPoint( const PlottableT& point ) { + points.add( point ); + } + +private: + /* The points that make up this + * quad strip */ + GloxPointCollection points; +}; + +} +#endif /* QUADSTRIP_HPP_ */ diff --git a/glox/glox/GloxRenderable.hpp b/glox/glox/GloxRenderable.hpp new file mode 100644 index 0000000..cf1265b --- /dev/null +++ b/glox/glox/GloxRenderable.hpp @@ -0,0 +1,19 @@ +#ifndef GLOXRENDERABLE_HPP_ +#define GLOXRENDERABLE_HPP_ + +/* + * Author: jrahm + * created: 2013/10/23 + * GloxRenderable.hpp: + */ + +namespace glox { + +class GloxRenderable { +public: + virtual void render() const = 0; +}; + +} + +#endif /* GLOXRENDERABLE_HPP_ */ diff --git a/glox/glox/GloxRotation.hpp b/glox/glox/GloxRotation.hpp new file mode 100644 index 0000000..3dd9966 --- /dev/null +++ b/glox/glox/GloxRotation.hpp @@ -0,0 +1,39 @@ +#ifndef GLOXROTATION_HPP_ +#define GLOXROTATION_HPP_ + +/* + * Author: jrahm + * created: 2013/10/24 + * GloxRotation.hpp: + */ + +#include "glox/GloxCommon.hpp" + +namespace glox { + +class GloxRotation { +public: + inline GloxRotation( double ang, double x, double y, double z ) : + m_ang( ang ), m_x( x ), m_y( y ), m_z( z ) {} + + inline void render() const { glRotatef( m_ang, m_x, m_y, m_z ); } + + inline double getAngle() const { return m_ang; } + inline double getX() const { return m_x; } + inline double getY() const { return m_y; } + inline double getZ() const { return m_z; } + + inline void setAngle( double ang ) { m_ang = ang ; } + inline void setX( double x ) { m_x = x; } + inline void setY( double y ) { m_y = y; } + inline void setZ( double z ) { m_z = z; } +private: + double m_ang; + double m_x; + double m_y; + double m_z; +}; + +} + +#endif /* GLOXROTATION_HPP_ */ diff --git a/glox/glox/GloxScopedAttributes.hpp b/glox/glox/GloxScopedAttributes.hpp new file mode 100644 index 0000000..7491ad8 --- /dev/null +++ b/glox/glox/GloxScopedAttributes.hpp @@ -0,0 +1,38 @@ +#ifndef GLOXSCOPEDATTRIBUTES_HPP_ +#define GLOXSCOPEDATTRIBUTES_HPP_ + +/* + * Author: jrahm + * created: 2013/10/29 + * GloxScopedAttributes.hpp: + */ + +#include "glox/GloxCommon.hpp" + +namespace glox { + +/* A class, which on creation + * will push the specified attributes + * to the GL stack, and upon deletion + * will restore those attributes + * + * NOTE: When using this class, one should + * be wary of manually pushing and popping + * attributes from the GL stack. + */ +class GloxScopedAttributes { +public: + /* Push the attributes on the GL stack */ + inline GloxScopedAttributes( GLbitfield fields ) { + glPushAttrib( fields ); + } + + /* Restore the attributes *