Equalizer  1.6.1
renderer.cpp
1 
2 /* Copyright (c) 2011, Stefan Eilemann <eile@eyescale.ch>
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 
29 #include "renderer.h"
30 
31 // light parameters
32 static GLfloat lightPosition[] = {0.0f, 0.0f, 1.0f, 0.0f};
33 static GLfloat lightAmbient[] = {0.1f, 0.1f, 0.1f, 1.0f};
34 static GLfloat lightDiffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
35 static GLfloat lightSpecular[] = {0.8f, 0.8f, 0.8f, 1.0f};
36 
37 // material properties
38 static GLfloat materialAmbient[] = {0.2f, 0.2f, 0.2f, 1.0f};
39 static GLfloat materialDiffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
40 static GLfloat materialSpecular[] = {0.5f, 0.5f, 0.5f, 1.0f};
41 static GLint materialShininess = 64;
42 
43 namespace seqPly
44 {
45 
46 bool Renderer::init( co::Object* initData )
47 {
48  _state = new State( glewGetContext( ));
49  return seq::Renderer::init( initData );
50 }
51 
53 {
54  _state->deleteAll();
55  delete _state;
56  _state = 0;
57  return seq::Renderer::exit();
58 }
59 
60 void Renderer::draw( co::Object* frameDataObj )
61 {
62  const FrameData* frameData = static_cast< FrameData* >( frameDataObj );
63  Application& application = static_cast< Application& >( getApplication( ));
64  const eq::uint128_t id = frameData->getModelID();
65  const Model* model = application.getModel( id );
66  if( !model )
67  return;
68 
70 
71  glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
72  glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
73  glLightfv( GL_LIGHT0, GL_DIFFUSE, lightDiffuse );
74  glLightfv( GL_LIGHT0, GL_SPECULAR, lightSpecular );
75 
76  glMaterialfv( GL_FRONT, GL_AMBIENT, materialAmbient );
77  glMaterialfv( GL_FRONT, GL_DIFFUSE, materialDiffuse );
78  glMaterialfv( GL_FRONT, GL_SPECULAR, materialSpecular );
79  glMateriali( GL_FRONT, GL_SHININESS, materialShininess );
80 
82 
83  glColor3f( .75f, .75f, .75f );
84 
85  // Compute cull matrix
86  const eq::Matrix4f& modelM = getModelMatrix();
87  const eq::Matrix4f& view = getViewMatrix();
88  const eq::Frustumf& frustum = getFrustum();
89  const eq::Matrix4f projection = frustum.compute_matrix();
90  const eq::Matrix4f pmv = projection * view * modelM;
91  const seq::RenderContext& context = getRenderContext();
92 
93  _state->setProjectionModelViewMatrix( pmv );
94  _state->setRange( &context.range.start );
95  _state->setColors( model->hasColors( ));
96 
97  model->cullDraw( *_state );
98 }
99 
100 }
101 
The context applied to a channel during rendering operations.
Definition: renderContext.h:38
virtual void applyModelMatrix()
Apply the current model matrix to OpenGL.
const RenderContext & getRenderContext() const
virtual bool init(co::Object *initData)
Initialize the renderer.
virtual void draw(co::Object *frameData)
Render the scene.
Definition: renderer.cpp:60
const Frustumf & getFrustum() const
const GLEWContext * glewGetContext() const
Get the GLEW context for this renderer.
Range range
database-range wrt to dest channel
Definition: renderContext.h:58
Application & getApplication()
const Matrix4f & getViewMatrix() const
virtual bool exit()
De-initialize the renderer.
virtual bool init(co::Object *initData)
Initialize the renderer.
Definition: renderer.cpp:46
virtual void applyRenderContext()
Apply the current rendering parameters to OpenGL.
const Matrix4f & getModelMatrix() const
virtual bool exit()
De-initialize the renderer.
Definition: renderer.cpp:52
float start
The start position.
Definition: range.h:75