#include "StdInc.h" #include #include #include "Images.h" #include "../UIFramework/GL2D.h" namespace Gfx { /*********** CImage ***********/ CImage::~CImage() { unloadFromVideoRAM(); } void CImage::loadToVideoRAM() { if (texHandle > 0) return; glGenTextures(1, &texHandle); glBindTexture(GL_TEXTURE_RECTANGLE, texHandle); GL2D::checkErrors("CImage::loadToVideoRAM"); textureTransfer(); } void CImage::unloadFromVideoRAM() { glDeleteTextures(1, &texHandle); texHandle = 0; } void CImage::bindTexture() { if (texHandle > 0) { glBindTexture(GL_TEXTURE_RECTANGLE, texHandle); return; } glGenTextures(1, &texHandle); glBindTexture(GL_TEXTURE_RECTANGLE, texHandle); textureTransfer(); } /*********** CBitmap32::QuadInstance ***********/ CBitmap32::QuadInstance::QuadInstance(Point p) : coords() { for (int i=0; i<4; ++i) coords[i].vertex = p; } void CBitmap32::QuadInstance::setOffset(TransformFlags flags, si32 x, si32 y) { if (flags & ROTATE_90_DEG) { } else { } } void CBitmap32::QuadInstance::transform(TransformFlags flags, ui32 w0, ui32 h0, ui32 w, ui32 h) { if (flags & MIRROR_HORIZ) { coords[0].vertex.x += w; coords[3].vertex.x += w; } else { coords[1].vertex.x += w; coords[2].vertex.x += w; } if (flags & MIRROR_VERTIC) { coords[0].vertex.y += h; coords[1].vertex.y += h; } else { coords[2].vertex.y += h; coords[3].vertex.y += h; } if (flags & ROTATE_90_DEG) { coords[0].texture.x = w0; coords[1].texture.x = w0; coords[1].texture.y = h0; coords[2].texture.y = h0; } else { coords[1].texture.x = w0; coords[2].texture.x = w0; coords[2].texture.y = h0; coords[3].texture.y = h0; } } void CBitmap32::QuadInstance::putToGL() const { glBegin(GL_QUADS); for (int i=0; i<4; ++i) { const CoordBind& row = coords[i]; glTexCoord2i(row.texture.x, row.texture.y); glVertex2i(row.vertex.x, row.vertex.y); } glEnd(); } /*********** CBitmap32 ***********/ CBitmap32::CBitmap32(ui32 w, ui32 h, const ColorRGB pixBuff[], bool bgra) : CImage(w, h), formatBGRA(bgra) { const ui32 pixNum = w * h; buffer = new ColorRGBA[pixNum]; for (ui32 it=0; it