Skip to content

Commit c2250b7

Browse files
committed
Add SDL2 compile option.
This sets SDL2 as the default as well.
1 parent f507a7a commit c2250b7

12 files changed

Lines changed: 683 additions & 48 deletions

File tree

Makefile

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ ifndef DEBUG_CFLAGS
240240
DEBUG_CFLAGS=-g -O0
241241
endif
242242

243+
ifndef SDL_VERSION
244+
SDL_VERSION=2
245+
endif
246+
243247
#############################################################################
244248

245249
BD=$(BUILD_DIR)/debug-$(PLATFORM)-$(ARCH)
@@ -274,7 +278,11 @@ Q3LCCETCDIR=$(MOUNT_DIR)/tools/lcc/etc
274278
Q3LCCSRCDIR=$(MOUNT_DIR)/tools/lcc/src
275279
LOKISETUPDIR=misc/setup
276280
NSISDIR=misc/nsis
277-
SDLHDIR=$(MOUNT_DIR)/SDL12
281+
ifeq ($(SDL_VERSION),2)
282+
SDLHDIR=$(MOUNT_DIR)/SDL2
283+
else
284+
SDLHDIR=$(MOUNT_DIR)/SDL12
285+
endif
278286
LIBSDIR=$(MOUNT_DIR)/libs
279287

280288
bin_path=$(shell which $(1) 2> /dev/null)
@@ -288,15 +296,27 @@ ifneq ($(BUILD_CLIENT),0)
288296
CURL_LIBS=$(shell pkg-config --silence-errors --libs libcurl)
289297
OPENAL_CFLAGS=$(shell pkg-config --silence-errors --cflags openal)
290298
OPENAL_LIBS=$(shell pkg-config --silence-errors --libs openal)
291-
SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl|sed 's/-Dmain=SDL_main//')
292-
SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl)
299+
ifeq ($(SDL_VERSION),2)
300+
SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl2|sed 's/-Dmain=SDL_main//')
301+
SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl2)
302+
else
303+
SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl|sed 's/-Dmain=SDL_main//')
304+
SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl)
305+
endif
293306
FREETYPE_CFLAGS=$(shell pkg-config --silence-errors --cflags freetype2)
294307
endif
295308
# Use sdl-config if all else fails
296309
ifeq ($(SDL_CFLAGS),)
297-
ifneq ($(call bin_path, sdl-config),)
298-
SDL_CFLAGS=$(shell sdl-config --cflags)
299-
SDL_LIBS=$(shell sdl-config --libs)
310+
ifeq ($(SDL_VERSION),2)
311+
ifneq ($(call bin_path, sdl2-config),)
312+
SDL_CFLAGS=$(shell sdl2-config --cflags)
313+
SDL_LIBS=$(shell sdl2-config --libs)
314+
endif
315+
else
316+
ifneq ($(call bin_path, sdl-config),)
317+
SDL_CFLAGS=$(shell sdl-config --cflags)
318+
SDL_LIBS=$(shell sdl-config --libs)
319+
endif
300320
endif
301321
endif
302322
endif
@@ -495,11 +515,17 @@ ifeq ($(PLATFORM),darwin)
495515

496516
# We copy sdlmain before ranlib'ing it so that subversion doesn't think
497517
# the file has been modified by each build.
498-
LIBSDLMAIN=$(B)/libSDLmain.a
499-
LIBSDLMAINSRC=$(LIBSDIR)/macosx/libSDLmain.a
500-
CLIENT_LIBS += -framework IOKit \
501-
$(LIBSDIR)/macosx/libSDL-1.2.0.dylib
502-
RENDERER_LIBS += -framework OpenGL $(LIBSDIR)/macosx/libSDL-1.2.0.dylib
518+
ifeq ($(SDL_VERSION),2)
519+
LIBSDLMAIN=$(B)/libSDL2main.a
520+
LIBSDLMAINSRC=$(LIBSDIR)/macosx/libSDL2main.a
521+
CLIENT_LIBS += -framework IOKit $(LIBSDIR)/macosx/libSDL2-2.0.0.dylib
522+
RENDERER_LIBS += -framework OpenGL $(LIBSDIR)/macosx/libSDL2-2.0.0.dylib
523+
else
524+
LIBSDLMAIN=$(B)/libSDLmain.a
525+
LIBSDLMAINSRC=$(LIBSDIR)/macosx/libSDLmain.a
526+
CLIENT_LIBS += -framework IOKit $(LIBSDIR)/macosx/libSDL-1.2.0.dylib
527+
RENDERER_LIBS += -framework OpenGL $(LIBSDIR)/macosx/libSDL-1.2.0.dylib
528+
endif
503529

504530
OPTIMIZEVM += -falign-loops=16
505531
OPTIMIZE = $(OPTIMIZEVM) -ffast-math
@@ -643,24 +669,44 @@ ifeq ($(PLATFORM),mingw32)
643669

