Skip to content
Permalink
Browse files
Use stb_image for retexturing support, also support png, no more libjpeg
Retexturing support is now always on (you can still switch it off with
the gl_retexturing  CVAR), as we don't have the additional libjpeg
dependency anymore.

stb_image is used for tga, jpg and the newly supported png, so the
old tga and jpeg loading code has been removed.

I furthermore cleaned up the somehow messy and possibly slightly broken
retexturing selection code in R_FindImage()
  • Loading branch information
DanielGibson authored and Yamagi committed Mar 20, 2015
1 parent 046ae5c commit 47cde06
Show file tree
Hide file tree
Showing 8 changed files with 6,478 additions and 718 deletions.
@@ -11,7 +11,6 @@
# - libGL #
# #
# Further dependencies: #
# - libjpeg #
# - libogg #
# - libvorbis #
# - OpenAL #
@@ -45,10 +44,6 @@ WITH_OGG:=yes
# installed
WITH_OPENAL:=yes

# Enables retexturing support. Adds
# a dependency to libjpeg
WITH_RETEXTURING:=yes

# Use SDL2 instead of SDL1.2. Disables CD audio support,
# because SDL2 has none. Use OGG/Vorbis music instead :-)
# On Windows sdl-config isn't used, so make sure that
@@ -165,7 +160,7 @@ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
CFLAGS += $(OSX_ARCH)
else
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -MMD
-Wall -pipe -g -ggdb -MMD
endif

# ----------
@@ -312,7 +307,6 @@ config:
@echo "============================"
@echo "WITH_CDA = $(WITH_CDA)"
@echo "WITH_OPENAL = $(WITH_OPENAL)"
@echo "WITH_RETEXTURING = $(WITH_RETEXTURING)"
@echo "WITH_SDL2 = $(WITH_SDL2)"
@echo "WITH_X11GAMMA = $(WITH_X11GAMMA)"
@echo "WITH_ZIP = $(WITH_ZIP)"
@@ -376,11 +370,6 @@ ifeq ($(WITH_ZIP),yes)
release/quake2.exe : CFLAGS += -DZIP -DNOUNCRYPT
release/quake2.exe : LDFLAGS += -lz
endif

ifeq ($(WITH_RETEXTURING),yes)
release/quake2.exe : CFLAGS += -DRETEXTURE
release/quake2.exe : LDFLAGS += -ljpeg
endif

ifeq ($(WITH_SDL2),yes)
release/quake2.exe : CFLAGS += -DSDL2
@@ -438,15 +427,6 @@ ifeq ($(WITH_X11GAMMA),yes)
release/quake2 : CFLAGS += -DX11GAMMA
endif

ifeq ($(WITH_RETEXTURING),yes)
release/quake2 : CFLAGS += -DRETEXTURE
ifeq ($(OSTYPE), Darwin)
release/quake2 : LDFLAGS += -framework libjpeg
else
release/quake2 : LDFLAGS += -ljpeg
endif
endif

ifeq ($(WITH_SDL2),yes)
release/quake2 : CFLAGS += -DSDL2
endif
@@ -649,8 +629,7 @@ CLIENT_OBJS_ := \
src/client/refresh/files/md2.o \
src/client/refresh/files/pcx.o \
src/client/refresh/files/sp2.o \
src/client/refresh/files/tga.o \
src/client/refresh/files/jpeg.o \
src/client/refresh/files/stb.o \
src/client/refresh/files/wal.o \
src/client/menu/menu.o \
src/client/menu/qmenu.o \

This file was deleted.

@@ -0,0 +1,93 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2015 Daniel Gibson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* File formats supported by stb_image, for now only tga, png, jpg
* See also https://github.com/nothings/stb
*
* =======================================================================
*/

#include <stdlib.h>

#include "../header/local.h"

// don't need HDR stuff
#define STBI_NO_LINEAR
#define STBI_NO_HDR
// make sure STB_image uses standard malloc(), as we'll use standard free() to deallocate
#define STBI_MALLOC(sz) malloc(sz)
#define STBI_REALLOC(p,sz) realloc(p,sz)
#define STBI_FREE(p) free(p)
// include implementation part of stb_image into this file
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

/*
* origname: the filename to be opened, might be without extension
* type: extension of the type we wanna open ("jpg", "png" or "tga")
* pic: pointer RGBA pixel data will be assigned to
*/
qboolean
LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height)
{
char filename[256];

Q_strlcpy(filename, origname, sizeof(filename));

/* Add the extension */
if (strcmp(COM_FileExtension(filename), type) != 0)
{
Q_strlcat(filename, ".", sizeof(filename));
Q_strlcat(filename, type, sizeof(filename));
}

*pic = NULL;

byte* rawdata = NULL;
int rawsize = FS_LoadFile(filename, (void **)&rawdata);
if (rawdata == NULL)
{
return false;
}

int w, h, bytesPerPixel;
byte* data = NULL;
data = stbi_load_from_memory(rawdata, rawsize, &w, &h, &bytesPerPixel, STBI_rgb_alpha);
if (data == NULL)
{
VID_Printf(PRINT_ALL, "stb_image couldn't load data from %s: %s!\n", filename, stbi_failure_reason());
FS_FreeFile(rawdata);
return false;
}

FS_FreeFile(rawdata);

VID_Printf(PRINT_DEVELOPER, "LoadSTB() loaded: %s\n", filename);

*pic = data;
*width = w;
*height = h;
return true;
}



0 comments on commit 47cde06

Please sign in to comment.