File: MyGraphics

package info (click to toggle)
openscenegraph 1.2.0-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 26,924 kB
  • ctags: 25,229
  • sloc: cpp: 239,326; ansic: 2,178; sh: 1,990; yacc: 548; perl: 237; makefile: 227; lex: 151
file content (65 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef RENDER_SURFACE_EXAMPLE_MYGRAPHICS
#define RENDER_SURFACE_EXAMPLE_MYGRAPHICS

#include <GL/gl.h>
#include <GL/glu.h>


#include <Producer/RenderSurface>

extern void glutSolidTeapot(GLdouble scale);

class MyGraphics {
    public:
	    MyGraphics( Producer::RenderSurface &rs ) : 
			_rs(rs),
			_angle(0.0f),
			_initialized(false) 
		{}

		~MyGraphics() {}

        void init()
	    {
			glEnable( GL_DEPTH_TEST );
			glEnable( GL_LIGHTING );
			glEnable( GL_LIGHT0 );
		    glClearColor( 0.2f, 0.2f, 0.4f, 1.0f );

			_initialized = true;
	    }

		void draw()
		{
		    if( !_initialized ) init();

			// Query the render surface for its width and height
			glViewport( 0, 0, _rs.getWindowWidth(), _rs.getWindowHeight() );
			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
			glMatrixMode( GL_PROJECTION );
			glLoadIdentity();
			double aspect_ratio = double(_rs.getWindowWidth())/double(_rs.getWindowHeight());
			gluPerspective( 45.0, aspect_ratio, 1.0, 100.0 );
			glMatrixMode( GL_MODELVIEW );
			glLoadIdentity();
			glTranslatef( 0, 0, -4.0 );

			glPushMatrix();
			glRotatef( _angle, 0, 1, 0 );

			// Using the OpenGL teapot
			glutSolidTeapot(1.0);

			glPopMatrix();

			_angle++;
		}

    private:
		Producer::RenderSurface &_rs;
	    GLUquadricObj *_object;
		bool _initialized;
		float _angle;

};
#endif