13QHyodaIceT::QHyodaIceT(QWidget *prnt): QOpenGLWidget(prnt),
16 pov(QVector4D(13.25,26.75,0,0.73)),
19 qDebug()<<
"\33[31m[QHyodaIceT::QHyodaIceT] NEW\33[m";
27QHyodaIceT::~QHyodaIceT(){
28 qDebug()<<
"~QHyodaIceT";
36void QHyodaIceT::sxyz(
double *v){
43void QHyodaIceT::setPov(QVector4D v){
51void QHyodaIceT::setImage(QImage *qImg){
61void QHyodaIceT::initializeGL(){
62 qDebug()<<
"\33[31m[QHyodaIceT::initializeGL]\33[m";
63 glViewport(0, 0, parent->width(), parent->height());
64 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
65 glEnable(GL_DEPTH_TEST);
66 glEnable(GL_NORMALIZE);
67 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
68 glEnable(GL_TEXTURE_2D);
69 glGenTextures(1,&texture);
70 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
71 glBindTexture(GL_TEXTURE_2D, texture);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
75 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
83void QHyodaIceT::resizeGL(
int w,
int h){
85 glViewport(0.0, 0.0, w, h);
86 glMatrixMode(GL_PROJECTION);
88 glFrustum(-1.0f, 1.0f, -1.0f, 1.0f, +1, 8);
89 glTranslatef(0.0f, 0.0f, -2.0f);
103 const double sqrtd=2.0;
106 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
107 image->width(), image->height(), 0,
108 GL_RGBA, GL_UNSIGNED_BYTE, image->bits());
109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
114 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
116 glTexCoord2d(0.0, 0.0); glVertex3d(-sqrtd, -sqrtd, 0.0);
117 glTexCoord2d(0.0, 1.0); glVertex3d(-sqrtd, +sqrtd, 0.0);
118 glTexCoord2d(1.0, 1.0); glVertex3d(+sqrtd, +sqrtd, 0.0);
119 glTexCoord2d(1.0, 0.0); glVertex3d(+sqrtd, -sqrtd, 0.0);
129void QHyodaIceT::mousePressEvent(QMouseEvent *e){
131 mouse = QVector2D(e->localPos());
137void QHyodaIceT::mouseMoveEvent(QMouseEvent *e){
139 QVector2D diff = QVector2D(e->localPos())-mouse;
141 if (e->buttons() & Qt::LeftButton) {
142 pov.setX(pov.x()+diff.y()/4.0f);
143 pov.setY(pov.y()+diff.x()/4.0f);
144 }
else if (e->buttons() & Qt::RightButton) {
145 pov.setX(pov.x()+diff.y()/4.0f);
146 pov.setZ(pov.z()+diff.x()/4.0f);
148 mouse = QVector2D(e->localPos());
155void QHyodaIceT::wheelEvent(QWheelEvent *e){
158 pov.setW(pov.w()+pov.w()*0.1f):
159 pov.setW(pov.w()-pov.w()*0.1f);
167void QHyodaIceT::saveGLState(){
168 glPushAttrib(GL_ALL_ATTRIB_BITS);
169 glMatrixMode(GL_PROJECTION);
171 glMatrixMode(GL_MODELVIEW);
179void QHyodaIceT::restoreGLState(){
180 glMatrixMode(GL_PROJECTION);
182 glMatrixMode(GL_MODELVIEW);