// declaration (CGLFrame.h)
#ifndef CGLFRAME_H
#define CGLFRAME_H
#include "GLee.h"
#include <qgl.h>
#include <qframe.h>
#include <qpaintdevice.h>
#include <qapplication.h>
#include <qevent.h>
#include <qmessagebox.h>
#include <qstring.h>
#include <qfileinfo.h>
#include <qtimer.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
class CGLFrame
: public QFrame{
Q_OBJECT
public:
CGLFrame
(QWidget * parent
= 0,
const char * name
= 0);
virtual ~CGLFrame();
virtual void InitGLScene();
virtual void ResizeGLScene();
virtual void RenderGLScene(int pick);
virtual void KillGLScene();
virtual void InitGLSL();
virtual void CheckGLError();
private:
// enum PickMode { PickNone, PickWidget };
int m_iPickMode;
char * readShaderFile(const char * filename);
virtual void info(const char * title, const char * msg, ...);
public slots:
void timerGLFire();
};
#endif
// declaration (CGLFrame.h)
#ifndef CGLFRAME_H
#define CGLFRAME_H
#include "GLee.h"
#include <qgl.h>
#include <qframe.h>
#include <qpaintdevice.h>
#include <qapplication.h>
#include <qevent.h>
#include <qmessagebox.h>
#include <qstring.h>
#include <qfileinfo.h>
#include <qtimer.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
class CGLFrame : public QFrame
{
Q_OBJECT
public:
CGLFrame(QWidget * parent = 0, const char * name = 0);
virtual ~CGLFrame();
virtual void InitGLScene();
virtual void ResizeGLScene();
virtual void RenderGLScene(int pick);
virtual void KillGLScene();
virtual void InitGLSL();
virtual void CheckGLError();
private:
// enum PickMode { PickNone, PickWidget };
int m_iPickMode;
QGLContext * m_cContext;
QTimer timerGL;
char * readShaderFile(const char * filename);
virtual void mousePressEvent(QMouseEvent * event);
virtual void mouseReleaseEvent(QMouseEvent * event);
virtual void mouseMoveEvent(QMouseEvent * event);
virtual void resizeEvent(QResizeEvent * event);
virtual void paintEvent(QPaintEvent * event);
virtual void showEvent(QShowEvent * event);
virtual void info(const char * title, const char * msg, ...);
public slots:
void timerGLFire();
};
#endif
To copy to clipboard, switch view to plain text mode
#include "CGLFrame.h"
CGLFrame
::CGLFrame(QWidget * parent,
const char * name
) m_iPickMode(0),
m_cContext(0)
{
m_cContext->create();
InitGLScene();
}
void CGLFrame::CheckGLError()
{
int err;
if ((err = glGetError()) != GL_NO_ERROR)
{
info("GL error!", "%s\n", s.data());
}
}
void CGLFrame::info(const char * title, const char * msg, ...)
{
... format message
}
void CGLFrame::InitGLScene()
{
m_cContext->makeCurrent();
// initialize GLSL
InitGLSL();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
ResizeGLScene();
connect(&timerGL, SIGNAL(timeout()), this, SLOT(timerGLFire()));
timerGL.start(0, FALSE);
}
void CGLFrame::InitGLSL()
{
... init GLSL
}
char * CGLFrame::readShaderFile(const char * filename)
{
... read shader file
}
void CGLFrame::ResizeGLScene()
{
m_cContext->makeCurrent();
glViewport(0, 0, width(), height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0, 10.0, 0.0, 10.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CGLFrame::RenderGLScene(int pick)
{
m_cContext->makeCurrent();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
if(m_cContext->format().doubleBuffer())
m_cContext->swapBuffers();
}
void CGLFrame::KillGLScene()
{
timerGL.stop();
delete m_cContext;
return;
}
{
int mx = event->x();
int my = event->y();
}
{
int mx = event->x();
int my = event->y();
}
{
int mx = event->x();
int my = event->y();
}
{
ResizeGLScene();
}
{
}
void CGLFrame::timerGLFire()
{
RenderGLScene(m_iPickMode);
}
{
}
CGLFrame::~CGLFrame()
{
KillGLScene();
}
#include "CGLFrame.h"
CGLFrame::CGLFrame(QWidget * parent, const char * name)
: QFrame(parent, name),
m_iPickMode(0),
m_cContext(0)
{
QGLFormat format;
m_cContext = new QGLContext(format, (QPaintDevice *)this);
m_cContext->create();
InitGLScene();
}
void CGLFrame::CheckGLError()
{
int err;
if ((err = glGetError()) != GL_NO_ERROR)
{
QString s = QString((char *)gluErrorString(err));
info("GL error!", "%s\n", s.data());
}
}
void CGLFrame::info(const char * title, const char * msg, ...)
{
... format message
QMessageBox::information(0, title, text);
}
void CGLFrame::InitGLScene()
{
m_cContext->makeCurrent();
// initialize GLSL
InitGLSL();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
ResizeGLScene();
connect(&timerGL, SIGNAL(timeout()), this, SLOT(timerGLFire()));
timerGL.start(0, FALSE);
}
void CGLFrame::InitGLSL()
{
... init GLSL
}
char * CGLFrame::readShaderFile(const char * filename)
{
... read shader file
}
void CGLFrame::ResizeGLScene()
{
m_cContext->makeCurrent();
glViewport(0, 0, width(), height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0, 10.0, 0.0, 10.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CGLFrame::RenderGLScene(int pick)
{
m_cContext->makeCurrent();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
if(m_cContext->format().doubleBuffer())
m_cContext->swapBuffers();
}
void CGLFrame::KillGLScene()
{
timerGL.stop();
delete m_cContext;
return;
}
void CGLFrame::mousePressEvent(QMouseEvent * event)
{
int mx = event->x();
int my = event->y();
}
void CGLFrame::mouseReleaseEvent(QMouseEvent * event)
{
int mx = event->x();
int my = event->y();
}
void CGLFrame::mouseMoveEvent(QMouseEvent * event)
{
int mx = event->x();
int my = event->y();
}
void CGLFrame::resizeEvent(QResizeEvent * event)
{
ResizeGLScene();
}
void CGLFrame::paintEvent(QPaintEvent * event)
{
}
void CGLFrame::timerGLFire()
{
RenderGLScene(m_iPickMode);
}
void CGLFrame::showEvent(QShowEvent * event)
{
}
CGLFrame::~CGLFrame()
{
KillGLScene();
}
To copy to clipboard, switch view to plain text mode
#include "CGLFrame.h"
CGLFrame * cGLFrame2DLUT = 0;
void CFormControls::init()
{
cGLFrame2DLUT = new CGLFrame( tab2DLUT, "cGLFrame2DLUT" );
cGLFrame2DLUT
->setGeometry
( QRect( 20,
20,
256,
256 ) );
}
#include "CGLFrame.h"
CGLFrame * cGLFrame2DLUT = 0;
void CFormControls::init()
{
cGLFrame2DLUT = new CGLFrame( tab2DLUT, "cGLFrame2DLUT" );
cGLFrame2DLUT->setGeometry( QRect( 20, 20, 256, 256 ) );
}
To copy to clipboard, switch view to plain text mode
Bookmarks