#include "qgl.h"
#include "qapplication.h"
#include "qimage.h"
public:
void paintGL();
void resizeGL(int w,int h);
protected:
float width,height;
};
data.load(filename);
resize(data.size());
}
void PaintWidget::paintGL(){
QImage half
=data.
copy(0,
0,data.
width()/2,data.
height()/2);
int xsize,ysize;
float xscale,yscale;
xsize=width;
ysize=gldata.height()*xsize / gldata.width();
if(ysize > height)
{
ysize=height;
xsize=gldata.width()*ysize / gldata.height();
}
xscale=(float)xsize /(float)gldata.width();
yscale=(float)ysize/(float)gldata.height();
glPixelZoom(xscale,yscale);
glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,gldata.bits());
}
void PaintWidget::resizeGL(int w, int h){
glViewport(0,0,w,h);
width=w;
height=h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,-1,1);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv){
PaintWidget pw(argv[1]);
pw.showFullScreen();
return app.exec();
}
#include "qgl.h"
#include "qapplication.h"
#include "qimage.h"
class PaintWidget : public QGLWidget{
public:
PaintWidget(const QString &filename,QWidget *parent=0);
void paintGL();
void resizeGL(int w,int h);
protected:
QImage data,gldata;
float width,height;
};
PaintWidget::PaintWidget(const QString &filename,QWidget *parent):QGLWidget(parent){
data.load(filename);
resize(data.size());
}
void PaintWidget::paintGL(){
QImage half=data.copy(0,0,data.width()/2,data.height()/2);
gldata = QGLWidget::convertToGLFormat(half);
int xsize,ysize;
float xscale,yscale;
xsize=width;
ysize=gldata.height()*xsize / gldata.width();
if(ysize > height)
{
ysize=height;
xsize=gldata.width()*ysize / gldata.height();
}
xscale=(float)xsize /(float)gldata.width();
yscale=(float)ysize/(float)gldata.height();
glPixelZoom(xscale,yscale);
glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,gldata.bits());
}
void PaintWidget::resizeGL(int w, int h){
glViewport(0,0,w,h);
width=w;
height=h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,-1,1);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv){
QApplication app(argc,argv);
PaintWidget pw(argv[1]);
pw.showFullScreen();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks