Equalizer  1.4.1
renderer.cpp
00001 
00002 /* Copyright (c) 2011, Stefan Eilemann <eile@eyescale.ch> 
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 
00029 #include "renderer.h"
00030 
00031 // light parameters
00032 static GLfloat lightPosition[] = {0.0f, 0.0f, 1.0f, 0.0f};
00033 static GLfloat lightAmbient[]  = {0.1f, 0.1f, 0.1f, 1.0f};
00034 static GLfloat lightDiffuse[]  = {0.8f, 0.8f, 0.8f, 1.0f};
00035 static GLfloat lightSpecular[] = {0.8f, 0.8f, 0.8f, 1.0f};
00036 
00037 // material properties
00038 static GLfloat materialAmbient[]  = {0.2f, 0.2f, 0.2f, 1.0f};
00039 static GLfloat materialDiffuse[]  = {0.8f, 0.8f, 0.8f, 1.0f};
00040 static GLfloat materialSpecular[] = {0.5f, 0.5f, 0.5f, 1.0f};
00041 static GLint  materialShininess   = 64;
00042 
00043 namespace seqPly
00044 {
00045 
00046 bool Renderer::init( co::Object* initData )
00047 {
00048     _state = new State( glewGetContext( ));
00049     return seq::Renderer::init( initData );
00050 }
00051 
00052 bool Renderer::exit()
00053 {
00054     _state->deleteAll();
00055     delete _state;
00056     _state = 0;
00057     return seq::Renderer::exit();
00058 }
00059 
00060 void Renderer::draw( co::Object* frameDataObj )
00061 {
00062     const FrameData* frameData = static_cast< FrameData* >( frameDataObj );
00063     Application& application = static_cast< Application& >( getApplication( ));
00064     const eq::uint128_t id = frameData->getModelID();
00065     const Model* model = application.getModel( id );
00066     if( !model )
00067         return;
00068 
00069     applyRenderContext();
00070 
00071     glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
00072     glLightfv( GL_LIGHT0, GL_AMBIENT,  lightAmbient  );
00073     glLightfv( GL_LIGHT0, GL_DIFFUSE,  lightDiffuse  );
00074     glLightfv( GL_LIGHT0, GL_SPECULAR, lightSpecular );
00075 
00076     glMaterialfv( GL_FRONT, GL_AMBIENT,   materialAmbient );
00077     glMaterialfv( GL_FRONT, GL_DIFFUSE,   materialDiffuse );
00078     glMaterialfv( GL_FRONT, GL_SPECULAR,  materialSpecular );
00079     glMateriali(  GL_FRONT, GL_SHININESS, materialShininess );
00080 
00081     applyModelMatrix();
00082 
00083     glColor3f( .75f, .75f, .75f );
00084 
00085     // Compute cull matrix
00086     const eq::Matrix4f& modelM = getModelMatrix();
00087     const eq::Matrix4f& view = getViewMatrix();
00088     const eq::Frustumf& frustum = getFrustum();
00089     const eq::Matrix4f projection = frustum.compute_matrix();
00090     const eq::Matrix4f pmv = projection * view * modelM;
00091     const seq::RenderContext& context = getRenderContext();
00092 
00093     _state->setProjectionModelViewMatrix( pmv );
00094     _state->setRange( &context.range.start );
00095     _state->setColors( model->hasColors( ));
00096     
00097     model->cullDraw( *_state );
00098 }
00099 
00100 }
00101 
Generated on Mon Nov 26 2012 14:41:49 for Equalizer 1.4.1 by  doxygen 1.7.6.1