Skip to content

Commit

Permalink
[LINUX] Removed SDL_Image dependancy to use stb_image instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Jul 8, 2019
1 parent 40fc811 commit 647f899
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,18 @@ endif
ifeq ($(SDL),2)
SDL_=sdl2
TTF_ = SDL2_ttf
IMAGE_ = SDL2_image
CFLAGS += -DUSE_SDL2
else
SDL_=
CFLAGS+=`sdl-config --cflags`
TTF_ = SDL_ttf
IMAGE_ = SDL_image
endif

# library headers
ifeq ($(PANDORA),1)
CFLAGS+= `pkg-config --cflags $(SDL_) $(TTF_) $(IMAGE_) libpng zlib openal`
CFLAGS+= `pkg-config --cflags $(SDL_) $(TTF_) libpng zlib openal`
else
CFLAGS+= `pkg-config --cflags $(SDL_) $(TTF_) $(IMAGE_) libpng zlib openal`
CFLAGS+= `pkg-config --cflags $(SDL_) $(TTF_) libpng zlib openal`
endif

# dynamic only libraries
Expand All @@ -92,7 +90,7 @@ else
LIB+= `pkg-config --libs $(SDL_)`
endif

LIB+= `pkg-config --libs $(TTF_) $(IMAGE_)`
LIB+= `pkg-config --libs $(TTF_)`

ifeq ($(MINGW),1)
LIB += -L./mingw/bin
Expand Down
32 changes: 18 additions & 14 deletions dx_linux.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#ifdef linux
#include "dx_linux.h"
// use a light version of stb_image
#define STBI_NO_PSD
#define STBI_NO_GIF
#define STBI_NO_HDR
#define STBI_NO_PIC
#define STBI_NO_PNM
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

extern bool wideScreen;

Expand All @@ -25,33 +33,28 @@ void IDirect3DTexture9::LoadTexture(const char* name)
{
if (texID) glDeleteTextures(1, &texID);
glGenTextures(1, &texID);
SDL_Surface *img = IMG_Load(BitMapRessourceName(name));
int x,y,n;
unsigned char *img = stbi_load(BitMapRessourceName(name), &x, &y, &n, 0);
if(!img) {
printf("Warning, image \"%s\" => \"%s\" not loaded\n", name, BitMapRessourceName(name));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
return;
}
GLint intfmt = img->format->BytesPerPixel;
GLint intfmt = n;
GLenum fmt = GL_RGBA;
switch (intfmt) {
case 1:
fmt = GL_ALPHA;
break;
case 3: // no alpha channel
if (img->format->Rmask == 0x000000ff)
fmt = GL_RGB;
else
fmt = GL_BGR;
fmt = GL_RGB;
break;
case 4: // contains an alpha channel
if (img->format->Rmask == 0x000000ff)
fmt = GL_RGBA;
else
fmt = GL_BGRA;
fmt = GL_RGBA;
break;
}
w2 = w = img->w;
h2 = h = img->h;
w2 = w = x;
h2 = h = y;
// will handle non-pot2 texture later? or resize the texture to POT?
/*w2 = NP2(w);
h2 = NP2(h);
Expand All @@ -65,11 +68,12 @@ void IDirect3DTexture9::LoadTexture(const char* name)
glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE );
glTexImage2D(GL_TEXTURE_2D, 0, intfmt, w2, h2, 0, fmt, GL_UNSIGNED_BYTE, NULL);
// simple and hugly way to make the texture upside down...
int pitch = y*n;
for (int i = 0; i< h ; i++) {
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, (h-1)-i, w, 1, fmt, GL_UNSIGNED_BYTE, (char*)(img->pixels)+(img->pitch*i));
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, (h-1)-i, w, 1, fmt, GL_UNSIGNED_BYTE, img+(pitch*i));
}
UnBind();
if (img) SDL_FreeSurface(img);
if (img) free(img);
}


Expand Down

0 comments on commit 647f899

Please sign in to comment.