FLTK logo

Re: Program becomes very slow after some time running

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.opengl  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Program becomes very slow after some time running yin Jan 15, 2012  
 
//OBPM.CPP
#include "stdafx.h"
#include "OBPM_UI.h"

int main(int argc, char* argv[])
{
	OBPMViewUI UI;	
	UI.start(argc,argv);
	return Fl::run();
}


//VideoGLWin.h
////////////////////////////////////////////////////////////
// Class Name: VideoGLWin
// Description: Display the video from camera or file by openGL(FLTK)
// Date: 2012-01-09 09:54
////////////////////////////////////////////////////////////

#ifndef VIDEO_GL_WIN_H
#define VIDEO_GL_WIN_H

#include <FL/Fl.H>
#include <FL/Gl.H>
#include <FL/Glu.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/Threads.h>
#include <FL/Fl_Ask.h>

#include<OpenCV/cv.h>


class VideoGlWin :
	public Fl_Gl_Window
{
private:
	bool m_openGLInitialized;
	GLuint textureName;
public:
	double zoom_ratio;  //0.1  10.0
	double xpan_ratio,ypan_ratio; // -1.0-1.0
	double frame_rate;

public:
	IplImage *m_processedImage; 

public:
	VideoGlWin(int x,int y , int w, int h,const char *L=0):Fl_Gl_Window(x,y,w,h,L)
	{
		zoom_ratio=1.0;
		xpan_ratio=0.0;
		ypan_ratio=0.0;
		m_processedImage=NULL;
		m_openGLInitialized=false;
		
		if(!initOpenGL())
		{
			fl_alert("Can not init OpenGL! Exit!");
			exit(0);
		}
		Fl::add_timeout(1.0/frame_rate, Timer_CB, (void*)this);
	}
	~VideoGlWin()
	{
		if(m_processedImage)  
		{
			cvReleaseImage(&m_processedImage);
			m_processedImage=NULL;
		}
	}
	bool initOpenGL(void);
	void draw(void);

	//void draw_overlay(void);

	void ShowAppMessage(void);
    void VideoGlWin::grid_draw(int r2,int c2);
    bool upload_iplimage (const IplImage *img,GLuint& tex);
// 24 FPS TIMER CALLBACK
    //     Called 24x per second to redraw the widget
    //
    static void Timer_CB(void *userdata)
	{
		VideoGlWin *glW = (VideoGlWin*)userdata;
        glW->redraw();
        Fl::repeat_timeout(1.0/24.0, Timer_CB, userdata);
    }

	void SetFPS(double fps)
	{
		Fl::remove_timeout(Timer_CB,(void*)this);
		Fl::add_timeout(1.0/fps, Timer_CB, (void*)this);
		frame_rate=fps;
	}
};

#endif
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.