diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Main.cpp | 5 | ||||
| -rwxr-xr-x | genmake.sh | 97 | ||||
| m--------- | glox | 0 | ||||
| m--------- | slox | 0 | ||||
| -rw-r--r-- | sons_of_sol/SonsOfSolApplication.hpp | 106 | ||||
| -rw-r--r-- | sons_of_sol/private_db/SonsOfSolApplication.cpp | 114 | ||||
| -rw-r--r-- | stars.bmp | bin | 0 -> 786570 bytes |
8 files changed, 324 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d772925 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.swp +*.swo @@ -37,6 +37,9 @@ public: void onEvent( const SDL_Event& event ) { SloxRawEventHandler::onEvent( event ); } bool initialize( int argc, char** argv ) { + (void) argc; + (void) argv; + unsigned int tex = 0; SDL_Init( SDL_INIT_VIDEO ); @@ -78,10 +81,10 @@ public: } bool loop( uint32_t ticks ) { + (void) ticks; /* Set some parameters */ GloxState::clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); GloxState::enable( GL_DEPTH_TEST ); - // GloxState::enable( GL_CULL_FACE ); GloxState::loadIdentity(); /* Translate to the this perspective */ diff --git a/genmake.sh b/genmake.sh new file mode 100755 index 0000000..f484e9e --- /dev/null +++ b/genmake.sh @@ -0,0 +1,97 @@ +#!/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 + +BINARY_NAME="SonsOfSol" + +obs=() +src=() +libs=() + +function generate_depends { + # get the dependencies of the dependencies + if [ ! -f $1 ] ; then + return ; + fi + + 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 ]] ; 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 Main.cpp sons_of_sol/ | 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 "CFLAGS=$CFLAGS -Wall -Wextra -I. -g3 -ggdb -D DEBUG_LEVEL_TRACE -Islox -Iglox">&3 +echo "LDFLAGS=$LDFLAGS -Lslox -Lglox -lslox -lglox -lGL -lGLU -lSDL -lm">&3 +echo 'OBJECTS='${obs[@]}>&3 +echo 'BINARY='$BINARY_NAME>&3 + +# Add all, setup and clean rules +echo -e \ +'all: submodules setup $(OBJECTS) + $(CPPC) -o $(BINARY) $(OBJECTS) $(LDFLAGS) +'>&3 + +echo -e 'genmake:\n\tfind . -name genmake.sh -exec {} \;\n'>&3 +echo -e 'setup:\n\tmkdir -p obs/\n'>&3 + +echo -e \ +'submodules: + for i in $$(find */ -name Makefile) ; do \ + pushd $$(dirname $$i) && make && popd; \ + done +'>&3 + +echo -e \ +'clean: + - rm -rf obs $(BINARY) + for i in $$(find */ -name Makefile) ; do \ + pushd $$(dirname $$i) && make clean && popd; \ + done'>&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 b/glox -Subproject f6ceb6aaaba75961d3e9739766b986b00acf827 +Subproject 06b216d01ebcf4fb5aa3d4540ef084d6a0a8595 diff --git a/slox b/slox -Subproject 94d66617886e7bf03d667c28c047a7c31ad640f +Subproject 6a40f5305d038001c750c4b8a623bd16d735556 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(); +} diff --git a/stars.bmp b/stars.bmp Binary files differnew file mode 100644 index 0000000..abc0157 --- /dev/null +++ b/stars.bmp |