rm FileLoader/TextureCache/TextureLoader; update wfobj to v2.0
This commit is contained in:
parent
5e4860f266
commit
e305a264f1
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -1,9 +1,3 @@
|
||||
[submodule "wfobj"]
|
||||
path = wfobj
|
||||
url = ../wfobj.git
|
||||
[submodule "FileLoader"]
|
||||
path = FileLoader
|
||||
url = ../FileLoader.git
|
||||
[submodule "TextureLoader"]
|
||||
path = TextureLoader
|
||||
url = ../TextureLoader.git
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit 8abf3ff02b6a8cc7024006a9379fd7e8b07cd4a6
|
@ -1,12 +0,0 @@
|
||||
|
||||
CXX := g++
|
||||
CXXFLAGS ?= -O2
|
||||
OBJS := TextureCache.o
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
%.o: %.cc %.hh
|
||||
$(CXX) -c -o $@ $< $(CXXFLAGS)
|
||||
|
||||
clean:
|
||||
-rm -f *~ *.o
|
@ -1,94 +0,0 @@
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_image.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <iostream>
|
||||
#include "TextureCache.h"
|
||||
using namespace std;
|
||||
|
||||
GLuint TextureCache::load(const string & filename)
|
||||
{
|
||||
map<string,GLuint>::iterator it = m_cache.find(filename);
|
||||
if (it != m_cache.end())
|
||||
return it->second;
|
||||
GLuint tex = loadTexture(filename.c_str());
|
||||
m_cache[filename] = tex;
|
||||
return tex;
|
||||
}
|
||||
|
||||
GLuint TextureCache::loadTexture(const char * filename,
|
||||
bool mipmaps,
|
||||
int mode,
|
||||
int quality)
|
||||
{
|
||||
GLuint texture;
|
||||
SDL_Surface * temp = IMG_Load(filename);
|
||||
if (!temp)
|
||||
{
|
||||
cerr << "Failed to load image '" << filename << "'!" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_PixelFormat fmt;
|
||||
fmt.palette = NULL;
|
||||
fmt.BitsPerPixel = 32;
|
||||
fmt.BytesPerPixel = 4;
|
||||
fmt.Rmask = 0x000000FF;
|
||||
fmt.Gmask = 0x0000FF00;
|
||||
fmt.Bmask = 0x00FF0000;
|
||||
fmt.Amask = 0xFF000000;
|
||||
fmt.Rshift = 0;
|
||||
fmt.Gshift = 8;
|
||||
fmt.Bshift = 16;
|
||||
fmt.Ashift = 24;
|
||||
|
||||
SDL_Surface * texsurf = SDL_ConvertSurface(temp, &fmt, SDL_SWSURFACE);
|
||||
SDL_FreeSurface(temp);
|
||||
if (!texsurf)
|
||||
{
|
||||
cerr << '\'' << filename << "' was not converted properly!" << endl;
|
||||
return 0;
|
||||
}
|
||||
unsigned int * pixels = new unsigned int[texsurf->w * texsurf->h];
|
||||
int y;
|
||||
unsigned int dstOffset = texsurf->w * (texsurf->h - 1);
|
||||
unsigned int srcOffset = 0;
|
||||
for (y = 0; y < texsurf->h; y++)
|
||||
{
|
||||
memcpy(pixels + dstOffset,
|
||||
((unsigned int *)texsurf->pixels) + srcOffset,
|
||||
texsurf->w << 2);
|
||||
dstOffset -= texsurf->w;
|
||||
srcOffset += texsurf->w;
|
||||
}
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4, texsurf->w, texsurf->h, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
if (quality > 0)
|
||||
{
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
mipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
mipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
||||
mipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
mipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
|
||||
}
|
||||
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
|
||||
|
||||
if (mipmaps)
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA,
|
||||
texsurf->w, texsurf->h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
SDL_FreeSurface(texsurf);
|
||||
delete[] pixels;
|
||||
return texture;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class TextureCache
|
||||
{
|
||||
public:
|
||||
GLuint load(const std::string & filename);
|
||||
|
||||
private:
|
||||
/* methods */
|
||||
GLuint loadTexture(const char * filename,
|
||||
bool mipmaps = false,
|
||||
int mode = GL_DECAL,
|
||||
int quality = 1);
|
||||
|
||||
/* data */
|
||||
std::map< std::string, GLuint > m_cache;
|
||||
};
|
@ -1 +0,0 @@
|
||||
Subproject commit 9855d3e577208d7c1ebc73f31489c7da9d6f7d07
|
2
wfobj
2
wfobj
@ -1 +1 @@
|
||||
Subproject commit d06888128c5a645a8815cb86bb4b3dfe1c76f454
|
||||
Subproject commit a12c4ec42d9718e1b99085672077c2d98f78dd74
|
Loading…
x
Reference in New Issue
Block a user