#ifndef COMATIMER_HPP
#define COMATIMER_HPP
#include "comaglobal.hpp"
#include <QTime>
COMA_BEGIN_NAMESPACE
class COMA_DLL Timer
{
public:
Timer()
{
reset();
}
~Timer()
{
}
void reset()
{
m_zeroClock
= QTime::currentTime();
m_startClock
= QTime(0,
0,
0);
}
ULong milliseconds()
{
return (now.second() - m_startClock.second()) * 1000 + (now.msec() - m_startClock.msec()) / 1000;
}
private:
};
COMA_END_NAMESPACE
#endif /*COMATIMER_HPP*/
#ifndef COMATIMER_HPP
#define COMATIMER_HPP
#include "comaglobal.hpp"
#include <QTime>
COMA_BEGIN_NAMESPACE
class COMA_DLL Timer
{
public:
Timer()
{
reset();
}
~Timer()
{
}
void reset()
{
m_zeroClock = QTime::currentTime();
m_startClock = QTime(0, 0, 0);
}
ULong milliseconds()
{
QTime now = QTime::currentTime();
return (now.second() - m_startClock.second()) * 1000 + (now.msec() - m_startClock.msec()) / 1000;
}
private:
QTime m_zeroClock;
QTime m_startClock;
};
COMA_END_NAMESPACE
#endif /*COMATIMER_HPP*/
To copy to clipboard, switch view to plain text mode
void
ComaGL::paintGL()
{
++g_fps;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Vector3 eye(0.0, 0.0, -15.0);
Vector3 centre(0.0, 0.0, 0.0);
Vector3 up(0.0, 1.0, 0.0);
Matrix4 modelViewMatrix(Matrix4::M4_Identity);
modelViewMatrix.lookAt(eye, centre, up);
glMultMatrixf(modelViewMatrix.data());
Matrix4 rot(Matrix4::M4_Identity);
rot.rotateX(g_angle);
glMultMatrixf(rot.data());
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &m_tri[0]);
glColorPointer(3, GL_FLOAT, 0, &m_colour[0]);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
g_angle += 2.0;
g_currentTime = g_timer.milliseconds();
ULong time = g_currentTime - g_lastTime;
if(g_currentTime - g_lastTime > 1000)
{
.arg((UInt32)(g_fps / (Real)(g_currentTime - g_lastTime) * 1000.0)));
g_lastTime = g_currentTime;
g_fps = 0;
}
}
void
ComaGL::paintGL()
{
++g_fps;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Vector3 eye(0.0, 0.0, -15.0);
Vector3 centre(0.0, 0.0, 0.0);
Vector3 up(0.0, 1.0, 0.0);
Matrix4 modelViewMatrix(Matrix4::M4_Identity);
modelViewMatrix.lookAt(eye, centre, up);
glMultMatrixf(modelViewMatrix.data());
Matrix4 rot(Matrix4::M4_Identity);
rot.rotateX(g_angle);
glMultMatrixf(rot.data());
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &m_tri[0]);
glColorPointer(3, GL_FLOAT, 0, &m_colour[0]);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
g_angle += 2.0;
g_currentTime = g_timer.milliseconds();
ULong time = g_currentTime - g_lastTime;
if(g_currentTime - g_lastTime > 1000)
{
setWindowTitle(QString("Fps: %1")
.arg((UInt32)(g_fps / (Real)(g_currentTime - g_lastTime) * 1000.0)));
g_lastTime = g_currentTime;
g_fps = 0;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks