[Add] Added Animating sprites. -- Bit buggy right now.

This commit is contained in:
Rtch90 2012-04-15 22:15:23 +01:00
parent cda3b3d086
commit 42ecaaefd2
24 changed files with 206 additions and 114 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,3 @@
2;
Idle 1 1;
Walk 2 4;

0
Data/Img/Player/Player_F Normal file
View File

BIN
Data/Img/Reniesta.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -12,7 +12,14 @@ Actor::Actor(void) {
_stepSFX[3] = sfxManager.Load("../Data/SFX/step_cloth4.wav"); _stepSFX[3] = sfxManager.Load("../Data/SFX/step_cloth4.wav");
_lastStepSFXPlayed = -1; _lastStepSFXPlayed = -1;
_velocity = 4.0f; _velocity = 4.0f;
_direction = Front;
_preventMovement = NONE;
_actorLeft = new AnimatingSprite();
_actorRight = new AnimatingSprite();
_actorFront = new AnimatingSprite();
_actorBack = new AnimatingSprite();
} }
Actor::~Actor(void) { Actor::~Actor(void) {
@ -23,6 +30,10 @@ Actor::~Actor(void) {
} }
} }
delete _actor; delete _actor;
delete _actorLeft;
delete _actorRight;
delete _actorFront;
delete _actorBack;
} }
void Actor::LoadSprite(const char* filename) { void Actor::LoadSprite(const char* filename) {
@ -35,6 +46,24 @@ void Actor::Update(float dt) {
float oldX = x = _actor->GetX(); float oldX = x = _actor->GetX();
float oldY = y = _actor->GetY(); float oldY = y = _actor->GetY();
if(_direction == LEFT) {
_actorLeft->Update(dt);
}
else if(_direction == RIGHT) {
_actorRight->Update(dt);
}
else if(_direction == Front) {
_actorFront->Update(dt);
}
else if(_direction == BACK) {
_actorBack->Update(dt);
}
// We should check for collisions now.
Move(dt); Move(dt);
if(x != oldX || y != oldY) { if(x != oldX || y != oldY) {

View File

@ -2,12 +2,27 @@
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include "../Sprite/Sprite.h" #include "../Sprite/Sprite.h"
#include "../Animation/AnimatingSprite.h"
#include "../Math/Vec2.h" #include "../Math/Vec2.h"
class SoundEffect; class SoundEffect;
class Actor { class Actor {
public: public:
enum Facing {
Front,
BACK,
LEFT,
RIGHT,
NONE
};
enum Status {
WALKING,
HURT
};
Actor(void); Actor(void);
~Actor(void); ~Actor(void);
@ -24,21 +39,22 @@ public:
void SetXY(float xArg, float yArg) { x = xArg; y = yArg; } void SetXY(float xArg, float yArg) { x = xArg; y = yArg; }
int GetDirection(void) { return _direction; } Facing GetDirection(void) { return _direction; }
void SetDirection(int direction) { _direction = direction; } void SetDirection(Facing direction) { _direction = direction; }
protected: protected:
virtual void Move(float dt) = 0; virtual void Move(float dt) = 0;
float _velocity; float _velocity;
int _direction;
static const int ANIM_LEFT_FOOT = 0;
static const int ANIM_NO_FOOT = 1;
static const int ANIM_RIGHT_FOOT = 2;
static const int ANIM_ATTACK = 3;
Sprite* _actor; Sprite* _actor;
AnimatingSprite* _actorLeft;
AnimatingSprite* _actorRight;
AnimatingSprite* _actorFront;
AnimatingSprite* _actorBack;
Facing _direction;
Facing _preventMovement;
float x; float x;
float y; float y;
@ -47,8 +63,6 @@ private:
float w; float w;
float h; float h;
Vec2 _spriteVector[4][4];
SoundEffect* _stepSFX[4]; SoundEffect* _stepSFX[4];
int _lastStepSFXPlayed; int _lastStepSFXPlayed;
}; };

View File

@ -1,6 +1,7 @@
#include "NPC.h" #include "NPC.h"
NPC::NPC(void) : Actor() { NPC::NPC(void) : Actor() {
LoadSprite("../Data/Img/Player.png");
} }
NPC::~NPC(void) { NPC::~NPC(void) {

View File

@ -2,6 +2,10 @@
#include "../IO/Input.h" #include "../IO/Input.h"
Player::Player(void) : Actor() { Player::Player(void) : Actor() {
Actor::_actorFront->LoadAnimatingSprite("Player_f", "../Data/Img/Player/Front/Player_F", "../Data/Img/Player/Player_F", 4, _velocity);
//Actor::_actorFront->LoadAnimatingSprite("Player_b", "../Data/Img/Player/Front/Player_B", "../Data/Img/Player/Player_B", 4, _velocity);
//Actor::_actorFront->LoadAnimatingSprite("Player_L", "../Data/Img/Player/Front/Player_L", "../Data/Img/Player/Player_L", 4, _velocity);
//Actor::_actorFront->LoadAnimatingSprite("Player_R", "../Data/Img/Player/Front/Player_R", "../Data/Img/Player/Player_R", 4, _velocity);
} }
Player::~Player(void) { Player::~Player(void) {

View File

@ -59,13 +59,34 @@ void AnimatingSprite::Update(float dt) {
void AnimatingSprite::LoadAnimatingSprite(const char* id, const char* filename, const char* sequence, int frames, float animationSpeed) { void AnimatingSprite::LoadAnimatingSprite(const char* id, const char* filename, const char* sequence, int frames, float animationSpeed) {
for(int i = 0; i < frames; i++) {
String tempFilename;
tempFilename = "";
if(i < 10) {
tempFilename.Format("%s.00%i.png", filename, i);
}
else if(i < 100) {
tempFilename.Format("%s.0%i.png", filename, i);
} else {
tempFilename.Format("%s.%i.png", filename, i);
}
_sprites[_spriteCounter] = new Sprite();
_sprites[_spriteCounter]->LoadSprite((const char*)tempFilename);
_spriteCounter++;
}
_id = id;
_numberOfFrames = frames;
_animationSpeed = animationSpeed;
_sequence = new AnimationSequence(sequence);
SetCurrentAnimation(0);
} }
void AnimatingSprite::SetCurrentAnimation(const char* filename) { void AnimatingSprite::SetCurrentAnimation(const char* animation) {
_currentAnimation = _sequence->GetAnimation(animation)->_animationID;
_currentFrame = _sequence->GetAnimation(animation)->frameBegin;
} }
void AnimatingSprite::SetCurrentAnimation(int index) { void AnimatingSprite::SetCurrentAnimation(int index) {
_currentAnimation = _sequence->GetAnimation(index)->_animationID;
_currentFrame = _sequence->GetAnimation(index)->frameBegin;
} }

View File

@ -29,11 +29,11 @@ private:
int _spriteCounter; int _spriteCounter;
AnimationSequence* _sequence; AnimationSequence* _sequence;
String _id; const char* _id;
float _animationSpeed; float _animationSpeed;
float _timer; float _timer;
int _currentFrame; int _currentFrame;
int _numberOfFrames; int _numberOfFrames;
String _currentAnimation; const char* _currentAnimation;
}; };

View File

@ -24,7 +24,6 @@ AnimationSequence::AnimationSequence(void) {
AnimationSequence::AnimationSequence(const char* filename) { AnimationSequence::AnimationSequence(const char* filename) {
_numberOfFrames = 0; _numberOfFrames = 0;
_sequenceID = filename; _sequenceID = filename;
_sequenceID.Concatenate(".txt");
ReadFile(); ReadFile();
} }
@ -70,7 +69,7 @@ void AnimationSequence::ReadFile(void) {
_animations[index]->_loopTo = loop; _animations[index]->_loopTo = loop;
} }
} else { } else {
//Debug::logger->message("%s does not exist.", _sequenceID); Debug::logger->message("%s does not exist.", _sequenceID);
assert(false); assert(false);
} }
} }

View File

@ -12,7 +12,7 @@
class AnimationSequence { class AnimationSequence {
struct Animation { struct Animation {
String _animationID; const char* _animationID;
int frameBegin; int frameBegin;
int frameEnd; int frameEnd;
String _loopTo; String _loopTo;
@ -30,7 +30,7 @@ public:
private: private:
const char* Scan(char* source, int& counter); const char* Scan(char* source, int& counter);
String _sequenceID; const char* _sequenceID;
int _numberOfFrames; int _numberOfFrames;
FileReader _file; FileReader _file;
Animation* _animations[MAX_FRAMES]; Animation* _animations[MAX_FRAMES];

View File

@ -20,9 +20,6 @@ Game::Game(void) {
_NPC = new NPC(); _NPC = new NPC();
_level = new Level(); _level = new Level();
_player->LoadSprite("../Data/Img/Player.png");
_NPC->LoadSprite("../Data/Img/Player.png");
_NPC->SetXY(30.0f, 30.0f); _NPC->SetXY(30.0f, 30.0f);
_testFont = new Font(); _testFont = new Font();

View File

@ -101,4 +101,3 @@ void Sprite::SetTexture(Texture* texture) {
this->texture = texture; this->texture = texture;
this->size = Vec2((float)texture->GetWidth(), (float)texture->GetHeight()); this->size = Vec2((float)texture->GetWidth(), (float)texture->GetHeight());
} }

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <cstdarg>
#include "../System/String.h"
#include "../Math/Vec2.h" #include "../Math/Vec2.h"
#include "../Math/Rect.h" #include "../Math/Rect.h"

View File

@ -18,85 +18,85 @@ using namespace std;
Debug *Debug::logger = NULL; Debug *Debug::logger = NULL;
Debug::Debug(bool logToFile) { Debug::Debug(bool logToFile) {
time_t timestamp; time_t timestamp;
if(logToFile) { if(logToFile) {
_logFile.open("../Bin/Debug.log", ios::out); _logFile.open("../Bin/Debug.log", ios::out);
if(!_logFile.is_open()) { if(!_logFile.is_open()) {
// We can not open our log. // We can not open our log.
cerr << "Warning: Can not open Debug.log to write, continueing without logging\n"; cerr << "Warning: Can not open Debug.log to write, continueing without logging\n";
} else { } else {
// Log File is open, let us give it a nice time stamp. // Log File is open, let us give it a nice time stamp.
timestamp = time(NULL); timestamp = time(NULL);
_logFile << "Log Started: " << ctime(&timestamp) << endl; _logFile << "Log Started: " << ctime(&timestamp) << endl;
} }
} }
} }
Debug::~Debug(void) { Debug::~Debug(void) {
time_t timestamp; time_t timestamp;
// We only need to close the log if it is open. // We only need to close the log if it is open.
if(_logFile.is_open()) { if(_logFile.is_open()) {
// Give it a closing timestamp. // Give it a closing timestamp.
timestamp = time(NULL); timestamp = time(NULL);
_logFile << endl << "Log Closed: " << ctime(&timestamp) << endl; _logFile << endl << "Log Closed: " << ctime(&timestamp) << endl;
// Close the log file. // Close the log file.
_logFile.close(); _logFile.close();
} }
} }
void Debug::message(std::string msg) { void Debug::message(std::string msg) {
if(_logFile.is_open()) { if(_logFile.is_open()) {
_logFile << msg << endl; _logFile << msg << endl;
} }
cerr << msg << endl << endl; cerr << msg << endl << endl;
} }
void Debug::message(const char *msg, ...) { void Debug::message(const char *msg, ...) {
va_list vargList; // This is to handlle the variable arguments va_list vargList; // This is to handlle the variable arguments
char outBuf[1024]; char outBuf[1024];
unsigned short outLen; unsigned short outLen;
// This takes the arguments and puts them into the character array. // This takes the arguments and puts them into the character array.
va_start(vargList, msg); va_start(vargList, msg);
#if defined WIN32 #ifdef WIN32
outLen = _vsnprintf(outBuf, sizeof(outBuf), msg, vargList); outLen = _vsnprintf(outBuf, sizeof(outBuf), msg, vargList);
#else #else
outLen = vsnprintf(outBuf, sizeof(outBuf), msg, vargList); outLen = vsnprintf(outBuf, sizeof(outBuf), msg, vargList);
#endif #endif
va_end(vargList); va_end(vargList);
if(outLen >= sizeof(outBuf)) { if(outLen >= sizeof(outBuf)) {
outLen = sizeof(outBuf); outLen = sizeof(outBuf);
} }
if(_logFile.is_open()) { if(_logFile.is_open()) {
_logFile << outBuf << endl; _logFile << outBuf << endl;
} }
cerr << outBuf << endl; cerr << outBuf << endl;
} }
bool Debug::openLog(bool logToFile) { bool Debug::openLog(bool logToFile) {
// Make sure the logger has not already been initialized. // Make sure the logger has not already been initialized.
if(logger != NULL) { if(logger != NULL) {
logger->message("Warning: Multiple calls to openLog()."); logger->message("Warning: Multiple calls to openLog().");
return false; return false;
} }
logger = new Debug(logToFile); logger = new Debug(logToFile);
return true; return true;
} }
void Debug::closeLog(void) { void Debug::closeLog(void) {
if(logger == NULL) { if(logger == NULL) {
cerr << "Warning: Call to closeLog() with NULL logger pointer." << endl; cerr << "Warning: Call to closeLog() with NULL logger pointer." << endl;
return; return;
} }
delete logger; delete logger;
logger = NULL; logger = NULL;
} }

View File

@ -3,6 +3,8 @@
#include <string> #include <string>
#include <map> #include <map>
#include "../System/String.h"
class Resource { class Resource {
public: public:
virtual bool Load(const std::string& filename) = 0; virtual bool Load(const std::string& filename) = 0;

View File

@ -1,7 +1,10 @@
#ifdef _WIN32
#define "windows.h"
#endif
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdarg.h>
#include "String.h" #include "String.h"
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
@ -40,6 +43,21 @@ int String::Length(void) {
return strlen(_string); return strlen(_string);
} }
void String::Format(const char* format, ...) {
char temp[256];
va_list vlist;
va_start(vlist, format);
#ifdef _WIN32
vsprintf_s(&temp[0], 256, format, vlist);
#else
vsnprintf(&temp[0], 256, format, vlist);
#endif
va_end(vlist);
memcpy(_string, temp, strlen(temp)+1);
}
void String::Concatenate(char value) { void String::Concatenate(char value) {
// Concatenate a char on the end of a string. // Concatenate a char on the end of a string.
assert(strlen(_string) + 1 < MAX_STRING_LEN); assert(strlen(_string) + 1 < MAX_STRING_LEN);

View File

@ -16,6 +16,8 @@ public:
void Concatenate(char value); void Concatenate(char value);
int Length(void); int Length(void);
void Format(const char* format, ...);
// Operator overloads. // Operator overloads.
String& operator=(const char* value); String& operator=(const char* value);
String& operator=(String& value); String& operator=(String& value);

View File

@ -34,7 +34,7 @@ int BuildTexture(const char* filename, GLuint* texID, GLint param, bool genMips)
// Load the image, check for errors, if it isn't found, quit. // Load the image, check for errors, if it isn't found, quit.
textureImage = IMG_Load(filename); textureImage = IMG_Load(filename);
if(!textureImage) { if(!textureImage) {
Debug::logger->message("Warning: could not load %s", filename); Debug::logger->message("Warning: could not load %s", filename);
return false; return false;
@ -70,18 +70,18 @@ int BuildTexture(const char* filename, GLuint* texID, GLint param, bool genMips)
SDL_FreeSurface(textureImage); SDL_FreeSurface(textureImage);
return false; return false;
} }
// Create the texture. // Create the texture.
glGenTextures(1, texID); glGenTextures(1, texID);
// Typical texture generation using data from the bitmap. // Typical texture generation using data from the bitmap.
BindTexture(*texID); BindTexture(*texID);
// Setup filtering. // Setup filtering.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, param); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, param);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, param); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, param);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(genMips) { if(genMips) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
// Generate the textures and mipmaps. // Generate the textures and mipmaps.
@ -107,52 +107,52 @@ int LoadTGAFile(const char* filename, TGAFILE* tgaFile) {
int colorMode; // 4 for RGBA or 3 for RGB. int colorMode; // 4 for RGBA or 3 for RGB.
long imgIndex; // counter variable. long imgIndex; // counter variable.
unsigned char colorSwap; // Swap variable. unsigned char colorSwap; // Swap variable.
// Open the TGA file. // Open the TGA file.
filePtr = fopen(filename, "rb"); filePtr = fopen(filename, "rb");
if(!filePtr) if(!filePtr)
return 0; return 0;
// Read the first two bytes of garbage. // Read the first two bytes of garbage.
fread(&ucharBad, sizeof(unsigned char), 1, filePtr); fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
fread(&ucharBad, sizeof(unsigned char), 1, filePtr); fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
// Read in the image type. // Read in the image type.
fread(&tgaFile->textureTypeCode, sizeof(unsigned char), 1, filePtr); fread(&tgaFile->textureTypeCode, sizeof(unsigned char), 1, filePtr);
// The texture type should be either 2(color) or 3(greyscale). // The texture type should be either 2(color) or 3(greyscale).
if((tgaFile->textureTypeCode != 2) && (tgaFile->textureTypeCode != 3)) { if((tgaFile->textureTypeCode != 2) && (tgaFile->textureTypeCode != 3)) {
fclose(filePtr); fclose(filePtr);
return 0; return 0;
} }
// Read 13 bytes of garbage data. // Read 13 bytes of garbage data.
fread(&sintBad, sizeof(short int), 1, filePtr); fread(&sintBad, sizeof(short int), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr); fread(&sintBad, sizeof(short int), 1, filePtr);
fread(&ucharBad, sizeof(unsigned char), 1, filePtr); fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr); fread(&sintBad, sizeof(short int), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr); fread(&sintBad, sizeof(short int), 1, filePtr);
// Read image dimensions. // Read image dimensions.
fread(&tgaFile->textureWidth, sizeof(short int), 1, filePtr); fread(&tgaFile->textureWidth, sizeof(short int), 1, filePtr);
fread(&tgaFile->textureHeight, sizeof(short int), 1, filePtr); fread(&tgaFile->textureHeight, sizeof(short int), 1, filePtr);
// Read image bit depth. // Read image bit depth.
fread(&tgaFile->bitCount, sizeof(unsigned char), 1, filePtr); fread(&tgaFile->bitCount, sizeof(unsigned char), 1, filePtr);
// Read 1 byte of garbage data. // Read 1 byte of garbage data.
fread(&ucharBad, sizeof(unsigned char), 1, filePtr); fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
// colorMode -> 3 = BGR, 4 = BGRA // colorMode -> 3 = BGR, 4 = BGRA
colorMode = tgaFile->bitCount / 8; colorMode = tgaFile->bitCount / 8;
imageSize = tgaFile->textureWidth * tgaFile->textureHeight * colorMode; imageSize = tgaFile->textureWidth * tgaFile->textureHeight * colorMode;
// Allocate memory for image data. // Allocate memory for image data.
tgaFile->textureData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize); tgaFile->textureData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);
// Read in the image data. // Read in the image data.
fread(tgaFile->textureData, sizeof(unsigned char), imageSize, filePtr); fread(tgaFile->textureData, sizeof(unsigned char), imageSize, filePtr);
// Change BGR to RGB so OpenGL can read the data. // Change BGR to RGB so OpenGL can read the data.
for(imgIndex = 0; imgIndex < imageSize; imgIndex += colorMode) { for(imgIndex = 0; imgIndex < imageSize; imgIndex += colorMode) {
colorSwap = tgaFile->textureData[imgIndex]; colorSwap = tgaFile->textureData[imgIndex];
@ -174,58 +174,58 @@ int WriteTGAFile(const char* filename, short int width, short int height, unsign
unsigned char bitDepth; unsigned char bitDepth;
long imageSize; long imageSize;
FILE* filePtr; FILE* filePtr;
// Create a file for writing to binary mode. // Create a file for writing to binary mode.
filePtr = fopen(filename, "wb"); filePtr = fopen(filename, "wb");
if(!filePtr) { if(!filePtr) {
fclose(filePtr); fclose(filePtr);
return 0; return 0;
} }
imageType = 2; // RGB, uncompressed. imageType = 2; // RGB, uncompressed.
bitDepth = 24; // 24-bitdepth. bitDepth = 24; // 24-bitdepth.
colorMode = 3; // RGB color mode. colorMode = 3; // RGB color mode.
byteSkip = 0; byteSkip = 0;
shortSkip = 0; shortSkip = 0;
// Write 2 bytes of data. // Write 2 bytes of data.
fwrite(&byteSkip, sizeof(unsigned char), 1, filePtr); fwrite(&byteSkip, sizeof(unsigned char), 1, filePtr);
fwrite(&byteSkip, sizeof(unsigned char), 1, filePtr); fwrite(&byteSkip, sizeof(unsigned char), 1, filePtr);
// Write image type. // Write image type.
fwrite(&imageType, sizeof(unsigned char), 1, filePtr); fwrite(&imageType, sizeof(unsigned char), 1, filePtr);
fwrite(&shortSkip, sizeof(short int), 1, filePtr); fwrite(&shortSkip, sizeof(short int), 1, filePtr);
fwrite(&shortSkip, sizeof(short int), 1, filePtr); fwrite(&shortSkip, sizeof(short int), 1, filePtr);
fwrite(&byteSkip, sizeof(unsigned char), 1, filePtr); fwrite(&byteSkip, sizeof(unsigned char), 1, filePtr);
fwrite(&shortSkip, sizeof(short int), 1, filePtr); fwrite(&shortSkip, sizeof(short int), 1, filePtr);
fwrite(&shortSkip, sizeof(short int), 1, filePtr); fwrite(&shortSkip, sizeof(short int), 1, filePtr);
// Write image dimensions. // Write image dimensions.
fwrite(&width, sizeof(short int), 1, filePtr); fwrite(&width, sizeof(short int), 1, filePtr);
fwrite(&height, sizeof(short int), 1, filePtr); fwrite(&height, sizeof(short int), 1, filePtr);
fwrite(&bitDepth, sizeof(unsigned char), 1, filePtr); fwrite(&bitDepth, sizeof(unsigned char), 1, filePtr);
// Write 1 byte of data // Write 1 byte of data
fwrite(&byteSkip, sizeof(unsigned char), 1, filePtr); fwrite(&byteSkip, sizeof(unsigned char), 1, filePtr);
// Calculate the image size. // Calculate the image size.
imageSize = width * height * colorMode; imageSize = width * height * colorMode;
// Change the image data from RGB to BGR // Change the image data from RGB to BGR
for(imgIndex = 0; imgIndex < imageSize; imgIndex += colorMode) { for(imgIndex = 0; imgIndex < imageSize; imgIndex += colorMode) {
colorSwap = imageData[imgIndex]; colorSwap = imageData[imgIndex];
imageData[imgIndex] = imageData[imgIndex + 2]; imageData[imgIndex] = imageData[imgIndex + 2];
imageData[imgIndex + 2] = colorSwap; imageData[imgIndex + 2] = colorSwap;
} }
// Write the image data. // Write the image data.
fwrite(imageData, sizeof(unsigned char), imageSize, filePtr); fwrite(imageData, sizeof(unsigned char), imageSize, filePtr);
// Close the file. // Close the file.
fclose(filePtr); fclose(filePtr);
return 1; return 1;
} }
@ -257,3 +257,4 @@ bool Texture::Load(const std::string& filename) {
} }
return false; return false;
} }