X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FTuto_Image_Cuda%2Fsrc%2Fcpp%2Fcore%2F04_OpenGL_pure%2Fopengl%2FMyDisplayable.cpp;fp=WCudaMSE%2FTuto_Image_Cuda%2Fsrc%2Fcpp%2Fcore%2F04_OpenGL_pure%2Fopengl%2FMyDisplayable.cpp;h=73e45e686314fa8808c327e9c7e4a0ac3868d935;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Tuto_Image_Cuda/src/cpp/core/04_OpenGL_pure/opengl/MyDisplayable.cpp b/WCudaMSE/Tuto_Image_Cuda/src/cpp/core/04_OpenGL_pure/opengl/MyDisplayable.cpp new file mode 100755 index 0000000..73e45e6 --- /dev/null +++ b/WCudaMSE/Tuto_Image_Cuda/src/cpp/core/04_OpenGL_pure/opengl/MyDisplayable.cpp @@ -0,0 +1,135 @@ +#include +#include + +#include "MyDisplayable.h" + +using std::cout; +using std::endl; + + + + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*----------------------*\ +|* Constructeur *| + \*---------------------*/ + +MyDisplayable::MyDisplayable():variateur(IntervalF(0 ,1), 0.01) + { + animationStep(); + } + +MyDisplayable::~MyDisplayable() + { + // rien + } + +/*----------------------*\ +|* Methodes *| + \*---------------------*/ + +/*-----------*\ +|* Override *| + \*----------*/ + +/** + * Override + */ +void MyDisplayable::reshape(Panel_A &panel, int w, int h) + { + glViewport(0, 0, w, h); + + //Projection + glMatrixMode (GL_PROJECTION); + glLoadIdentity(); + double fovy = 45; + if (h <= 0) + { + h = 1; + } + double ratio = w / h; + + gluPerspective(fovy, ratio, 1, 10); + + //Camera + glMatrixMode (GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0); + } + +/** + * Override + * + * Animation: + * Pour une animation, en fenetrage glut, il faut deriver de + * + * GLUTWindow + * + * Puis redéfinir IdlFunc, et faire un repaint dedans + */ +void MyDisplayable::display(Panel_A &panel) + { + glEnable (GL_DEPTH_TEST); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + animationStep(); + drawScene3D(); + + glPopMatrix(); + glFinish(); + } + +/** + * Override + */ +void MyDisplayable::init(Panel_A &panel) + { + // Create OpenGL resources here (Textures,VBO,PBO,Shaders...) + } + +/** + * Override + */ +void MyDisplayable::release(Panel_A &panel) + { + //Freen OpenGL resources here! + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +void MyDisplayable::drawScene3D() + { + glBegin (GL_TRIANGLES); + + glColor3f(1, 0, 0); + glVertex3f(-1, -1, 0); + glColor3f(0, 1, 0); + glVertex3f(1, -1, 0); + glColor3f(0, 0, 1); + glVertex3f(0, py, 0); + + glEnd(); + } + +void MyDisplayable::animationStep() + { + py=variateur.varierAndGet(); + + // cout<<"[MyDisplayable] : py = "<