644670
ifeq ($(USE_LOCAL_HEADERS),1)
645671
CLIENT_CFLAGS += -I$(SDLHDIR)/include
646-
ifeq ($(ARCH),x86)
647-
CLIENT_LIBS += $(LIBSDIR)/win32/libSDLmain.a \
648-
$(LIBSDIR)/win32/libSDL.dll.a
649-
RENDERER_LIBS += $(LIBSDIR)/win32/libSDLmain.a \
650-
$(LIBSDIR)/win32/libSDL.dll.a
651-
SDLDLL=SDL.dll
672+
ifeq ($(SDL_VERSION),2)
673+
ifeq ($(ARCH),x86)
674+
CLIENT_LIBS += $(LIBSDIR)/win32/libSDL2main.a \
675+
$(LIBSDIR)/win32/libSDL2.dll.a
676+
RENDERER_LIBS += $(LIBSDIR)/win32/libSDL2main.a \
677+
$(LIBSDIR)/win32/libSDL2.dll.a
678+
SDLDLL=SDL2.dll
679+
else
680+
CLIENT_LIBS += $(LIBSDIR)/win64/libSDL264main.a \
681+
$(LIBSDIR)/win64/libSDL264.dll.a
682+
RENDERER_LIBS += $(LIBSDIR)/win64/libSDL264main.a \
683+
$(LIBSDIR)/win64/libSDL264.dll.a
684+
SDLDLL=SDL264.dll
685+
endif
652686
else
653-
CLIENT_LIBS += $(LIBSDIR)/win64/libSDLmain.a \
654-
$(LIBSDIR)/win64/libSDL64.dll.a
655-
RENDERER_LIBS += $(LIBSDIR)/win64/libSDLmain.a \
656-
$(LIBSDIR)/win64/libSDL64.dll.a
657-
SDLDLL=SDL64.dll
687+
ifeq ($(ARCH),x86)
688+
CLIENT_LIBS += $(LIBSDIR)/win32/libSDLmain.a \
689+
$(LIBSDIR)/win32/libSDL.dll.a
690+
RENDERER_LIBS += $(LIBSDIR)/win32/libSDLmain.a \
691+
$(LIBSDIR)/win32/libSDL.dll.a
692+
SDLDLL=SDL.dll
693+
else
694+
CLIENT_LIBS += $(LIBSDIR)/win64/libSDLmain.a \
695+
$(LIBSDIR)/win64/libSDL64.dll.a
696+
RENDERER_LIBS += $(LIBSDIR)/win64/libSDLmain.a \
697+
$(LIBSDIR)/win64/libSDL64.dll.a
698+
SDLDLL=SDL64.dll
699+
endif
658700
endif
659701
else
660702
CLIENT_CFLAGS += $(SDL_CFLAGS)
661703
CLIENT_LIBS += $(SDL_LIBS)
662704
RENDERER_LIBS += $(SDL_LIBS)
663-
SDLDLL=SDL.dll
705+
ifeq ($(SDL_VERSION),2)
706+
SDLDLL=SDL2.dll
707+
else
708+
SDLDLL=SDL.dll
709+
endif
664710
endif
665711

666712
else # ifeq mingw32

Makefile.OpenArena

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ BUILD_RENDERER_OPENGL2=0
3333
# You can disable the renderer libraries and build in the OA renderer by default
3434
USE_RENDERER_DLOPEN=0
3535

36+
# Choose version 1 or 2
37+
SDL_VERSION=2
38+
3639
ifndef USE_CONSOLE_WINDOW
3740
USE_CONSOLE_WINDOW=1 # use an early console window (WIN32 only)
3841
endif

code/client/cl_keys.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2121
*/
2222
#include "client.h"
2323

24+
#ifdef USE_LOCAL_HEADERS
25+
# include "SDL.h"
26+
#else
27+
# include <SDL.h>
28+
#endif
29+
2430
/*
2531
2632
key up events are sent even if in console mode
@@ -401,7 +407,11 @@ void Field_Paste( field_t *edit ) {
401407
char *cbd;
402408
int pasteLen, i;
403409

410+
#if SDL_MAJOR_VERSION == 2
411+
cbd = SDL_GetClipboardText();
412+
#else
404413
cbd = Sys_GetClipboardData();
414+
#endif
405415

406416
if ( !cbd ) {
407417
return;
@@ -413,7 +423,11 @@ void Field_Paste( field_t *edit ) {
413423
Field_CharEvent( edit, cbd[i] );
414424
}
415425

426+
#if SDL_MAJOR_VERSION == 2
427+
SDL_free( cbd );
428+
#else
416429
Z_Free( cbd );
430+
#endif
417431
}
418432

419433
/*

code/client/cl_ui.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,11 @@ CL_GetClipboardData
584584
static void CL_GetClipboardData( char *buf, int buflen ) {
585585
char *cbd;
586586

587+
#if SDL_MAJOR_VERSION == 2
588+
cbd = Sys_GetClipboardData2();
589+
#else
587590
cbd = Sys_GetClipboardData();
591+
#endif
588592

589593
if ( !cbd ) {
590594
*buf = 0;

code/renderercommon/tr_public.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ typedef struct {
169169
void (*CL_WriteAVIVideoFrame)( const byte *buffer, int size );
170170

171171
// input event handling
172+
#if SDL_MAJOR_VERSION == 2
173+
void (*IN_Init)( void *windowData );
174+
#else
172175
void (*IN_Init)( void );
176+
#endif
173177
void (*IN_Shutdown)( void );
174178
void (*IN_Restart)( void );
175179

code/sdl/sdl_gamma.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2929
#include "../renderercommon/tr_common.h"
3030
#include "../qcommon/qcommon.h"
3131

32+
#if SDL_MAJOR_VERSION == 2
33+
extern SDL_Window *SDL_window;
34+
#endif
35+
3236
#ifdef _WIN32
3337
// leilei - 3dfx gamma fix
3438
BOOL ( WINAPI * qwglGetDeviceGammaRamp3DFX)( HDC, LPVOID );
@@ -103,7 +107,11 @@ void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned
103107
else
104108
#endif
105109
{
106-
SDL_SetGammaRamp(table[0], table[1], table[2]);
110+
#if SDL_MAJOR_VERSION == 2
111+
SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]);
112+
#else
113+
SDL_SetGammaRamp(table[0], table[1], table[2]);
114+
#endif
107115
}
108116
}
109117

0 commit comments

Comments
 (0)