2013-06-02 15:08:32 +00:00
|
|
|
#include "ImageComponent.h"
|
2012-08-02 01:43:55 +00:00
|
|
|
#include <iostream>
|
2012-08-09 21:19:07 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2012-09-07 21:44:07 +00:00
|
|
|
#include <math.h>
|
2013-01-04 23:31:51 +00:00
|
|
|
#include "../Log.h"
|
2013-04-08 17:40:15 +00:00
|
|
|
#include "../Renderer.h"
|
2012-08-02 01:43:55 +00:00
|
|
|
|
2013-06-02 22:33:49 +00:00
|
|
|
Vector2u ImageComponent::getTextureSize() { return mTextureSize; }
|
2012-08-09 21:19:07 +00:00
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
ImageComponent::ImageComponent(Window* window, int offsetX, int offsetY, std::string path, unsigned int resizeWidth, unsigned int resizeHeight, bool allowUpscale) : GuiComponent(window)
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
2012-08-29 18:53:53 +00:00
|
|
|
mTextureID = 0;
|
2012-08-09 21:19:07 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
setOffset(Vector2i(offsetX, offsetY));
|
2012-08-09 21:19:07 +00:00
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
//default origin is the center of image
|
2013-06-02 21:05:29 +00:00
|
|
|
mOrigin.x = 0.5;
|
|
|
|
mOrigin.y = 0.5;
|
2012-08-13 18:32:53 +00:00
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
mOpacity = 255;
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-08-13 18:32:53 +00:00
|
|
|
mTiled = false;
|
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
mTargetSize.x = resizeWidth;
|
|
|
|
mTargetSize.y = resizeHeight;
|
2012-08-13 18:32:53 +00:00
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
mAllowUpscale = allowUpscale;
|
2012-08-09 21:19:07 +00:00
|
|
|
|
2012-10-07 22:25:51 +00:00
|
|
|
mFlipX = false;
|
|
|
|
mFlipY = false;
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
if(!path.empty())
|
|
|
|
setImage(path);
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
ImageComponent::~ImageComponent()
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
2012-08-29 18:53:53 +00:00
|
|
|
unloadImage();
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::loadImage(std::string path)
|
2012-08-09 21:19:07 +00:00
|
|
|
{
|
2012-08-29 18:53:53 +00:00
|
|
|
//make sure the file *exists*
|
|
|
|
if(!boost::filesystem::exists(path))
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
2013-06-02 21:05:29 +00:00
|
|
|
LOG(LogError) << "Image \"" << path << "\" not found!";
|
2012-08-29 18:53:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-09 21:19:07 +00:00
|
|
|
|
2012-09-04 16:45:16 +00:00
|
|
|
//make sure we don't already have an image
|
|
|
|
unloadImage();
|
|
|
|
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
FREE_IMAGE_FORMAT format = FIF_UNKNOWN;
|
|
|
|
FIBITMAP* image = NULL;
|
|
|
|
BYTE* imageData = NULL;
|
|
|
|
unsigned int width, height;
|
2012-08-09 21:19:07 +00:00
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
//detect the filetype
|
2012-09-07 21:44:07 +00:00
|
|
|
format = FreeImage_GetFileType(path.c_str(), 0);
|
2012-08-29 18:53:53 +00:00
|
|
|
if(format == FIF_UNKNOWN)
|
|
|
|
format = FreeImage_GetFIFFromFilename(path.c_str());
|
|
|
|
if(format == FIF_UNKNOWN)
|
|
|
|
{
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogError) << "Error - could not detect filetype for image \"" << path << "\"!";
|
2012-08-29 18:53:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-09 21:19:07 +00:00
|
|
|
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
//make sure we can read this filetype first, then load it
|
|
|
|
if(FreeImage_FIFSupportsReading(format))
|
|
|
|
{
|
|
|
|
image = FreeImage_Load(format, path.c_str());
|
|
|
|
}else{
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogError) << "Error - file format reading not supported for image \"" << path << "\"!";
|
2012-08-29 18:53:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-13 18:32:53 +00:00
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
//make sure it loaded properly
|
|
|
|
if(!image)
|
|
|
|
{
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogError) << "Error loading image \"" << path << "\"!";
|
2012-08-29 18:53:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-10 19:28:34 +00:00
|
|
|
|
2012-08-29 19:22:05 +00:00
|
|
|
//convert to 32bit
|
|
|
|
FIBITMAP* imgConv = FreeImage_ConvertTo32Bits(image);
|
|
|
|
FreeImage_Unload(image);
|
|
|
|
image = imgConv;
|
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
//get a pointer to the image data as BGRA
|
2012-08-29 18:53:53 +00:00
|
|
|
imageData = FreeImage_GetBits(image);
|
|
|
|
if(!imageData)
|
|
|
|
{
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogError) << "Error retriving bits from image \"" << path << "\"!";
|
2012-08-29 18:53:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-02 01:43:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
width = FreeImage_GetWidth(image);
|
|
|
|
height = FreeImage_GetHeight(image);
|
2012-08-13 18:32:53 +00:00
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
//if width or height are zero then something is clearly wrong
|
2012-08-29 18:53:53 +00:00
|
|
|
if(!width || !height)
|
|
|
|
{
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogError) << "Width or height are zero for image \"" << path << "\"!";
|
2012-09-07 21:44:07 +00:00
|
|
|
FreeImage_Unload(image);
|
2012-08-29 18:53:53 +00:00
|
|
|
return;
|
2012-08-10 02:17:48 +00:00
|
|
|
}
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-08-29 19:22:05 +00:00
|
|
|
//convert from BGRA to RGBA
|
|
|
|
GLubyte* imageRGBA = new GLubyte[4*width*height];
|
|
|
|
for(unsigned int i = 0; i < width*height; i++)
|
|
|
|
{
|
|
|
|
imageRGBA[i*4+0] = imageData[i*4+2];
|
|
|
|
imageRGBA[i*4+1] = imageData[i*4+1];
|
|
|
|
imageRGBA[i*4+2] = imageData[i*4+0];
|
|
|
|
imageRGBA[i*4+3] = imageData[i*4+3];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
//now for the openGL texture stuff
|
|
|
|
glGenTextures(1, &mTextureID);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mTextureID);
|
2012-08-29 19:22:05 +00:00
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageRGBA);
|
|
|
|
|
2013-01-08 17:19:38 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2012-10-01 03:29:55 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-10-10 15:21:03 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
mTextureSize.x = width;
|
|
|
|
mTextureSize.y = height;
|
2012-08-29 18:53:53 +00:00
|
|
|
|
|
|
|
//free the image data
|
|
|
|
FreeImage_Unload(image);
|
|
|
|
|
2012-08-29 19:22:05 +00:00
|
|
|
//free the memory from that pointer
|
|
|
|
delete[] imageRGBA;
|
|
|
|
|
2012-10-05 20:04:12 +00:00
|
|
|
resize();
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::resize()
|
2012-10-05 20:04:12 +00:00
|
|
|
{
|
2013-06-02 21:05:29 +00:00
|
|
|
mSize.x = mTextureSize.x;
|
|
|
|
mSize.y = mTextureSize.y;
|
2012-10-05 20:04:12 +00:00
|
|
|
|
2012-08-29 21:52:25 +00:00
|
|
|
//(we don't resize tiled images)
|
2013-06-02 21:05:29 +00:00
|
|
|
if(!mTiled && (mTargetSize.x || mTargetSize.y))
|
2012-08-29 21:52:25 +00:00
|
|
|
{
|
2013-06-02 21:05:29 +00:00
|
|
|
Vector2f resizeScale;
|
2012-08-29 21:52:25 +00:00
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
if(mTargetSize.x && (mAllowUpscale || mSize.x > mTargetSize.x))
|
|
|
|
{
|
|
|
|
resizeScale.x = (float)mTargetSize.x / mSize.x;
|
|
|
|
}
|
|
|
|
if(mTargetSize.y && (mAllowUpscale || mSize.y > mTargetSize.y))
|
|
|
|
{
|
|
|
|
resizeScale.y = (float)mTargetSize.y / mSize.y;
|
2012-08-29 21:52:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
if(resizeScale.x && !resizeScale.y)
|
|
|
|
resizeScale.y = resizeScale.x;
|
|
|
|
if(resizeScale.y && !resizeScale.x)
|
|
|
|
resizeScale.x = resizeScale.y;
|
2012-08-29 21:52:25 +00:00
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
if(resizeScale.x)
|
|
|
|
mSize.x = (int)(mSize.x * resizeScale.x);
|
|
|
|
if(resizeScale.y)
|
|
|
|
mSize.y = (int)(mSize.y * resizeScale.y);
|
2012-08-29 21:52:25 +00:00
|
|
|
}
|
2013-06-02 22:33:49 +00:00
|
|
|
|
|
|
|
if(mTiled)
|
|
|
|
{
|
|
|
|
mSize = mTargetSize;
|
|
|
|
}
|
2012-08-09 21:19:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::unloadImage()
|
2012-08-13 18:32:53 +00:00
|
|
|
{
|
2012-08-29 18:53:53 +00:00
|
|
|
if(mTextureID)
|
2012-08-13 18:32:53 +00:00
|
|
|
{
|
2012-08-29 18:53:53 +00:00
|
|
|
glDeleteTextures(1, &mTextureID);
|
2012-08-13 18:32:53 +00:00
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
mTextureID = 0;
|
2012-08-13 18:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::setImage(std::string path)
|
2012-08-09 21:19:07 +00:00
|
|
|
{
|
2012-08-10 02:17:48 +00:00
|
|
|
if(mPath == path)
|
|
|
|
return;
|
2012-08-09 21:19:07 +00:00
|
|
|
|
2012-08-10 02:17:48 +00:00
|
|
|
mPath = path;
|
|
|
|
|
2012-08-29 18:53:53 +00:00
|
|
|
unloadImage();
|
2012-08-10 02:17:48 +00:00
|
|
|
if(!path.empty())
|
|
|
|
loadImage(path);
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::setOrigin(float originX, float originY)
|
2012-08-13 18:32:53 +00:00
|
|
|
{
|
2013-06-02 21:05:29 +00:00
|
|
|
mOrigin.x = originX;
|
|
|
|
mOrigin.y = originY;
|
2012-08-13 18:32:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::setTiling(bool tile)
|
2012-08-13 18:32:53 +00:00
|
|
|
{
|
|
|
|
mTiled = tile;
|
|
|
|
|
|
|
|
if(mTiled)
|
2013-06-02 21:05:29 +00:00
|
|
|
mAllowUpscale = false;
|
2013-06-02 22:33:49 +00:00
|
|
|
|
|
|
|
resize();
|
2012-08-13 18:32:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 21:05:29 +00:00
|
|
|
void ImageComponent::setResize(unsigned int width, unsigned int height, bool allowUpscale)
|
2012-10-05 20:04:12 +00:00
|
|
|
{
|
2013-06-02 21:05:29 +00:00
|
|
|
mTargetSize.x = width;
|
|
|
|
mTargetSize.y = height;
|
|
|
|
mAllowUpscale = allowUpscale;
|
2012-10-05 20:04:12 +00:00
|
|
|
resize();
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::setFlipX(bool flip)
|
2012-10-07 22:25:51 +00:00
|
|
|
{
|
|
|
|
mFlipX = flip;
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::setFlipY(bool flip)
|
2012-10-07 22:25:51 +00:00
|
|
|
{
|
|
|
|
mFlipY = flip;
|
|
|
|
}
|
|
|
|
|
2013-06-02 19:34:50 +00:00
|
|
|
void ImageComponent::onRender()
|
2012-08-02 01:43:55 +00:00
|
|
|
{
|
2012-10-17 17:15:58 +00:00
|
|
|
if(mTextureID && getOpacity() > 0)
|
2012-08-13 18:32:53 +00:00
|
|
|
{
|
2012-10-17 17:15:58 +00:00
|
|
|
GLfloat points[12], texs[12];
|
|
|
|
GLubyte colors[6*4];
|
|
|
|
|
2012-08-29 21:52:25 +00:00
|
|
|
if(mTiled)
|
|
|
|
{
|
2013-06-02 22:33:49 +00:00
|
|
|
float xCount = (float)mSize.x / mTextureSize.x;
|
|
|
|
float yCount = (float)mSize.y / mTextureSize.y;
|
2013-06-02 21:05:29 +00:00
|
|
|
|
2012-10-17 18:21:56 +00:00
|
|
|
Renderer::buildGLColorArray(colors, 0xFFFFFF00 | (getOpacity()), 6);
|
2013-06-02 19:34:50 +00:00
|
|
|
buildImageArray(0, 0, points, texs, xCount, yCount);
|
2012-08-29 21:52:25 +00:00
|
|
|
}else{
|
2012-10-17 18:21:56 +00:00
|
|
|
Renderer::buildGLColorArray(colors, 0xFFFFFF00 | (getOpacity()), 6);
|
2013-06-02 19:34:50 +00:00
|
|
|
buildImageArray(0, 0, points, texs);
|
2012-08-29 21:52:25 +00:00
|
|
|
}
|
2012-10-17 17:15:58 +00:00
|
|
|
|
|
|
|
drawImageArray(points, texs, colors, 6);
|
2012-08-29 21:52:25 +00:00
|
|
|
}
|
2013-06-02 19:34:50 +00:00
|
|
|
|
|
|
|
GuiComponent::onRender();
|
2012-08-29 21:52:25 +00:00
|
|
|
}
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::buildImageArray(int posX, int posY, GLfloat* points, GLfloat* texs, float px, float py)
|
2012-08-29 21:52:25 +00:00
|
|
|
{
|
2013-06-02 22:33:49 +00:00
|
|
|
points[0] = posX - (mSize.x * mOrigin.x); points[1] = posY - (mSize.y * mOrigin.y);
|
|
|
|
points[2] = posX - (mSize.x * mOrigin.x); points[3] = posY + (mSize.y * (1 - mOrigin.y));
|
|
|
|
points[4] = posX + (mSize.x * (1 - mOrigin.x)); points[5] = posY - (mSize.y * mOrigin.y);
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2013-06-02 22:33:49 +00:00
|
|
|
points[6] = posX + (mSize.x * (1 - mOrigin.x)); points[7] = posY - (mSize.y * mOrigin.y);
|
|
|
|
points[8] = posX - (mSize.x * mOrigin.x); points[9] = posY + (mSize.y * (1 - mOrigin.y));
|
|
|
|
points[10] = posX + (mSize.x * (1 -mOrigin.x)); points[11] = posY + (mSize.y * (1 - mOrigin.y));
|
2012-08-29 18:53:53 +00:00
|
|
|
|
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
|
2012-10-10 15:26:14 +00:00
|
|
|
texs[0] = 0; texs[1] = py;
|
2012-10-10 15:21:03 +00:00
|
|
|
texs[2] = 0; texs[3] = 0;
|
2012-10-10 15:26:14 +00:00
|
|
|
texs[4] = px; texs[5] = py;
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-10-10 15:26:14 +00:00
|
|
|
texs[6] = px; texs[7] = py;
|
2012-10-10 15:21:03 +00:00
|
|
|
texs[8] = 0; texs[9] = 0;
|
2012-10-10 15:26:14 +00:00
|
|
|
texs[10] = px; texs[11] = 0;
|
2012-10-07 22:25:51 +00:00
|
|
|
|
|
|
|
if(mFlipX)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 11; i += 2)
|
2012-10-10 15:26:14 +00:00
|
|
|
if(texs[i] == px)
|
2012-10-10 15:21:03 +00:00
|
|
|
texs[i] = 0;
|
|
|
|
else
|
2012-10-10 15:26:14 +00:00
|
|
|
texs[i] = px;
|
2012-10-07 22:25:51 +00:00
|
|
|
}
|
|
|
|
if(mFlipY)
|
|
|
|
{
|
|
|
|
for(int i = 1; i < 12; i += 2)
|
2012-10-10 15:26:14 +00:00
|
|
|
if(texs[i] == py)
|
2012-10-10 15:21:03 +00:00
|
|
|
texs[i] = 0;
|
|
|
|
else
|
2012-10-10 15:26:14 +00:00
|
|
|
texs[i] = py;
|
2012-10-07 22:25:51 +00:00
|
|
|
}
|
2012-09-07 21:44:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::drawImageArray(GLfloat* points, GLfloat* texs, GLubyte* colors, unsigned int numArrays)
|
2012-09-07 21:44:07 +00:00
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mTextureID);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-08-29 21:52:25 +00:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-10-17 17:15:58 +00:00
|
|
|
if(colors != NULL)
|
|
|
|
{
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
|
|
|
|
}
|
|
|
|
|
2012-08-29 21:52:25 +00:00
|
|
|
glVertexPointer(2, GL_FLOAT, 0, points);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, texs);
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, numArrays);
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-08-29 21:52:25 +00:00
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-10-17 17:15:58 +00:00
|
|
|
if(colors != NULL)
|
|
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
|
|
|
|
2012-08-29 21:52:25 +00:00
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glDisable(GL_BLEND);
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
2012-09-04 16:45:16 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::init()
|
2012-09-04 16:45:16 +00:00
|
|
|
{
|
|
|
|
if(!mPath.empty())
|
|
|
|
loadImage(mPath);
|
2013-06-02 21:05:29 +00:00
|
|
|
|
|
|
|
GuiComponent::init();
|
2012-09-04 16:45:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void ImageComponent::deinit()
|
2012-09-04 16:45:16 +00:00
|
|
|
{
|
|
|
|
unloadImage();
|
2013-06-02 21:05:29 +00:00
|
|
|
|
|
|
|
GuiComponent::deinit();
|
2012-09-04 16:45:16 +00:00
|
|
|
}
|
2012-10-10 13:51:48 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
bool ImageComponent::hasImage()
|
2012-10-10 13:51:48 +00:00
|
|
|
{
|
|
|
|
return !mPath.empty();
|
|
|
|
}
|
2013-04-08 16:52:40 +00:00
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
unsigned char ImageComponent::getOpacity() { return mOpacity; }
|
|
|
|
void ImageComponent::setOpacity(unsigned char opacity) { mOpacity = opacity; }
|
2013-06-16 21:23:04 +00:00
|
|
|
|
|
|
|
void ImageComponent::copyScreen()
|
|
|
|
{
|
|
|
|
unloadImage();
|
|
|
|
|
2013-06-20 00:56:45 +00:00
|
|
|
int width = Renderer::getScreenWidth();
|
|
|
|
int height = Renderer::getScreenHeight();
|
|
|
|
|
|
|
|
//glReadBuffer(GL_FRONT);
|
|
|
|
|
|
|
|
/*char* data = new char[width*height*3];
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
|
|
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);*/
|
2013-06-16 21:23:04 +00:00
|
|
|
|
|
|
|
glGenTextures(1, &mTextureID);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mTextureID);
|
|
|
|
|
2013-06-20 00:56:45 +00:00
|
|
|
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
|
|
|
//delete[] data;
|
2013-06-16 21:23:04 +00:00
|
|
|
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, width, height, 0);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
|
|
|
|
mTextureSize.x = height;
|
|
|
|
mTextureSize.y = height;
|
|
|
|
|
|
|
|
resize();
|
|
|
|
}
|