aboutsummaryrefslogtreecommitdiff
path: root/sons_of_sol
diff options
context:
space:
mode:
authorJoshua Rahm <joshua.rahm@colorado.edu>2013-10-31 03:01:33 -0600
committerJoshua Rahm <joshua.rahm@colorado.edu>2013-10-31 03:01:33 -0600
commit88d0215624de994b4456c8eac537262118ffed52 (patch)
tree8c1567d1fd43a5fdf3e9ccfd3bc6d498f4aa3e0c /sons_of_sol
parent501e02f70c335602f11e4a4f59304cb0788a5986 (diff)
downloadSonsOfSol-88d0215624de994b4456c8eac537262118ffed52.tar.gz
SonsOfSol-88d0215624de994b4456c8eac537262118ffed52.tar.bz2
SonsOfSol-88d0215624de994b4456c8eac537262118ffed52.zip
Added more robust recursive make structure; started on SonsOfSol infrastructure
Diffstat (limited to 'sons_of_sol')
-rw-r--r--sons_of_sol/SonsOfSolApplication.hpp106
-rw-r--r--sons_of_sol/private_db/SonsOfSolApplication.cpp114
2 files changed, 220 insertions, 0 deletions
diff --git a/sons_of_sol/SonsOfSolApplication.hpp b/sons_of_sol/SonsOfSolApplication.hpp
new file mode 100644
index 0000000..1faeaa4
--- /dev/null
+++ b/sons_of_sol/SonsOfSolApplication.hpp
@@ -0,0 +1,106 @@
+#ifndef SONSOFSOLAPPLICATION_HPP_
+#define SONSOFSOLAPPLICATION_HPP_
+
+/*
+ * Author: jrahm
+ * created: 2013/10/31
+ * SonsOfSolApplication.hpp: <description>
+ */
+
+#include "slox/SloxApplication.hpp"
+#include "slox/SloxTextureFactory.hpp"
+#include "slox/SloxRawEventHandler.hpp"
+#include "slox/events/SloxFunctionQuitListener.hpp"
+
+#include "glox/GloxViewport.hpp"
+#include "glox/GloxCommon.hpp"
+#include "glox/GloxFirstPersonPerspective.hpp"
+#include "glox/objects/GloxTexturedCube.hpp"
+#include "glox/GloxColor.hpp"
+#include "glox/GloxLookAtPerspective.hpp"
+#include "glox/GloxLightSourceManager.hpp"
+
+class SonsOfSolApplication : public
+ slox::SloxApplication,
+ slox::SloxRawEventHandler,
+ slox::SloxQuitListener {
+public:
+ /* Process an event */
+ inline void onEvent( const SDL_Event& event )
+ { SloxRawEventHandler::onEvent( event ); }
+
+ /* Initializes this application;
+ * returns true if initialization
+ * succeeded, false otherwise */
+ bool initialize( int argc, char** argv );
+
+ /* The main loop of the application */
+ bool loop( uint32_t ticks ) {
+ /* Update things that we might
+ * want to */
+ update( ticks );
+
+ /* Some boilder OpenGL stuff */
+ glox::GloxState::clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glox::GloxState::enable( GL_DEPTH_TEST );
+ glox::GloxState::loadIdentity();
+
+ /* Display some stuff */
+ display();
+
+ /* Flush the buffers and
+ * do the appropriate delay */
+ glFlush();
+ SDL_GL_SwapBuffers();
+ SDL_Delay( 5 );
+
+ return !m_quit;
+ }
+
+ /* What happens when a quit event is
+ * intercepted */
+ inline void onQuit( const SDL_QuitEvent& evt ) {
+ (void) evt;
+ m_quit = true;
+ }
+
+ inline virtual ~SonsOfSolApplication() {
+
+ }
+
+private:
+
+ /* Resizes the perspective for OpenGL */
+ void reshape( int width, int height );
+
+ /* Sets up the lights to be used */
+ void enableLighting( );
+
+ void update( uint32_t ticks );
+
+ void display( ) ;
+
+ bool loadTextures();
+
+ /* perspective stuff */
+ glox::GloxViewport m_viewport;
+ glox::GloxLookAtPerspective m_perspective;
+
+ /* The sky */
+ glox::GloxTexturedCube* m_sky;
+
+ /* Textures */
+ glox::GloxTexture m_sky_tex;
+ glox::GloxTexture m_leaf_tex;
+ glox::GloxTexture m_cube_tex;
+
+ /* A boolean stating if it is time
+ * to quit */
+ bool m_quit;
+
+ glox::GloxLightSourceManager m_light_manager;
+
+ SDL_Surface* m_screen;
+};
+
+#endif /* SONSOFSOLAPPLICATION_HPP_ */
diff --git a/sons_of_sol/private_db/SonsOfSolApplication.cpp b/sons_of_sol/private_db/SonsOfSolApplication.cpp
new file mode 100644
index 0000000..f6a52c2
--- /dev/null
+++ b/sons_of_sol/private_db/SonsOfSolApplication.cpp
@@ -0,0 +1,114 @@
+#include "sons_of_sol/SonsOfSolApplication.hpp"
+
+#include "glox/GloxLightSource.hpp"
+
+using namespace slox;
+using namespace glox;
+
+bool SonsOfSolApplication::initialize( int argc, char** argv ) {
+ SDL_Init( SDL_INIT_VIDEO );
+ m_screen = SDL_SetVideoMode( 600, 600, 0, SDL_OPENGL|SDL_RESIZABLE|SDL_DOUBLEBUF );
+
+ m_perspective.setPosition( GloxPoint<>( 0, 0, 10 ) );
+
+ this->addQuitListener( this );
+
+ if( ! m_screen ) {
+ /* If the screen could not be initialized, print
+ * a useful video message */
+ this->setError( "Cannot set SDL video mode\n" );
+ return false;
+ }
+
+ SDL_WM_SetCaption( "Sons Of Sol", "" );
+ reshape( m_screen->w, m_screen->h );
+
+ /* Load the textures into memory */
+ if( ! loadTextures() ) return false;
+
+ GloxTextureRepeat texrep( &m_sky_tex, 3, 3 );
+ m_sky = new GloxTexturedCube( 900.0f, GloxColor( 255, 255, 255 ),
+ texrep, texrep, texrep, texrep, texrep, texrep );
+
+ m_quit = false;
+ return true;
+}
+
+#define NTEX 3
+bool SonsOfSolApplication::loadTextures() {
+ const char* files[NTEX] = {
+ "stars.bmp",
+ "leaf.bmp",
+ "crate.bmp"
+ };
+
+ GloxTexture* textures[NTEX] = {
+ &m_sky_tex,
+ &m_leaf_tex,
+ &m_cube_tex
+ };
+
+ unsigned int tex;
+
+ for ( int i = 0; i < NTEX; ++ i ) {
+ if( SloxTextureFactory::readBitmapFile( files[i], &tex ) ) {
+ /* Either there was a warning or an error, print out
+ * either */
+ fprintf( stderr, "Reading %s: %s\n", files[i], SloxTextureFactory::getMessage().c_str() );
+
+ if( tex == 0 ) {
+ /* If the texture hasn't changed, its an error, otherwise
+ * it's a warning, so continue */
+ this->setError( "Aborting: unable to load texture" );
+ return false;
+ }
+ }
+ textures[i]->setId( tex );
+ }
+
+ return true;
+}
+
+void SonsOfSolApplication::enableLighting() {
+ int ambient_coef = 30;
+ int diffuse_coef = 100;
+ int specular_coef = 0;
+
+ GloxLightSource* source = m_light_manager.getLightSource( 0 );
+
+ GloxColor base(2,2,2);
+ source->setAmbient ( base * ambient_coef );
+ source->setDiffuse ( base * diffuse_coef );
+ source->setSpecular( base * specular_coef );
+ source->setLightModelAttribute( GL_LIGHT_MODEL_LOCAL_VIEWER, 1 );
+ GloxTrace( "init", "Source=%p\n", source );
+ source->setEnabled( true );
+}
+
+void SonsOfSolApplication::update( uint32_t ticks ) {
+
+}
+
+void SonsOfSolApplication::display() {
+ /* Translate to the this perspective */
+ m_perspective.render();
+ m_sky->draw();
+
+ GloxColor( 255,255,255 ).render();
+
+ GloxWith( GL_QUADS, {
+ GloxPoint<>( 0,0,0 ).plot();
+ GloxPoint<>( 0,5,0 ).plot();
+ GloxPoint<>( 5,5,0 ).plot();
+ GloxPoint<>( 5,0,0 ).plot();
+ } );
+}
+
+void SonsOfSolApplication::reshape( int width, int height ) {
+ m_viewport.setWidth( width );
+ m_viewport.setHeight( height );
+
+ m_viewport.render();
+ m_perspective.setAspectRatio( m_viewport.getAspectRatio() );
+ m_perspective.project();
+}