hello.cpp

00001 
00002 /* Copyright (c) 2007, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016 
00017  *
00018  * Equalizer 'Hello, World!' example. Shows the minimum Equalizer program,
00019  * rendering spinning quads around the origin.
00020  */
00021 
00022 #include <eq/eq.h>
00023 #include <stdlib.h>
00024 
00025 using namespace eq::base;
00026 using namespace std;
00027 
00028 class Channel : public eq::Channel
00029 {
00030 public:
00031     Channel( eq::Window* parent ) : eq::Channel( parent ) {}
00032 
00033 protected:
00034     virtual void frameDraw( const uint32_t spin );
00035 };
00036 
00037 class NodeFactory : public eq::NodeFactory
00038 {
00039 public:
00040     virtual eq::Channel* createChannel( eq::Window* parent )
00041         { return new Channel( parent ); }
00042 };
00043 
00044 int main( const int argc, char** argv )
00045 {
00046     // 1. Equalizer initialization
00047     NodeFactory nodeFactory;
00048     if( !eq::init( argc, argv, &nodeFactory ))
00049     {
00050         EQERROR << "Equalizer init failed" << endl;
00051         return EXIT_FAILURE;
00052     }
00053     
00054     // 2. get a configuration
00055     bool        error  = false;
00056     eq::Config* config = eq::getConfig( argc, argv );
00057     if( config )
00058     {
00059         // 3. init config
00060         if( config->init( 0 ))
00061         {
00062             // 4. run main loop
00063             uint32_t spin = 0;
00064             while( config->isRunning( ))
00065             {
00066                 config->startFrame( ++spin );
00067                 config->finishFrame();
00068             }
00069         
00070             // 5. exit config
00071             config->exit();
00072         }
00073         else
00074         {
00075             EQERROR << "Config initialization failed: " 
00076                     << config->getErrorMessage() << endl;
00077             error = true;
00078         }
00079 
00080         // 6. release config
00081         eq::releaseConfig( config );
00082     }
00083     else
00084     {
00085         EQERROR << "Cannot get config" << endl;
00086         error = true;
00087     }    
00088 
00089     // 7. exit
00090     eq::exit();
00091     return error ? EXIT_FAILURE : EXIT_SUCCESS;
00092 }
00093 
00095 void Channel::frameDraw( const uint32_t spin )
00096 {
00097     // setup OpenGL State
00098     eq::Channel::frameDraw( spin );
00099     
00100     const float lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
00101     glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
00102 
00103     const float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
00104     glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
00105 
00106     // rotate scene around the origin
00107     glRotatef( static_cast< float >( spin ) * 0.1f, 1.0f, 0.5f, 0.25f );
00108 
00109     // render six axis-aligned colored quads around the origin
00110     //  front
00111     glColor3f( 1.0f, 0.5f, 0.5f );
00112     glNormal3f( 0.0f, 0.0f, 1.0f );
00113     glBegin( GL_TRIANGLE_STRIP );
00114     glVertex3f(  .7f,  .7f, -1.0f );
00115     glVertex3f( -.7f,  .7f, -1.0f );
00116     glVertex3f(  .7f, -.7f, -1.0f );
00117     glVertex3f( -.7f, -.7f, -1.0f );
00118     glEnd();
00119 
00120     //  bottom
00121     glColor3f( 0.5f, 1.0f, 0.5f );
00122     glNormal3f( 0.0f, 1.0f, 0.0f );
00123     glBegin( GL_TRIANGLE_STRIP );
00124     glVertex3f(  .7f, -1.0f,  .7f );
00125     glVertex3f( -.7f, -1.0f,  .7f );
00126     glVertex3f(  .7f, -1.0f, -.7f );
00127     glVertex3f( -.7f, -1.0f, -.7f );
00128     glEnd();
00129 
00130     //  back
00131     glColor3f( 0.5f, 0.5f, 1.0f );
00132     glNormal3f( 0.0f, 0.0f, -1.0f );
00133     glBegin( GL_TRIANGLE_STRIP );
00134     glVertex3f(  .7f,  .7f, 1.0f );
00135     glVertex3f( -.7f,  .7f, 1.0f );
00136     glVertex3f(  .7f, -.7f, 1.0f );
00137     glVertex3f( -.7f, -.7f, 1.0f );
00138     glEnd();
00139 
00140     //  top
00141     glColor3f( 1.0f, 1.0f, 0.5f );
00142     glNormal3f( 0.f, -1.f, 0.f );
00143     glBegin( GL_TRIANGLE_STRIP );
00144     glVertex3f(  .7f, 1.0f,  .7f );
00145     glVertex3f( -.7f, 1.0f,  .7f );
00146     glVertex3f(  .7f, 1.0f, -.7f );
00147     glVertex3f( -.7f, 1.0f, -.7f );
00148     glEnd();
00149 
00150     //  right
00151     glColor3f( 1.0f, 0.5f, 1.0f );
00152     glNormal3f( -1.f, 0.f, 0.f );
00153     glBegin( GL_TRIANGLE_STRIP );
00154     glVertex3f( 1.0f,  .7f,  .7f );
00155     glVertex3f( 1.0f, -.7f,  .7f );
00156     glVertex3f( 1.0f,  .7f, -.7f );
00157     glVertex3f( 1.0f, -.7f, -.7f );
00158     glEnd();
00159 
00160     //  left
00161     glColor3f( 0.5f, 1.0f, 1.0f );
00162     glNormal3f( 1.f, 0.f, 0.f );
00163     glBegin( GL_TRIANGLE_STRIP );
00164     glVertex3f( -1.0f,  .7f,  .7f );
00165     glVertex3f( -1.0f, -.7f,  .7f );
00166     glVertex3f( -1.0f,  .7f, -.7f );
00167     glVertex3f( -1.0f, -.7f, -.7f );
00168     glEnd();
00169 }
Generated on Mon Aug 10 18:58:39 2009 for Equalizer 0.9 by  doxygen 1.5.8