//VideoGLWin.cpp #include "StdAfx.h" #include "VideoGLWin.h"
bool VideoGlWin::initOpenGL(void) { if(m_openGLInitialized) return false; //initialize matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,1,0,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0,0,w(),h()); m_openGLInitialized=true; return m_openGLInitialized; } void VideoGlWin::ShowAppMessage(void) { glDisable(GL_TEXTURE_2D); glColor3f(0.618,0.618,0.618); glRasterPos2f(-0.75,0.75); gl_font(1,42); gl_draw("Video Player 1.0"); const GLubyte* OpenGLVersion =glGetString(GL_VERSION); const GLubyte* OpenGLMaker = glGetString(GL_VENDOR); const GLubyte* OpenGLRender = glGetString(GL_RENDERER); char str[255]; gl_font(1,14); //OpenGL information sprintf(str,"OpenGL Version: %s",OpenGLVersion); glRasterPos2f(-1.0,-0.5);gl_draw(str); sprintf(str,"OpenGL Maker: %s",OpenGLMaker); glRasterPos2f(-1.0,-0.55);gl_draw(str); sprintf(str,"OpenGL Render: %s",OpenGLRender); glRasterPos2f(-1.0,-0.60);gl_draw(str); //FLTK information //sprintf(str,"FLTK Version: %d.%d.%d",FL_MAJOR_VERSION,FL_MINOR_VERSION,FL_PATCH_VERSION); sprintf(str,"FLTK Version: %4.3f",Fl::version()); glRasterPos2f(-1.0,-0.70);gl_draw(str); //OpenCV version const char* opencv_libraries = 0; const char* addon_modules = 0; cvGetModuleInfo( 0, &opencv_libraries,&addon_modules ); sprintf(str,"OpenCV: %s",opencv_libraries); glRasterPos2f(-1.0,-0.80);gl_draw(str); sprintf(str,"Add-on Modules: %s\n",addon_modules); glRasterPos2f(-1.0,-0.85);gl_draw(str); } /////////////////////////////////////////////////// // use texture to display a picture /////////////////////////////////////////////////// bool VideoGlWin::upload_iplimage (const IplImage *img,GLuint& tex) { GLint format, type; /* Set pixel format */ switch(img->nChannels) { case 1: format = GL_LUMINANCE; break; case 3: format = GL_BGR_EXT; break; case 4: format = GL_BGRA_EXT; default: return 0; } /* Set pixel type */ switch(img->depth) { case IPL_DEPTH_8U: type = GL_UNSIGNED_BYTE; break; case IPL_DEPTH_8S: type = GL_BYTE; break; case IPL_DEPTH_16U: type = GL_UNSIGNED_SHORT; break; case IPL_DEPTH_16S: type = GL_SHORT; break; case IPL_DEPTH_32S: type = GL_INT; break; case IPL_DEPTH_32F: type = GL_FLOAT; break; case IPL_DEPTH_64F: /* Not supported by OpenGL */ default: return 0; } /* Create texture object */ glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); /* If necessary, specify texture parameters here */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* Now upload pixels */ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->width, img->height, 0, format, type, img->imageData); return true; } void VideoGlWin::draw() { // the valid() property may be used to avoid reinitializing your // GL transformation for each redraw: if (!valid()) { valid(1); glClear(GL_COLOR_BUFFER_BIT); } if(!m_processedImage) ShowAppMessage(); else { double ox,oy; double x1,y1,x2,y2,x3,y3,x4,y4; ox=xpan_ratio*(1.0+zoom_ratio); oy=-ypan_ratio*(1.0+zoom_ratio); x1=ox-zoom_ratio; y1=oy-zoom_ratio; x2=ox+zoom_ratio; y2=oy-zoom_ratio; x3=ox+zoom_ratio; y3=oy+zoom_ratio; x4=ox-zoom_ratio; y4=oy+zoom_ratio; glEnable(GL_TEXTURE_2D); upload_iplimage(m_processedImage,textureName); glBindTexture(GL_TEXTURE_2D, textureName); glBegin( GL_QUADS ); glTexCoord2d(0.0,0.0); glVertex2d(x1,y1); glTexCoord2d(1.0,0.0); glVertex2d(x2,y2); glTexCoord2d(1.0,1.0); glVertex2d(x3,y3); glTexCoord2d(0.0,1.0); glVertex2d(x4,y4); glEnd(); } } _______________________________________________ fltk-opengl mailing list fltk-opengl@easysw.com http://lists.easysw.com/mailman/listinfo/fltk-opengl