#include "qgl.h"
#include "qapplication.h"
#include "qimage.h"
public:
void paintGL();
void resizeGL(int w,int h);
protected:
};
data.load(filename);
resize(data.size());
}
void PaintWidget::paintGL(){
int k,i,j,count_h=0,count_v=0,flag=1;
uchar *temp;
uchar *img;
temp=gldata.bits();
//<problem>
for(i=0;i<gldata.width()*gldata.height();i++){
if(count_h==gldata.width()/2){ //checking for first half of image
flag=1-flag; // flag =1 : 1st half flag=0 : second half
count_h=0; // for counting next half counter make zero
}
if(flag==1)
img[++j]=temp[i]; //img[j++]will read only half of the image therefore j++
count_h++;
}
glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,img);
//</problem> //glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,gldata.bits());
}
void PaintWidget::resizeGL(int w, int h){
glViewport(0,0,w,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.show();
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;
};
PaintWidget::PaintWidget(const QString &filename,QWidget *parent):QGLWidget(parent){
data.load(filename);
gldata=QGLWidget::convertToGLFormat(data);
resize(data.size());
}
void PaintWidget::paintGL(){
int k,i,j,count_h=0,count_v=0,flag=1;
uchar *temp;
uchar *img;
temp=gldata.bits();
//<problem>
for(i=0;i<gldata.width()*gldata.height();i++){
if(count_h==gldata.width()/2){ //checking for first half of image
flag=1-flag; // flag =1 : 1st half flag=0 : second half
count_h=0; // for counting next half counter make zero
}
if(flag==1)
img[++j]=temp[i]; //img[j++]will read only half of the image therefore j++
count_h++;
}
glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,img);
//</problem> //glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,gldata.bits());
}
void PaintWidget::resizeGL(int w, int h){
glViewport(0,0,w,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.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks