Skip to content

Commit 47cde06

Browse files
DanielGibsonYamagi
authored andcommitted
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()
1 parent 046ae5c commit 47cde06

File tree

8 files changed

+6478
-718
lines changed

8 files changed

+6478
-718
lines changed

Diff for: Makefile

+2-23
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# - libGL #
1212
# #
1313
# Further dependencies: #
14-
# - libjpeg #
1514
# - libogg #
1615
# - libvorbis #
1716
# - OpenAL #
@@ -45,10 +44,6 @@ WITH_OGG:=yes
4544
# installed
4645
WITH_OPENAL:=yes
4746

48-
# Enables retexturing support. Adds
49-
# a dependency to libjpeg
50-
WITH_RETEXTURING:=yes
51-
5247
# Use SDL2 instead of SDL1.2. Disables CD audio support,
5348
# because SDL2 has none. Use OGG/Vorbis music instead :-)
5449
# On Windows sdl-config isn't used, so make sure that
@@ -165,7 +160,7 @@ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
165160
CFLAGS += $(OSX_ARCH)
166161
else
167162
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
168-
-Wall -pipe -g -MMD
163+
-Wall -pipe -g -ggdb -MMD
169164
endif
170165

171166
# ----------
@@ -312,7 +307,6 @@ config:
312307
@echo "============================"
313308
@echo "WITH_CDA = $(WITH_CDA)"
314309
@echo "WITH_OPENAL = $(WITH_OPENAL)"
315-
@echo "WITH_RETEXTURING = $(WITH_RETEXTURING)"
316310
@echo "WITH_SDL2 = $(WITH_SDL2)"
317311
@echo "WITH_X11GAMMA = $(WITH_X11GAMMA)"
318312
@echo "WITH_ZIP = $(WITH_ZIP)"
@@ -376,11 +370,6 @@ ifeq ($(WITH_ZIP),yes)
376370
release/quake2.exe : CFLAGS += -DZIP -DNOUNCRYPT
377371
release/quake2.exe : LDFLAGS += -lz
378372
endif
379-
380-
ifeq ($(WITH_RETEXTURING),yes)
381-
release/quake2.exe : CFLAGS += -DRETEXTURE
382-
release/quake2.exe : LDFLAGS += -ljpeg
383-
endif
384373

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

441-
ifeq ($(WITH_RETEXTURING),yes)
442-
release/quake2 : CFLAGS += -DRETEXTURE
443-
ifeq ($(OSTYPE), Darwin)
444-
release/quake2 : LDFLAGS += -framework libjpeg
445-
else
446-
release/quake2 : LDFLAGS += -ljpeg
447-
endif
448-
endif
449-
450430
ifeq ($(WITH_SDL2),yes)
451431
release/quake2 : CFLAGS += -DSDL2
452432
endif
@@ -649,8 +629,7 @@ CLIENT_OBJS_ := \
649629
src/client/refresh/files/md2.o \
650630
src/client/refresh/files/pcx.o \
651631
src/client/refresh/files/sp2.o \
652-
src/client/refresh/files/tga.o \
653-
src/client/refresh/files/jpeg.o \
632+
src/client/refresh/files/stb.o \
654633
src/client/refresh/files/wal.o \
655634
src/client/menu/menu.o \
656635
src/client/menu/qmenu.o \

Diff for: src/client/refresh/files/jpeg.c

-181
This file was deleted.

Diff for: src/client/refresh/files/stb.c

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (C) 1997-2001 Id Software, Inc.
3+
* Copyright (C) 2015 Daniel Gibson
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or (at
8+
* your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but
11+
* WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13+
*
14+
* See the GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19+
* 02111-1307, USA.
20+
*
21+
* =======================================================================
22+
*
23+
* File formats supported by stb_image, for now only tga, png, jpg
24+
* See also https://github.com/nothings/stb
25+
*
26+
* =======================================================================
27+
*/
28+
29+
#include <stdlib.h>
30+
31+
#include "../header/local.h"
32+
33+
// don't need HDR stuff
34+
#define STBI_NO_LINEAR
35+
#define STBI_NO_HDR
36+
// make sure STB_image uses standard malloc(), as we'll use standard free() to deallocate
37+
#define STBI_MALLOC(sz) malloc(sz)
38+
#define STBI_REALLOC(p,sz) realloc(p,sz)
39+
#define STBI_FREE(p) free(p)
40+
// include implementation part of stb_image into this file
41+
#define STB_IMAGE_IMPLEMENTATION
42+
#include "stb_image.h"
43+
44+
/*
45+
* origname: the filename to be opened, might be without extension
46+
* type: extension of the type we wanna open ("jpg", "png" or "tga")
47+
* pic: pointer RGBA pixel data will be assigned to
48+
*/
49+
qboolean
50+
LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height)
51+
{
52+
char filename[256];
53+
54+
Q_strlcpy(filename, origname, sizeof(filename));
55+
56+
/* Add the extension */
57+
if (strcmp(COM_FileExtension(filename), type) != 0)
58+
{
59+
Q_strlcat(filename, ".", sizeof(filename));
60+
Q_strlcat(filename, type, sizeof(filename));
61+
}
62+
63+
*pic = NULL;
64+
65+
byte* rawdata = NULL;
66+
int rawsize = FS_LoadFile(filename, (void **)&rawdata);
67+
if (rawdata == NULL)
68+
{
69+
return false;
70+
}
71+
72+
int w, h, bytesPerPixel;
73+
byte* data = NULL;
74+
data = stbi_load_from_memory(rawdata, rawsize, &w, &h, &bytesPerPixel, STBI_rgb_alpha);
75+
if (data == NULL)
76+
{
77+
VID_Printf(PRINT_ALL, "stb_image couldn't load data from %s: %s!\n", filename, stbi_failure_reason());
78+
FS_FreeFile(rawdata);
79+
return false;
80+
}
81+
82+
FS_FreeFile(rawdata);
83+
84+
VID_Printf(PRINT_DEVELOPER, "LoadSTB() loaded: %s\n", filename);
85+
86+
*pic = data;
87+
*width = w;
88+
*height = h;
89+
return true;
90+
}
91+
92+
93+

0 commit comments

Comments
 (0)