Implemented cylinder shape, also fixed the coordinate system (again). I fucking hate...
[fail.git] / scenegraph / ViewPort.h
bloba7abed0cfe13c95bcc9dd28f5f923a34d28d4415
1 #ifndef AWFUL_SCENEGRAPH_VIEWPORT_H_
2 #define AWFUL_SCENEGRAPH_VIEWPORT_H_
4 #include "core/core.h"
5 #include "Camera.h"
6 #include "Projection.h"
7 #include "math/Rectu32.h"
8 #include <GL/gl.h>
10 namespace awful { namespace scenegraph
12 class ViewPort : public Serializable
14 public:
15 ViewPort( const Pointer< Projection >& pProjection, const Pointer< Camera >& pCamera = NULL ) :
16 m_pProjection( pProjection ),
17 m_pCamera( pCamera ),
18 m_ZNear( 0.1f ),
19 m_ZFar( 50.f ),
20 m_bClearColorBuffer( true ),
21 m_bClearDepthBuffer( true )
25 ViewPort( const Serialization_tag& ) {}
27 const Pointer< Camera >& getpCamera() const { return m_pCamera; }
28 void setpCamera( const Pointer< Camera >& x ) { m_pCamera = x; }
30 const Pointer< Projection >& getpProjection() const { return m_pProjection; }
31 void setpProjection( const Pointer< Projection >& x ) { m_pProjection = x; }
33 const math::Rectu32& getRect() const { return m_Rect; }
34 math::Rectu32& getRect() { return m_Rect; }
35 void setRect( const math::Rectu32& x ) { m_Rect = x; }
37 const float& getZNear() const { return m_ZNear; }
38 void setZNear( const float& x ) { m_ZNear = x; }
40 const float& getZFar() const { return m_ZFar; }
41 void setZFar( const float& x ) { m_ZFar = x; }
43 const bool& getbClearColorBuffer() const { return m_bClearColorBuffer; }
44 void setbClearColorBuffer( const bool& x ) { m_bClearColorBuffer = x; }
46 const bool& getbClearDepthBuffer() const { return m_bClearDepthBuffer; }
47 void setbClearDepthBuffer( const bool& x ) { m_bClearDepthBuffer = x; }
49 void renderSetup() const
51 GLint clearflags = 0;
53 if( m_bClearColorBuffer )
54 clearflags |= GL_COLOR_BUFFER_BIT;
55 if( m_bClearDepthBuffer )
56 clearflags |= GL_DEPTH_BUFFER_BIT;
58 if( clearflags )
59 glClear( clearflags );
61 glViewport( m_Rect.left(), m_Rect.top(), m_Rect.width(), m_Rect.height() );
63 m_pProjection->renderSetup( m_Rect, m_pCamera ? m_pCamera->getFOV() : 60.f );
65 // Just for testing purpose, a proper light system will of course need to
66 // be created later.
67 glEnable( GL_LIGHT0 );
69 GLfloat pos[] = { 0.f, -1.f, 0.f };
70 glLightfv( GL_LIGHT0, GL_POSITION, pos );
74 void getCameraMatrix( math::Matrix44f& Dest )
76 if( m_pCamera )
77 m_pCamera->matrix( Dest );
78 else
79 Dest.identity();
82 private:
83 template< class C, typename T > friend struct awful::attribute_traits;
84 Pointer< Projection > m_pProjection;
85 Pointer< Camera > m_pCamera;
86 math::Rectu32 m_Rect;
87 float m_ZNear;
88 float m_ZFar;
90 bool m_bClearColorBuffer;
91 bool m_bClearDepthBuffer;
95 #endif