[Add] Added texture loading crap.
This commit is contained in:
parent
c100118d72
commit
db9b05116c
@ -1,6 +1,6 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
# Makefile for building: Unuk-QT
|
# Makefile for building: Unuk-QT
|
||||||
# Generated by qmake (2.01a) (Qt 4.7.3) on: Wed Nov 9 00:17:08 2011
|
# Generated by qmake (2.01a) (Qt 4.7.3) on: Wed Nov 9 13:10:07 2011
|
||||||
# Project: Unuk-QT.pro
|
# Project: Unuk-QT.pro
|
||||||
# Template: app
|
# Template: app
|
||||||
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
|
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
|
||||||
@ -51,7 +51,9 @@ SOURCES = ../src/libUnuk/Debug.cpp \
|
|||||||
../src/libUnuk/ApplySurface.cpp \
|
../src/libUnuk/ApplySurface.cpp \
|
||||||
../src/Unuk/Globals.cpp \
|
../src/Unuk/Globals.cpp \
|
||||||
../src/libUnuk/Rect.cpp \
|
../src/libUnuk/Rect.cpp \
|
||||||
../src/libUnuk/ImageLoader.cpp
|
../src/libUnuk/ImageLoader.cpp \
|
||||||
|
../src/libUnuk/TextureManager.cpp \
|
||||||
|
../src/libUnuk/Texture.cpp
|
||||||
OBJECTS = Debug.o \
|
OBJECTS = Debug.o \
|
||||||
main.o \
|
main.o \
|
||||||
Input.o \
|
Input.o \
|
||||||
@ -60,7 +62,9 @@ OBJECTS = Debug.o \
|
|||||||
ApplySurface.o \
|
ApplySurface.o \
|
||||||
Globals.o \
|
Globals.o \
|
||||||
Rect.o \
|
Rect.o \
|
||||||
ImageLoader.o
|
ImageLoader.o \
|
||||||
|
TextureManager.o \
|
||||||
|
Texture.o
|
||||||
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
|
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
|
||||||
/usr/share/qt4/mkspecs/common/unix.conf \
|
/usr/share/qt4/mkspecs/common/unix.conf \
|
||||||
/usr/share/qt4/mkspecs/common/linux.conf \
|
/usr/share/qt4/mkspecs/common/linux.conf \
|
||||||
@ -163,7 +167,7 @@ qmake: FORCE
|
|||||||
|
|
||||||
dist:
|
dist:
|
||||||
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
|
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
|
||||||
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Input.h ../src/libUnuk/Rect.h ../src/libUnuk/Timer.h ../src/libUnuk/Font.h ../Constants.h ../src/Unuk/Constants.h ../src/libUnuk/ApplySurface.h ../src/Unuk/Globals.h ../src/libUnuk/ImageLoader.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.cpp ../src/Unuk/main.cpp ../src/libUnuk/Input.cpp ../src/libUnuk/Timer.cpp ../src/libUnuk/Font.cpp ../src/libUnuk/ApplySurface.cpp ../src/Unuk/Globals.cpp ../src/libUnuk/Rect.cpp ../src/libUnuk/ImageLoader.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
|
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Input.h ../src/libUnuk/Rect.h ../src/libUnuk/Timer.h ../src/libUnuk/Font.h ../Constants.h ../src/Unuk/Constants.h ../src/libUnuk/ApplySurface.h ../src/Unuk/Globals.h ../src/libUnuk/ImageLoader.h ../src/libUnuk/TextureManager.h ../src/libUnuk/Texture.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.cpp ../src/Unuk/main.cpp ../src/libUnuk/Input.cpp ../src/libUnuk/Timer.cpp ../src/libUnuk/Font.cpp ../src/libUnuk/ApplySurface.cpp ../src/Unuk/Globals.cpp ../src/libUnuk/Rect.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/TextureManager.cpp ../src/libUnuk/Texture.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
|
||||||
|
|
||||||
|
|
||||||
clean:compiler_clean
|
clean:compiler_clean
|
||||||
@ -242,6 +246,19 @@ ImageLoader.o: ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/ImageLoader.h \
|
|||||||
../src/libUnuk/Debug.h
|
../src/libUnuk/Debug.h
|
||||||
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o ImageLoader.o ../src/libUnuk/ImageLoader.cpp
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o ImageLoader.o ../src/libUnuk/ImageLoader.cpp
|
||||||
|
|
||||||
|
TextureManager.o: ../src/libUnuk/TextureManager.cpp ../src/libUnuk/TextureManager.h \
|
||||||
|
../src/libUnuk/ImageLoader.h \
|
||||||
|
../src/Unuk/Globals.h \
|
||||||
|
../src/libUnuk/Debug.h
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o TextureManager.o ../src/libUnuk/TextureManager.cpp
|
||||||
|
|
||||||
|
Texture.o: ../src/libUnuk/Texture.cpp ../src/libUnuk/Texture.h \
|
||||||
|
../src/Unuk/Globals.h \
|
||||||
|
../src/libUnuk/ImageLoader.h \
|
||||||
|
../src/libUnuk/Debug.h \
|
||||||
|
../src/libUnuk/ApplySurface.h
|
||||||
|
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Texture.o ../src/libUnuk/Texture.cpp
|
||||||
|
|
||||||
####### Install
|
####### Install
|
||||||
|
|
||||||
install: FORCE
|
install: FORCE
|
||||||
|
@ -16,7 +16,9 @@ HEADERS += ../src/libUnuk/Debug.h \
|
|||||||
../src/Unuk/Constants.h \
|
../src/Unuk/Constants.h \
|
||||||
../src/libUnuk/ApplySurface.h \
|
../src/libUnuk/ApplySurface.h \
|
||||||
../src/Unuk/Globals.h \
|
../src/Unuk/Globals.h \
|
||||||
../src/libUnuk/ImageLoader.h
|
../src/libUnuk/ImageLoader.h \
|
||||||
|
../src/libUnuk/TextureManager.h \
|
||||||
|
../src/libUnuk/Texture.h
|
||||||
SOURCES += ../src/libUnuk/Debug.cpp \
|
SOURCES += ../src/libUnuk/Debug.cpp \
|
||||||
../src/Unuk/main.cpp \
|
../src/Unuk/main.cpp \
|
||||||
../src/libUnuk/Input.cpp \
|
../src/libUnuk/Input.cpp \
|
||||||
@ -25,4 +27,6 @@ SOURCES += ../src/libUnuk/Debug.cpp \
|
|||||||
../src/libUnuk/ApplySurface.cpp \
|
../src/libUnuk/ApplySurface.cpp \
|
||||||
../src/Unuk/Globals.cpp \
|
../src/Unuk/Globals.cpp \
|
||||||
../src/libUnuk/Rect.cpp \
|
../src/libUnuk/Rect.cpp \
|
||||||
../src/libUnuk/ImageLoader.cpp
|
../src/libUnuk/ImageLoader.cpp \
|
||||||
|
../src/libUnuk/TextureManager.cpp \
|
||||||
|
../src/libUnuk/Texture.cpp
|
||||||
|
53
src/libUnuk/Texture.cpp
Normal file
53
src/libUnuk/Texture.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
|
Texture::Texture(void) {
|
||||||
|
texture = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture::~Texture(void) {
|
||||||
|
assert(texture != NULL);
|
||||||
|
SDL_FreeSurface(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::SetXY(int xArg, int yArg) {
|
||||||
|
x = xArg;
|
||||||
|
y = yArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::Render(void) {
|
||||||
|
ApplySurface(x, y, texture, screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::Render(int xArg, int yArg) {
|
||||||
|
ApplySurface(xArg, yArg, texture, screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::RenderLiteral(void) {
|
||||||
|
ApplySurfaceLiteral(x, y, texture, screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::RenderLiteral(int xArg, int yArg) {
|
||||||
|
ApplySurfaceLiteral(xArg, yArg,texture, screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::Load(const char* filename) {
|
||||||
|
if(texture != NULL) {
|
||||||
|
// Free the texture.
|
||||||
|
SDL_FreeSurface(texture);
|
||||||
|
}
|
||||||
|
// Load the texture.
|
||||||
|
texture = LoadImage(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::LoadAlpha(const char* filename) {
|
||||||
|
if(texture != NULL) {
|
||||||
|
// Free the texture.
|
||||||
|
SDL_FreeSurface(texture);
|
||||||
|
}
|
||||||
|
// Load the texture with an alpha channel.
|
||||||
|
texture = LoadImageAlpha(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::SetAlpha(int alphaArg) {
|
||||||
|
SDL_SetAlpha(texture, SDL_SRCALPHA, alphaArg);
|
||||||
|
}
|
36
src/libUnuk/Texture.h
Normal file
36
src/libUnuk/Texture.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef _TEXTURE_H_
|
||||||
|
#define _TEXTURE_H_
|
||||||
|
#include "../Unuk/Globals.h"
|
||||||
|
#include "ImageLoader.h"
|
||||||
|
#include "ApplySurface.h"
|
||||||
|
|
||||||
|
class Texture {
|
||||||
|
public:
|
||||||
|
Texture(void);
|
||||||
|
~Texture(void);
|
||||||
|
|
||||||
|
int GetWidth(void) { return texture->w; }
|
||||||
|
int GetHeight(void) { return texture->h; }
|
||||||
|
int GetX(void) { return x; }
|
||||||
|
int GetY(void) { return y; }
|
||||||
|
|
||||||
|
void SetXY(int xArg, int yArg);
|
||||||
|
|
||||||
|
void Render(void);
|
||||||
|
void Render(int xArg, int yArg);
|
||||||
|
|
||||||
|
void RenderLiteral(void);
|
||||||
|
void RenderLiteral(int xArg, int yArg);
|
||||||
|
|
||||||
|
void Load(const char* filename);
|
||||||
|
void LoadAlpha(const char* filename);
|
||||||
|
void SetAlpha(int alphaArg);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SDL_Surface* texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
49
src/libUnuk/TextureManager.cpp
Normal file
49
src/libUnuk/TextureManager.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "TextureManager.h"
|
||||||
|
|
||||||
|
TextureManager::TextureManager(void) {
|
||||||
|
m_allocated = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureManager::~TextureManager(void) {
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureManager::Clear(void) {
|
||||||
|
for(int i = 0; i < m_allocated; i++) {
|
||||||
|
SDL_FreeSurface(array[i].texture);
|
||||||
|
array[i].name.clear();
|
||||||
|
}
|
||||||
|
m_allocated = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TextureManager::Add(string filename) {
|
||||||
|
assert(m_allocated < TEXTURE_NODE_SIZE);
|
||||||
|
|
||||||
|
// Has the texture been loaded already?
|
||||||
|
for(int i = 0; i < m_allocated; i++) {
|
||||||
|
if(array[i].name == filename) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array[m_allocated].name = filename;
|
||||||
|
array[m_allocated].texture = LoadImage(filename.c_str());
|
||||||
|
|
||||||
|
return m_allocated++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TextureManager::AddAlpha(string filename) {
|
||||||
|
assert(m_allocated < TEXTURE_NODE_SIZE);
|
||||||
|
|
||||||
|
// Has the texture been loaded already?
|
||||||
|
for(int i = 0; i < m_allocated; i++) {
|
||||||
|
if(array[i].name == filename) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array[m_allocated].name = filename;
|
||||||
|
array[m_allocated].texture = LoadImageAlpha(filename.c_str());
|
||||||
|
|
||||||
|
return m_allocated++;
|
||||||
|
}
|
44
src/libUnuk/TextureManager.h
Normal file
44
src/libUnuk/TextureManager.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef _TEXTUREMANAGER_H_
|
||||||
|
#define _TEXTUREMANAGER_H_
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <string>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "ImageLoader.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The Texture Manager will keep a small "Database"
|
||||||
|
* of the name of the texture that is loaded and the
|
||||||
|
* actual texture so we can query it with the filename
|
||||||
|
* and it will return an index that we can use to retrieve
|
||||||
|
* the texture.
|
||||||
|
*/
|
||||||
|
class TextureManager {
|
||||||
|
public:
|
||||||
|
TextureManager(void);
|
||||||
|
~TextureManager(void);
|
||||||
|
|
||||||
|
SDL_Surface* Get(int n) { return array[n].texture; }
|
||||||
|
int GetTextureWidth(int n) { return array[n].texture->w; }
|
||||||
|
int GetTextureHeight(int n) { return array[n].texture->h; }
|
||||||
|
|
||||||
|
void Clear(void);
|
||||||
|
|
||||||
|
int Add(string filename);
|
||||||
|
int AddAlpha(string filename);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// The textureNode will hold the name and the texture.
|
||||||
|
struct textureNode {
|
||||||
|
SDL_Surface* texture;
|
||||||
|
string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
// We should not need more than a hundred..
|
||||||
|
static const int TEXTURE_NODE_SIZE = 100;
|
||||||
|
textureNode array[TEXTURE_NODE_SIZE];
|
||||||
|
|
||||||
|
int m_allocated;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user