Equalizer  1.8.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
hello.cpp
1 
2 /* Copyright (c) 2007-2014, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Equalizer 'Hello, World!' example. Shows the minimum Equalizer program,
29  * rendering spinning quads around the origin.
30  */
31 
32 #include <seq/sequel.h>
33 #include <stdlib.h>
34 
35 namespace eqHello
36 {
37 class Renderer : public seq::Renderer
38 {
39 public:
40  Renderer( seq::Application& application ) : seq::Renderer( application ) {}
41  virtual ~Renderer() {}
42 
43 protected:
44  virtual void draw( co::Object* frameData );
45 };
46 
48 {
49  virtual ~Application() {}
50 public:
51  virtual seq::Renderer* createRenderer() { return new Renderer( *this ); }
52 };
53 typedef lunchbox::RefPtr< Application > ApplicationPtr;
54 }
55 
56 int main( const int argc, char** argv )
57 {
58  eqHello::ApplicationPtr app = new eqHello::Application;
59 
60  if( app->init( argc, argv, 0 ) && app->run( 0 ) && app->exit( ))
61  return EXIT_SUCCESS;
62 
63  return EXIT_FAILURE;
64 }
65 
67 void eqHello::Renderer::draw( co::Object* /*frameData*/ )
68 {
69  applyRenderContext(); // set up OpenGL State
70 
71  const float lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
72  glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
73 
74  const float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
75  glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
76 
77  applyModelMatrix(); // global camera
78 
79  // render six axis-aligned colored quads around the origin
80  for( int i = 0; i < 6; i++ )
81  {
82  glColor3f( (i&1) ? 0.5f:1.0f, (i&2) ? 1.0f:0.5f, (i&4) ? 1.0f:0.5f );
83 
84  glNormal3f( 0.0f, 0.0f, 1.0f );
85  glBegin( GL_TRIANGLE_STRIP );
86  glVertex3f( .7f, .7f, -1.0f );
87  glVertex3f( -.7f, .7f, -1.0f );
88  glVertex3f( .7f, -.7f, -1.0f );
89  glVertex3f( -.7f, -.7f, -1.0f );
90  glEnd();
91 
92  if( i < 3 )
93  glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );
94  else if( i == 3 )
95  glRotatef( 90.0f, 1.0f, 0.0f, 0.0f );
96  else
97  glRotatef( 180.0f, 1.0f, 0.0f, 0.0f );
98  }
99 }
virtual seq::Renderer * createRenderer()
Create a new renderer instance.
Definition: hello.cpp:51
The main application object.
virtual ~Renderer()
Destruct this renderer.
Definition: hello.cpp:41
virtual void draw(co::Object *frameData)
The rendering routine, a.k.a., glutDisplayFunc()
Definition: hello.cpp:67
A renderer instance.
virtual SEQ_API void applyRenderContext()
Apply the current rendering parameters to the rendering context.
virtual SEQ_API void applyModelMatrix()
Apply the current model matrix to the rendering context.