KINECT STATS GENERATOR FOR SPORTS VISUALISATION  1.0
ScreenQuad.cpp
Go to the documentation of this file.
00001 #include "ScreenQuad.h"
00002 #include <ngl/ShaderLib.h>
00003 
00004 
00005 ScreenQuad::ScreenQuad(int _width, int _height,const std::string &_shader)
00006 {
00007 
00008 
00009 //static ngl::Vec3 verts[]=
00010 //                        {
00011 //                          ngl::Vec3(-1,-1,0),
00012 //                          ngl::Vec3(1,-1,0),
00013 //                          ngl::Vec3(1,1,0),
00014 //                          ngl::Vec3(1,1,0),
00015 //                          ngl::Vec3(-1,-1,0),
00016 //                          ngl::Vec3(-1,1,0)
00017 //                        };
00018 
00019 
00020     static ngl::Vec3 verts[]=
00021                             {
00022                               ngl::Vec3(-1,-1,0),
00023                               ngl::Vec3(-1,1,0),
00024                               ngl::Vec3(1,1,0),
00025                               ngl::Vec3(1,1,0),
00026                               ngl::Vec3(-1,-1,0),
00027                               ngl::Vec3(1,-1,0)
00028                             };
00029 
00030 
00031 //static ngl::Vec2 uv[]=
00032 //                      {
00033 //                        ngl::Vec2(1,1),
00034 //                        ngl::Vec2(0,1),
00035 //                        ngl::Vec2(0,0),
00036 //                        ngl::Vec2(0,0),
00037 //                        ngl::Vec2(1,1),
00038 //                        ngl::Vec2(1,0)
00039 //                      };
00040 
00041 
00042 static ngl::Vec2 uv[]=
00043                       {
00044                         ngl::Vec2(0,1),
00045                         ngl::Vec2(0,0),
00046                         ngl::Vec2(1,0),
00047                         ngl::Vec2(1,0),
00048                         ngl::Vec2(0,1),
00049                         ngl::Vec2(1,1)
00050                       };
00051 
00052 
00053   m_shader=_shader;
00054   m_textureWidth=_width;
00055   m_textureHeight=_height;
00056 
00057   glGenVertexArrays(1,&m_vao);
00058   glBindVertexArray(m_vao);
00059 
00060   GLuint vbo[2];
00061   glGenBuffers(2,vbo);
00062   glBindBuffer(GL_ARRAY_BUFFER,vbo[0]);
00063   glBufferData(GL_ARRAY_BUFFER,6*sizeof(ngl::Vec3),&verts[0].m_x,GL_STATIC_DRAW);
00064 
00065   glVertexAttribPointer(0, // atrib 0
00066                         3, // with x,y,z
00067                         GL_FLOAT, // what type
00068                         GL_FALSE, // normalize?
00069                         0, // stride
00070                         0 // start ptr
00071                         );
00072   glEnableVertexAttribArray(0);
00073 
00074   glBindBuffer(GL_ARRAY_BUFFER,vbo[1]);
00075   glBufferData(GL_ARRAY_BUFFER,6*sizeof(ngl::Vec2),&uv[0].m_x,GL_STATIC_DRAW);
00076 
00077   glVertexAttribPointer(1, // atrib 1
00078                         2, // with u,v
00079                         GL_FLOAT, // what type
00080                         GL_FALSE, // normalize?
00081                         0, // stride
00082                         0 // start ptr
00083                         );
00084   glEnableVertexAttribArray(1);
00085 
00086 
00087 
00088   glBindVertexArray(0);
00089 
00090   glGenTextures(1, &m_texture);
00091   glActiveTextureARB(GL_TEXTURE0);
00092   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00093   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00094   m_textureMode=GL_RGB;
00095 
00096 }
00097 
00098 ScreenQuad::~ScreenQuad()
00099 {
00100   glDeleteVertexArrays(1,&m_vao);
00101   glDeleteTextures(1,&m_texture);
00102 }
00103 
00104 void ScreenQuad::draw(cv::Mat *_data)
00105 {
00106   ngl::ShaderLib *shader = ngl::ShaderLib::instance();
00107   shader->use(m_shader);
00108   shader->setUniform("textureFlag",false);
00109 
00110   //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
00111 
00112   glBindVertexArray(m_vao);
00113   glBindTexture(GL_TEXTURE_2D, m_texture);
00114   glTexImage2D(GL_TEXTURE_2D, 0, m_textureMode, m_textureWidth, m_textureHeight, 0, m_textureMode, GL_UNSIGNED_BYTE, &_data->data[0]);
00115   glGenerateMipmap(GL_TEXTURE_2D);
00116   glDrawArrays(GL_TRIANGLES,0,6);
00117   glBindVertexArray(0);
00118 }
00119 
00120 
 All Classes Files Functions Variables Enumerations Enumerator