start 380 project5
changes to 380 project 4 changes to 350 project 2 Signed-off-by: Amrit Panesar <apanesar@4195tech.com>
This commit is contained in:
1 parent
40ac78074b
commit
39ee821f54
174 files changed
+13356
-80
No files matched your search
@@ -0,0 +1,50 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkAnimatedFont.h"
|
||||
|
||||
#include "..\Utils\GkStrings.h"
|
||||
|
||||
|
||||
GkAnimatedFont::GkAnimatedFont(const wchar_t *charMap, int numFrames, float framesPerSecond)
|
||||
{
|
||||
this->charMap = GkStrings::Copy(charMap);
|
||||
this->numFrames = numFrames;
|
||||
this->numLetters = GkStrings::GetLength(charMap);
|
||||
this->framesPerSecond = framesPerSecond;
|
||||
|
||||
this->letterTextures = new GkAnimatedTexture*[this->numLetters];
|
||||
for (int i = 0; i < this->numLetters; i++)
|
||||
{
|
||||
this->letterTextures[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GkAnimatedFont::~GkAnimatedFont(void)
|
||||
{
|
||||
delete[] this->charMap;
|
||||
|
||||
for (int i = 0; i < this->numLetters; i++)
|
||||
{
|
||||
delete this->letterTextures[i];
|
||||
}
|
||||
delete[] this->letterTextures;
|
||||
}
|
||||
|
||||
void GkAnimatedFont::LoadAnimatedLetter(int letterIndex, void *data, int dataSize)
|
||||
{
|
||||
if (this->letterTextures[letterIndex] != 0)
|
||||
delete this->letterTextures[letterIndex];
|
||||
|
||||
this->letterTextures[letterIndex] = new GkAnimatedTexture(data, dataSize, 1, this->numFrames, this->numFrames);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include "..\Base\GkBase.h"
|
||||
#include "GkAnimatedTexture.h"
|
||||
|
||||
class GKDLLCLASS GkAnimatedFont :
|
||||
public GkBase
|
||||
{
|
||||
public:
|
||||
wchar_t *charMap;
|
||||
int numLetters, numFrames;
|
||||
|
||||
float framesPerSecond;
|
||||
|
||||
GkAnimatedTexture **letterTextures;
|
||||
|
||||
GkAnimatedFont::GkAnimatedFont(const wchar_t *charMap, int numFrames, float framesPerSecond = 25.0f);
|
||||
GkAnimatedFont::~GkAnimatedFont(void);
|
||||
|
||||
void GkAnimatedFont::LoadAnimatedLetter(int letterIndex, void *data, int dataSize);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkAnimatedTexture.h"
|
||||
|
||||
GkAnimatedTexture::GkAnimatedTexture(void)
|
||||
{
|
||||
this->numFrames = 0;
|
||||
}
|
||||
|
||||
GkAnimatedTexture::GkAnimatedTexture(void* data, unsigned int dataSize, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
|
||||
{
|
||||
this->numFrames = 0;
|
||||
|
||||
this->LoadFromMemory(data, dataSize, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
|
||||
}
|
||||
|
||||
GkAnimatedTexture::GkAnimatedTexture(char *fileName, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
|
||||
{
|
||||
this->numFrames = 0;
|
||||
|
||||
this->LoadFromFile(fileName, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
|
||||
}
|
||||
|
||||
GkAnimatedTexture::~GkAnimatedTexture(void)
|
||||
{
|
||||
this->Free();
|
||||
}
|
||||
|
||||
void GkAnimatedTexture::Free()
|
||||
{
|
||||
if (this->numFrames == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < this->numFrames; i++)
|
||||
{
|
||||
delete this->frames[i];
|
||||
}
|
||||
|
||||
delete this->frames;
|
||||
|
||||
this->numFrames = 0;
|
||||
}
|
||||
|
||||
bool GkAnimatedTexture::LoadFromImage(GkImage *image, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
|
||||
{
|
||||
this->Free();
|
||||
|
||||
this->numFrames = numFrames != 0 ? numFrames : columnFrames * rowFrames;
|
||||
this->framesPerSecond = framesPerSecond;
|
||||
|
||||
this->frames = new GkTexture*[this->numFrames];
|
||||
|
||||
int frameWidth = image->width / columnFrames;
|
||||
int frameHeight = image->height / rowFrames;
|
||||
|
||||
int iMax, jMax;
|
||||
if (animatedTexture_LoadOrder == GkAnimatedTexture::LoadOrder_Vertical)
|
||||
{
|
||||
jMax = columnFrames;
|
||||
iMax = rowFrames;
|
||||
}
|
||||
else
|
||||
{
|
||||
jMax = rowFrames;
|
||||
iMax = columnFrames;
|
||||
}
|
||||
|
||||
int frameIndex = 0;
|
||||
for (int j = 0; j < jMax; j++)
|
||||
{
|
||||
for (int i = 0; i < iMax; i++)
|
||||
{
|
||||
int x, y;
|
||||
if (animatedTexture_LoadOrder == GkAnimatedTexture::LoadOrder_Vertical)
|
||||
{
|
||||
x = j;
|
||||
y = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = i;
|
||||
y = j;
|
||||
}
|
||||
|
||||
GkTexture *frame = new GkTexture();
|
||||
frame->LoadFromImage(image, x * frameWidth, y * frameHeight, frameWidth, frameHeight);
|
||||
|
||||
frames[frameIndex++] = frame;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GkAnimatedTexture::LoadFromMemory(void* data, unsigned int dataSize, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
|
||||
{
|
||||
GkImage image;
|
||||
image.LoadFromMemory(data, dataSize);
|
||||
|
||||
this->LoadFromImage(&image, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GkAnimatedTexture::LoadFromFile(char *fileName, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
|
||||
{
|
||||
GkImage image;
|
||||
image.LoadFromFile(fileName);
|
||||
|
||||
this->LoadFromImage(&image, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include "..\Base\GkBase.h"
|
||||
#include "GkTexture.h"
|
||||
|
||||
class GKDLLCLASS GkAnimatedTexture :
|
||||
public GkBase
|
||||
{
|
||||
public:
|
||||
static const int LoadOrder_Horizontal = 0,
|
||||
LoadOrder_Vertical = 1;
|
||||
|
||||
GkTexture **frames;
|
||||
int numFrames;
|
||||
float framesPerSecond;
|
||||
|
||||
GkAnimatedTexture::GkAnimatedTexture(void);
|
||||
GkAnimatedTexture::GkAnimatedTexture(void* data, unsigned int dataSize, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
|
||||
GkAnimatedTexture::GkAnimatedTexture(char *fileName, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
|
||||
GkAnimatedTexture::~GkAnimatedTexture(void);
|
||||
|
||||
void GkAnimatedTexture::Free();
|
||||
bool GkAnimatedTexture::LoadFromImage(GkImage *image, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
|
||||
bool GkAnimatedTexture::LoadFromMemory(void* data, unsigned int dataSize, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
|
||||
bool GkAnimatedTexture::LoadFromFile(char *fileName, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGraphicsDevice.h"
|
||||
|
||||
#include "..\Utils\GkMaths.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <GL\GLUt.h>
|
||||
#include <string.h>
|
||||
|
||||
void GkGraphicsDevice::Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
GkGraphicsDevice::GkGraphicsDevice(void)
|
||||
{
|
||||
this->SetViewport(0, 0, 640, 480);
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_REPLACE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &this->maxTextureSize);
|
||||
this->nonPower2Textures = strstr((char*)glGetString(GL_EXTENSIONS),"GL_ARB_texture_non_power_of_two") != 0;
|
||||
|
||||
GkTexture::powerOfTwo = !this->nonPower2Textures;
|
||||
}
|
||||
|
||||
|
||||
GkGraphicsDevice::~GkGraphicsDevice(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GkGraphicsDevice::Clear()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void GkGraphicsDevice::Draw(int destX, int destY, int destWidth, int destHeight, int srcX, int srcY, int srcWidth, int srcHeight, GkTexture* texture)
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, this->width, this->height, 0, 1, -1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(destX, destY, 0);
|
||||
glScalef(destWidth, destHeight, 1);
|
||||
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glLoadIdentity();
|
||||
glTranslatef(srcX / (float)texture->textureWidth, srcY / (float)texture->textureHeight, 0.0f);
|
||||
glScalef(srcWidth / (float)texture->textureWidth, srcHeight / (float)texture->textureHeight, 1.0f);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture->handle);
|
||||
|
||||
GLint filtering = (destWidth != srcWidth) || (destHeight != srcHeight) ? GL_LINEAR : GL_NEAREST;
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glTexCoord2f(0.0f, 0.0f);
|
||||
glVertex3f(0.0f, 0.0f, 0.0f);
|
||||
|
||||
glTexCoord2f(0.0f, 1.0f);
|
||||
glVertex3f(0.0f, 1.0f, 0.0f);
|
||||
|
||||
glTexCoord2f(1.0f, 1.0f);
|
||||
glVertex3f(1.0f, 1.0f, 0.0f);
|
||||
|
||||
|
||||
glTexCoord2f(0.0f, 0.0f);
|
||||
glVertex3f(0.0f, 0.0f, 0.0f);
|
||||
|
||||
glTexCoord2f(1.0f, 1.0f);
|
||||
glVertex3f(1.0f, 1.0f, 0.0f);
|
||||
|
||||
glTexCoord2f(1.0f, 0.0f);
|
||||
glVertex3f(1.0f, 0.0f, 0.0f);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void GkGraphicsDevice::Draw(int x, int y, GkTexture* texture)
|
||||
{
|
||||
this->Draw(x, y, texture->width, texture->height, 0, 0, texture->width, texture->height, texture);
|
||||
}
|
||||
|
||||
void GkGraphicsDevice::DrawClipped(int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, GkTexture* texture)
|
||||
{
|
||||
int clipLeft = clipX - x;
|
||||
int clipTop = clipY - y;
|
||||
|
||||
int destX = clipLeft > 0 ? clipX : x;
|
||||
int destY = clipTop > 0 ? clipY : y;
|
||||
int width = GkMaths::Min(texture->width - GkMaths::Max(clipLeft, 0), GkMaths::Min(clipX + clipWidth - destX, texture->width));
|
||||
int height = GkMaths::Min(texture->height - GkMaths::Max(clipTop, 0), GkMaths::Min(clipY + clipHeight - destY, texture->height));
|
||||
|
||||
if ((width <= 0) || (height <= 0))
|
||||
return;
|
||||
|
||||
int srcX = clipLeft > 0 ? clipLeft : 0;
|
||||
int srcY = clipTop > 0 ? clipTop : 0;
|
||||
|
||||
this->Draw(destX, destY, width, height, srcX, srcY, width, height, texture);
|
||||
}
|
||||
|
||||
void GkGraphicsDevice::DrawString(int x, int y, const char *text)
|
||||
{
|
||||
|
||||
|
||||
glLoadIdentity();
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glRasterPos2i(x, y);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
for (int i = 0; text[i] != 0; i++)
|
||||
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, text[i]);
|
||||
}
|
||||
|
||||
void GkGraphicsDevice::DrawString(int x, int y, const wchar_t *text)
|
||||
{
|
||||
glLoadIdentity();
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glRasterPos2i(x, y);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
for (int i = 0; text[i] != 0; i++)
|
||||
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, text[i]);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void GkGraphicsDevice::SetViewport(int x, int y, int width, int height)
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
glViewport(x, y, width, height);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
bool GkGraphicsDevice::CaptureScreen(const wchar_t *fileName, int width, int height)
|
||||
{
|
||||
int length = std::wcslen(fileName);
|
||||
char *cFileName = new char[length + 1];
|
||||
std::wcstombs(cFileName, fileName, length);
|
||||
cFileName[length] = 0;
|
||||
|
||||
int dataSize = this->width * this->height * 4;
|
||||
char *data = new char[dataSize];
|
||||
|
||||
glReadPixels(0, 0, this->width, this->height, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
|
||||
ILuint imageId;
|
||||
ilGenImages(1, &imageId);
|
||||
ilBindImage(imageId);
|
||||
ilTexImage(this->width, this->height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data);
|
||||
iluImageParameter(ILU_FILTER, ILU_BILINEAR);
|
||||
iluScale(width, height, 1);
|
||||
ilSetInteger(IL_JPG_QUALITY, 50);
|
||||
ilEnable(IL_FILE_OVERWRITE);
|
||||
bool result = ilSaveImage(cFileName) != 0;
|
||||
ilDeleteImages(1, &imageId);
|
||||
|
||||
delete[] data;
|
||||
delete[] cFileName;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include "GkTexture.h"
|
||||
|
||||
class GKDLLCLASS GkGraphicsDevice
|
||||
{
|
||||
public:
|
||||
|
||||
static void Initialize();
|
||||
|
||||
int maxTextureSize;
|
||||
bool nonPower2Textures;
|
||||
|
||||
int width, height;
|
||||
|
||||
GkGraphicsDevice(void);
|
||||
~GkGraphicsDevice(void);
|
||||
|
||||
void Free();
|
||||
void Clear();
|
||||
|
||||
void Draw(int destX, int destY, int destWidth, int destHeight, int srcX, int srcY, int srcWidth, int srcHeight, GkTexture* texture);
|
||||
void Draw(int x, int y, GkTexture* texture);
|
||||
void DrawClipped(int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, GkTexture* texture);
|
||||
void DrawString(int x, int y, const char *text);
|
||||
void DrawString(int x, int y, const wchar_t *text);
|
||||
void SetViewport(int x, int y, int width, int height);
|
||||
|
||||
bool CaptureScreen(const wchar_t *fileName, int width, int height);
|
||||
};
|
||||
@@ -0,0 +1,69 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkImage.h"
|
||||
|
||||
void GkImage::Initialize()
|
||||
{
|
||||
ilInit();
|
||||
}
|
||||
|
||||
GkImage::GkImage(void)
|
||||
{
|
||||
ilGenImages(1, &this->handle);
|
||||
}
|
||||
|
||||
|
||||
GkImage::~GkImage(void)
|
||||
{
|
||||
ilDeleteImages(1, &this->handle);
|
||||
}
|
||||
|
||||
void GkImage::LoadFromMemory(void* data, unsigned int dataSize)
|
||||
{
|
||||
ilBindImage(this->handle);
|
||||
|
||||
ilLoadL(IL_TYPE_UNKNOWN, data, dataSize);
|
||||
this->width = ilGetInteger(IL_IMAGE_WIDTH);
|
||||
this->height = ilGetInteger(IL_IMAGE_HEIGHT);
|
||||
}
|
||||
|
||||
void GkImage::LoadFromFile(char* fileName)
|
||||
{
|
||||
ilBindImage(this->handle);
|
||||
|
||||
ilLoadImage(fileName);
|
||||
this->width = ilGetInteger(IL_IMAGE_WIDTH);
|
||||
this->height = ilGetInteger(IL_IMAGE_HEIGHT);
|
||||
}
|
||||
|
||||
void GkImage::CopyPixels(void* dest)
|
||||
{
|
||||
ilBindImage(this->handle);
|
||||
ilCopyPixels(0, 0, 0, this->width, this->height, 1, IL_RGBA, IL_UNSIGNED_BYTE, dest);
|
||||
}
|
||||
|
||||
void GkImage::CopyPixels(void* dest, int x, int y, int width, int height)
|
||||
{
|
||||
ilBindImage(this->handle);
|
||||
ilCopyPixels(x, y, 0, width, height, 1, IL_RGBA, IL_UNSIGNED_BYTE, dest);
|
||||
}
|
||||
|
||||
void GkImage::CopyPixels(void* dest, int x, int y, int width, int height, int destX, int destY, int destWidth, int destHeight)
|
||||
{
|
||||
ilBindImage(this->handle);
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
ilCopyPixels(x, y + i, 0, width, 1, 1, IL_RGBA, IL_UNSIGNED_BYTE, (void*)(&((int*)dest)[(destY + i) * destWidth + destX]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include <DevIL\il.h>
|
||||
#include <DevIL\ilu.h>
|
||||
|
||||
class GKDLLCLASS GkImage
|
||||
{
|
||||
public:
|
||||
ILuint handle,
|
||||
width, height;
|
||||
|
||||
static void GkImage::Initialize();
|
||||
|
||||
GkImage::GkImage(void);
|
||||
GkImage::~GkImage(void);
|
||||
|
||||
void GkImage::LoadFromMemory(void* data, unsigned int dataSize);
|
||||
void GkImage::LoadFromFile(char* fileName);
|
||||
void GkImage::CopyPixels(void* dest);
|
||||
void GkImage::CopyPixels(void* dest, int x, int y, int width, int height);
|
||||
void GkImage::CopyPixels(void* dest, int x, int y, int width, int height, int destX, int destY, int destWidth, int destHeight);
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkTexture.h"
|
||||
|
||||
#include <GL\GLUt.h>
|
||||
|
||||
bool GkTexture::powerOfTwo = false;
|
||||
|
||||
GkTexture::GkTexture(void)
|
||||
{
|
||||
glGenTextures(1, &handle);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, this->handle);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
}
|
||||
|
||||
GkTexture::~GkTexture(void)
|
||||
{
|
||||
glDeleteTextures(1, &handle);
|
||||
}
|
||||
|
||||
void GkTexture::LoadFromImage(GkImage* image)
|
||||
{
|
||||
this->LoadFromImage(image, 0, 0, image->width, image->height);
|
||||
}
|
||||
|
||||
void GkTexture::LoadFromImage(GkImage* image, int x, int y, int width, int height)
|
||||
{
|
||||
if (GkTexture::powerOfTwo)
|
||||
{
|
||||
this->textureWidth = GkTexture::GetPowerOfTwo(width);
|
||||
this->textureHeight = GkTexture::GetPowerOfTwo(height);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->textureWidth = width;
|
||||
this->textureHeight = height;
|
||||
}
|
||||
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
|
||||
void *imageData = new char[this->textureWidth * this->textureHeight * 4];
|
||||
|
||||
if (this->width != this->textureWidth)
|
||||
image->CopyPixels(imageData, x, y, width, height, 0, 0, this->textureWidth, this->textureHeight);
|
||||
else
|
||||
image->CopyPixels(imageData, x, y, width, height);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, this->handle);
|
||||
//glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this->textureWidth, this->textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
|
||||
|
||||
delete imageData;
|
||||
}
|
||||
|
||||
void GkTexture::LoadFromFile(char* fileName)
|
||||
{
|
||||
GkImage* image = new GkImage();
|
||||
image->LoadFromFile(fileName);
|
||||
this->LoadFromImage(image);
|
||||
delete image;
|
||||
}
|
||||
|
||||
int GkTexture::GetPowerOfTwo(int value)
|
||||
{
|
||||
int result = 1;
|
||||
while (result < value)
|
||||
result *= 2;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include "GkImage.h"
|
||||
#include "..\Base\GkBase.h"
|
||||
|
||||
class GKDLLCLASS GkTexture :
|
||||
public GkBase
|
||||
{
|
||||
public:
|
||||
static bool powerOfTwo;
|
||||
|
||||
unsigned int handle;
|
||||
|
||||
int width, height,
|
||||
textureWidth, textureHeight;
|
||||
|
||||
GkTexture::GkTexture(void);
|
||||
GkTexture::~GkTexture(void);
|
||||
|
||||
void GkTexture::LoadFromImage(GkImage* image);
|
||||
void GkTexture::LoadFromImage(GkImage* image, int x, int y, int width, int height);
|
||||
void GkTexture::LoadFromFile(char* fileName);
|
||||
|
||||
static int GkTexture::GetPowerOfTwo(int value);
|
||||
};
|
||||
Reference in new issue
Block a user