fysxasteroids/engine/libraries/oglft/tests/vignette.h

100 lines
2.8 KiB
C++

/* -*- c++ -*-
* speedtest.h: Header for Performance test for the OGLFT library
* Copyright (C) 2002 lignum Computing, Inc. <oglft@lignumcomputing.com>
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef VIGNETTE_H
#define VIGNETTE_H
#include <stdlib.h>
#if OGLFT_QT_VERSION == 3
#include <qgl.h>
#include <qqueue.h>
#include <qtimer.h>
#elif OGLFT_QT_VERSION == 4
#include <QGLWidget>
#include <QQueue>
#include <QTimer>
#include <QKeyEvent>
#endif
// Little animation vignettes. The function calls essentially follow
// those of the Qt OpenGL widget and are called at the corresponding times.
struct Vignette {
virtual ~Vignette ( void ) {}
virtual unsigned int frame_count ( void ) = 0;
virtual unsigned int frame_rate ( void ) = 0;
virtual void init ( void ) = 0;
virtual void view ( GLdouble /*left*/, GLdouble /*right*/,
GLdouble /*bottom*/, GLdouble /*top*/ )
{}
virtual void reset ( void )
{}
virtual bool input ( QKeyEvent* e )
{
if ( e->key() == Qt::Key_Escape ) exit( 0 );
return false;
}
virtual void draw ( unsigned int frame_number ) = 0;
virtual void finish ( void ) = 0;
};
// Yet another OpenGL view widget.
class CharacterView : public QGLWidget {
Q_OBJECT
GLsizei window_width_, window_height_;
GLdouble view_width_, view_height_;
GLdouble view_left_, view_right_, view_bottom_, view_top_;
bool flank_speed_;
QTimer redraw_timer_;
QTimer performance_timer_;
unsigned int frame_counter_;
unsigned int counter_snapshot_;
unsigned int animation_frame_count_;
unsigned int animation_frame_rate_;
unsigned int animation_frame_counter_;
static const unsigned int PERFORMANCE_SAMPLE_RATE_HZ = 1;
#if OGLFT_QT_VERSION == 3
QQueue<Vignette> vignettes;
#elif OGLFT_QT_VERSION == 4
QQueue<Vignette*> vignettes;
#endif
protected slots:
void redraw ( void );
void measure_performance ( void );
public:
CharacterView ( bool flank_speed, const char* fontfile,
QWidget* parent = 0, const char* name = 0 );
protected:
void initializeGL ( void );
void resizeGL ( int w, int h );
void paintGL ( void );
void keyPressEvent ( QKeyEvent* e );
void resetView ( void );
};
#endif /* VIGNETTE_H */