00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qimage.h>
00025
00026
00027 #include "thumbview.h"
00028 #include "gltexture.h"
00029 #include "galleryutil.h"
00030
00034 void GLTexture::Init(const QImage &image)
00035 {
00036 Deinit();
00037 glGenTextures(1, &tex);
00038 glBindTexture(GL_TEXTURE_2D, tex);
00039
00040
00041 glTexImage2D(GL_TEXTURE_2D, 0, 3, image.width(), image.height(), 0,
00042 GL_RGBA, GL_UNSIGNED_BYTE, image.bits());
00043
00044
00045 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00046 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00047 }
00048
00052 void GLTexture::Deinit(void)
00053 {
00054 if (tex)
00055 glDeleteTextures(1, &tex);
00056 }
00057
00058 void GLTexture::Bind(void)
00059 {
00060 glMatrixMode(GL_TEXTURE);
00061 glLoadIdentity();
00062 glRotatef(GetAngle(), 0.0f, 0.0f, 1.0f);
00063 glBindTexture(GL_TEXTURE_2D, tex);
00064 }
00065
00066 void GLTexture::MakeQuad(float alpha, float scale)
00067 {
00068 Bind();
00069
00070 glBegin(GL_QUADS);
00071 glColor4f(1.0f, 1.0f, 1.0f, alpha);
00072
00073 glTexCoord2f(0.0f, 0.0f);
00074 glVertex3f(-GetTextureX() * scale, -GetTextureY() * scale, 0.0f);
00075
00076 glTexCoord2f(1.0f, 0.0f);
00077 glVertex3f(+GetTextureX() * scale, -GetTextureY() * scale, 0.0f);
00078
00079 glTexCoord2f(1.0f, 1.0f);
00080 glVertex3f(+GetTextureX() * scale, +GetTextureY() * scale, 0.0f);
00081
00082 glTexCoord2f(0.0f, 1.0f);
00083 glVertex3f(-GetTextureX() * scale, +GetTextureY() * scale, 0.0f);
00084 glEnd();
00085 }
00086
00087 void GLTexture::ScaleTo(const QSize &dest, bool scaleMax)
00088 {
00089 QSize sz = GalleryUtil::ScaleToDest(GetSize(), dest, scaleMax);
00090 if ((sz.width() > 0) && (sz.height() > 0) &&
00091 (dest.width() > 0) && (dest.height() > 0))
00092 {
00093 SetScale((float)sz.width() / (float)dest.width(),
00094 (float)sz.height() / (float)dest.height());
00095 }
00096 }
00097
00098 void GLTexture::SetItem(ThumbItem *thumbItem, const QSize &sz)
00099 {
00100 item = thumbItem;
00101 if (item)
00102 {
00103 angle = item->GetRotationAngle();
00104 SetSize(sz);
00105
00106 if (angle % 180 != 0)
00107 SwapWidthHeight();
00108 }
00109 }
00110
00111 QString GLTexture::GetDescription(const QString &status) const
00112 {
00113 if (item)
00114 return item->GetDescription(status, GetSize(), angle);
00115
00116 return QString::null;
00117 }