void GLSingleView::loadImage() { loadingImage = true; ThumbItem *item = m_itemList.at(m_pos); if (!item) { std::cerr << "GLSingleView: The impossible happened. No item at " << m_pos << std::endl; return; } QImage image(item->path); if (!image.isNull()) { double scale_factor_w = aspect_w / aspect_h; int a = m_tex1First ? 0 : 1; TexItem& t = m_texItem[a]; t.item = item; t.angle = 0; QString queryStr = "SELECT angle FROM gallerymetadata WHERE " "image=\"" + item->path + "\";"; QSqlQuery query = m_db->exec(queryStr); if (query.isActive() && query.numRowsAffected() > 0) { query.next(); t.angle = query.value(0).toInt(); } t.width = (int)round(image.width() * scale_factor_w); t.height = (int)round(image.height()); printf("angle: %d, %d, %d\n", t.angle, t.width, t.height); /*if (t.angle%180 != 0) { int tmp = t.width; t.width = t.height; t.height = tmp; }*/ printf("angle: %d, %d, %d\n", t.angle, t.width, t.height); QSize sz(t.width,t.height); sz.scale(screenwidth, screenheight, QSize::ScaleMin); t.cx = (float)sz.width()/(float)screenwidth; t.cy = (float)sz.height()/(float)screenheight; //image = image.smoothScale(m_w, m_h); QImage tex = convertToGLFormat(image); /*if (t.tex) { glDeleteTextures(1, &t.tex); }*/ /* create the texture */ if(!t.tex) { printf("Create texture\n"); glGenTextures(1, &t.tex); } glMatrixMode(GL_TEXTURE); #ifdef GL_ARB_texture_rectangle glBindTexture(GL_TEXTURE_RECTANGLE_ARB, t.tex); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexImage2D(GL_PROXY_TEXTURE_RECTANGLE_ARB, 0, 3, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); GLint _width, _height; glGetTexLevelParameteriv(GL_PROXY_TEXTURE_RECTANGLE_ARB, 0, GL_TEXTURE_WIDTH, &_width); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_RECTANGLE_ARB, 0, GL_TEXTURE_HEIGHT, &_height); printf("w: %d, h: %d\n", (int)_width, (int)_height); if(_width && _height) { glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 3, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits()); glError(); } else fprintf(stderr, "Image too big\n"); #else glBindTexture(GL_TEXTURE_2D, t.tex); /* actually generate the texture */ glTexImage2D( GL_TEXTURE_2D, 0, 3, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits() ); /* enable linear filtering */ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); #endif glFinish(); glError(); } loadingImage = false; } void GLSingleView::paintTexture() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(m_sx, m_sy, 0.0); glScalef(m_zoom, m_zoom, 1.0); TexItem& t = m_texItem[m_curr]; glMatrixMode(GL_TEXTURE); glLoadIdentity(); glRotatef(90, 0.0, 0.0, 1.0); #ifdef GL_ARB_texture_rectangle glBindTexture(GL_TEXTURE_RECTANGLE_ARB, t.tex); glBegin(GL_QUADS); { glColor4f(1.0, 1.0, 1.0, 1.0); glTexCoord2f(0, 0); glVertex2f(-t.cx, -t.cy); glTexCoord2f(t.width, 0); glVertex2f(t.cx, -t.cy); glTexCoord2f(t.width, t.height); glVertex2f(t.cx, t.cy); glTexCoord2f(0, t.height); glVertex2f(-t.cx, t.cy); } glEnd(); #else glBindTexture(GL_TEXTURE_2D, t.tex); glBegin(GL_QUADS); { glColor4f(1.0, 1.0, 1.0, 1.0); glTexCoord2f(0, 0); glVertex3f(-t.cx, -t.cy, 0); glTexCoord2f(1, 0); glVertex3f(t.cx, -t.cy, 0); glTexCoord2f(1, 1); glVertex3f(t.cx, t.cy, 0); glTexCoord2f(0, 1); glVertex3f(-t.cx, t.cy, 0); } glEnd(); #endif if (m_showInfo) { createTexInfo(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); #ifdef GL_ARB_texture_rectangle glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_texInfo); glBegin(GL_QUADS); { glColor4f(1.0, 1.0, 1.0, 0.72); glTexCoord2f(0, 0); glVertex3f(-0.75, -0.75, 0); glTexCoord2f(512, 0); glVertex3f(0.75, -0.75, 0); glTexCoord2f(512, 512); glVertex3f(0.75, 0.75, 0); glTexCoord2f(0, 512); glVertex3f(-0.75, 0.75, 0); } glEnd(); #else glBindTexture(GL_TEXTURE_2D, m_texInfo); glBegin(GL_QUADS); { glColor4f(1.0, 1.0, 1.0, 0.72); glTexCoord2f(0, 0); glVertex3f(-0.75, -0.75, 0); glTexCoord2f(1, 0); glVertex3f(0.75, -0.75, 0); glTexCoord2f(1, 1); glVertex3f(0.75, 0.75, 0); glTexCoord2f(0, 1); glVertex3f(-0.75, 0.75, 0); } glEnd(); #endif } }