Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Tuto_Image / src / cpp / core / 04_OpenGL_pure / opengl / MyDisplayable.cpp
1 #include <iostream>
2 #include <GL/glew.h>
3
4 #include "MyDisplayable.h"
5
6 using std::cout;
7 using std::endl;
8
9
10
11
12 /*----------------------------------------------------------------------*\
13 |* Implementation *|
14 \*---------------------------------------------------------------------*/
15
16 /*--------------------------------------*\
17 |* Public *|
18 \*-------------------------------------*/
19
20 /*----------------------*\
21 |* Constructeur *|
22 \*---------------------*/
23
24 MyDisplayable::MyDisplayable():variateur(IntervalF(0 ,1), 0.01)
25 {
26 animationStep();
27 }
28
29 MyDisplayable::~MyDisplayable()
30 {
31 // rien
32 }
33
34 /*----------------------*\
35 |* Methodes *|
36 \*---------------------*/
37
38 /*-----------*\
39 |* Override *|
40 \*----------*/
41
42 /**
43 * Override
44 */
45 void MyDisplayable::reshape(Panel_A &panel, int w, int h)
46 {
47 glViewport(0, 0, w, h);
48
49 //Projection
50 glMatrixMode (GL_PROJECTION);
51 glLoadIdentity();
52 double fovy = 45;
53 if (h <= 0)
54 {
55 h = 1;
56 }
57 double ratio = w / h;
58
59 gluPerspective(fovy, ratio, 1, 10);
60
61 //Camera
62 glMatrixMode (GL_MODELVIEW);
63 glLoadIdentity();
64 gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
65 }
66
67 /**
68 * Override
69 *
70 * Animation:
71 * Pour une animation, en fenetrage glut, il faut deriver de
72 *
73 * GLUTWindow
74 *
75 * Puis redéfinir IdlFunc, et faire un repaint dedans
76 */
77 void MyDisplayable::display(Panel_A &panel)
78 {
79 glEnable (GL_DEPTH_TEST);
80 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
81
82 glPushMatrix();
83
84 animationStep();
85 drawScene3D();
86
87 glPopMatrix();
88 glFinish();
89 }
90
91 /**
92 * Override
93 */
94 void MyDisplayable::init(Panel_A &panel)
95 {
96 // Create OpenGL resources here (Textures,VBO,PBO,Shaders...)
97 }
98
99 /**
100 * Override
101 */
102 void MyDisplayable::release(Panel_A &panel)
103 {
104 //Freen OpenGL resources here!
105 }
106
107 /*--------------------------------------*\
108 |* Private *|
109 \*-------------------------------------*/
110
111 void MyDisplayable::drawScene3D()
112 {
113 glBegin (GL_TRIANGLES);
114
115 glColor3f(1, 0, 0);
116 glVertex3f(-1, -1, 0);
117 glColor3f(0, 1, 0);
118 glVertex3f(1, -1, 0);
119 glColor3f(0, 0, 1);
120 glVertex3f(0, py, 0);
121
122 glEnd();
123 }
124
125 void MyDisplayable::animationStep()
126 {
127 py=variateur.varierAndGet();
128
129 // cout<<"[MyDisplayable] : py = "<<py<<endl;
130 }
131
132 /*----------------------------------------------------------------------*\
133 |* End *|
134 \*---------------------------------------------------------------------*/
135