Equalizer 1.0

hello.cpp

00001 
00002 /* Copyright (c) 2007, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *
00007  * - Redistributions of source code must retain the above copyright notice, this
00008  *   list of conditions and the following disclaimer.
00009  * - Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * - Neither the name of Eyescale Software GmbH nor the names of its
00013  *   contributors may be used to endorse or promote products derived from this
00014  *   software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  *
00028  * Equalizer 'Hello, World!' example. Shows the minimum Equalizer program,
00029  * rendering spinning quads around the origin.
00030  */
00031 
00032 #include <eq/eq.h>
00033 #include <stdlib.h>
00034 
00035 using namespace co::base;
00036 using namespace std;
00037 
00038 namespace eqHello
00039 {
00040 class Channel : public eq::Channel
00041 {
00042 public:
00043     Channel( eq::Window* parent ) : eq::Channel( parent ) {}
00044 
00045 protected:
00046     virtual void frameDraw( const eq::uint128_t& spin );
00047 };
00048 
00049 class NodeFactory : public eq::NodeFactory
00050 {
00051 public:
00052     virtual eq::Channel* createChannel( eq::Window* parent )
00053         { return new Channel( parent ); }
00054 };
00055 }
00056 
00057 int main( const int argc, char** argv )
00058 {
00059     // 1. Equalizer initialization
00060     eqHello::NodeFactory nodeFactory;
00061     if( !eq::init( argc, argv, &nodeFactory ))
00062     {
00063         EQERROR << "Equalizer init failed" << endl;
00064         return EXIT_FAILURE;
00065     }
00066     
00067     // 2. get a configuration
00068     bool        error  = false;
00069     eq::Config* config = eq::getConfig( argc, argv );
00070     if( config )
00071     {
00072         // 3. init config
00073         if( config->init( 0 ))
00074         {
00075             if( config->getError( ))
00076                 EQWARN << "Error during initialization: " << config->getError()
00077                        << std::endl;
00078 
00079             // 4. run main loop
00080             eq::uint128_t spin = 0;
00081             while( config->isRunning( ))
00082             {
00083                 config->startFrame( ++spin );
00084                 config->finishFrame();
00085             }
00086         
00087             // 5. exit config
00088             config->exit();
00089         }
00090         else
00091             error = true;
00092 
00093         // 6. release config
00094         eq::releaseConfig( config );
00095     }
00096     else
00097     {
00098         EQERROR << "Cannot get config" << endl;
00099         error = true;
00100     }    
00101 
00102     // 7. exit
00103     eq::exit();
00104     return error ? EXIT_FAILURE : EXIT_SUCCESS;
00105 }
00106 
00108 void eqHello::Channel::frameDraw( const eq::uint128_t& spin )
00109 {
00110     // setup OpenGL State
00111     eq::Channel::frameDraw( spin );
00112     
00113     const float lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
00114     glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
00115 
00116     const float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
00117     glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
00118 
00119     // rotate scene around the origin
00120     glRotatef( static_cast< float >( spin.low( )) * 0.1f, 1.0f, 0.5f, 0.25f );
00121 
00122     // render six axis-aligned colored quads around the origin
00123     for( int i = 0; i < 6; i++ )
00124     {
00125         glColor3f( (i&1) ? 0.5f:1.0f, (i&2) ? 1.0f:0.5f, (i&4) ? 1.0f:0.5f );
00126 
00127         glNormal3f( 0.0f, 0.0f, 1.0f );
00128         glBegin( GL_TRIANGLE_STRIP );
00129             glVertex3f(  .7f,  .7f, -1.0f );
00130             glVertex3f( -.7f,  .7f, -1.0f );
00131             glVertex3f(  .7f, -.7f, -1.0f );
00132             glVertex3f( -.7f, -.7f, -1.0f );
00133         glEnd();
00134 
00135         if( i < 3 )
00136             glRotatef(  90.0f, 0.0f, 1.0f, 0.0f );
00137         else if( i == 3 )
00138             glRotatef(  90.0f, 1.0f, 0.0f, 0.0f );
00139         else
00140             glRotatef( 180.0f, 1.0f, 0.0f, 0.0f );
00141     }
00142 }
Generated on Sun May 8 2011 19:11:07 for Equalizer 1.0 by  doxygen 1.7.3