Skip to content

Commit

Permalink
Added an SDL2 build option
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Dec 10, 2018
1 parent e076e36 commit 4ae4ff7
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ compiler:
before_install:
- sudo apt-get install libsdl-mixer1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libopenal-dev libglm-dev -y

script: make
script: make LINUX=1
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ ifeq ($(PROFILE),1)
FLAGS+= -pg
endif

SDL=1
ifeq ($(SDL),1)
#SDL=1
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
else
SDL_=sdl$(SDL)
TTF_ = SDL$(SDL)_ttf
IMAGE_ = SDL$(SDL)_image
endif

# library headers
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

This is a port to Linux & OpenPandora of Stunt Car Racer Remake, a windows remake of the old Stunt Car Racer from the AtariST/Amiga time.

To build on Linux, simply use `make LINUX=1`
For ODroid it will be `make ODROID=1`
and for PocketCHIP: `make CHIP=1`
a simple `make` will build for Pandora.
Also, you can also use SDL2 instead of SDL1, by adding `SDL=2` to the make command (so SDL2 Linux is `make LINUX=1 SDL=2`)

Some code (the OpenAL part) come from Forsaken/ProjectX port by chino.

Controls are:
Expand Down
63 changes: 63 additions & 0 deletions StuntCarRacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1950,11 +1950,20 @@ bool process_events()
int GL_MSAA = 0;
int main(int argc, const char** argv)
{
#ifdef USE_SDL2
SDL_Window *window = NULL;
SDL_GLContext context = NULL;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK)==-1) {
printf("Could not initialise SDL2: %s\n", SDL_GetError());
exit(-1);
}
#else
SDL_Surface *screen = NULL;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | SDL_INIT_EVENTTHREAD)==-1) {
printf("Could not initialise SDL: %s\n", SDL_GetError());
exit(-1);
}
#endif
atexit(SDL_Quit);

TTF_Init();
Expand Down Expand Up @@ -2015,22 +2024,47 @@ int main(int argc, const char** argv)
int flags = 0;
wideScreen = 0;
int screenH, screenW, screenX, screenY;
#ifdef USE_SDL2
flags = SDL_WINDOW_OPENGL;
#else
flags = SDL_OPENGL | SDL_DOUBLEBUF;
#endif
if(fullscreen)
#ifdef USE_SDL2
flags |= SDL_WINDOW_FULLSCREEN;
#else
flags |= SDL_FULLSCREEN;
#endif
#ifdef PANDORA
#ifdef USE_SDL2
flags |= SDL_WINDOW_FULLSCREEN;
#else
flags |= SDL_FULLSCREEN;
#endif
screenW = 800; screenH = 480;
#elif defined(CHIP)
#ifdef USE_SDL2
flags |= SDL_WINDOW_FULLSCREEN;
#else
flags |= SDL_FULLSCREEN;
#endif
screenW = 480; screenH = 272;
#else
if(desktop || fullscreen) {
#ifdef USE_SDL2
flags |= (desktop)?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_FULLSCREEN;
#else
flags |= SDL_FULLSCREEN;
#endif
if(desktop) {
#ifdef USE_SDL2
screenW = 640;
screenH = 480;
#else
const SDL_VideoInfo* infos = SDL_GetVideoInfo();
screenW = infos->current_w;
screenH = infos->current_h;
#endif
} else {
screenW = 640;
screenH = 480;
Expand All @@ -2040,6 +2074,26 @@ int main(int argc, const char** argv)
screenH = 480;
}
#endif
#ifdef USE_SDL2
window = SDL_CreateWindow("StuntCarRemake", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screenW, screenH, flags);
if(window==NULL && GL_MSAA) {
// fallback to no MSAA
GL_MSAA=0;
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 0);
window = SDL_CreateWindow("StuntCarRemake", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screenW, screenH, flags);
}
if(window==NULL) {
printf("Couldn't create Window (%dx%d): %s\n", screenW, screenH, SDL_GetError());
exit(-2);
}
context = SDL_GL_CreateContext(window);
if(context==NULL) {
printf("Couldn't create OpenGL Context: %s\n", SDL_GetError());
exit(-3);
}
SDL_GetWindowSize(window, &screenW, &screenH);
#else
screen = SDL_SetVideoMode( screenW, screenH, 32, flags );
if ( screen == NULL ) {
// fallback to no MSAA
Expand All @@ -2058,6 +2112,7 @@ int main(int argc, const char** argv)
} else {
glEnable(GL_MULTISAMPLE);
}
#endif
// automatic guess the scale
float screenScale = 1.;
if(screenW/640. < screenH/480.)
Expand All @@ -2071,7 +2126,11 @@ int main(int argc, const char** argv)
screenY = (screenH-480.*screenScale)/2.;
screenW = (wideScreen?800:640)*screenScale;
screenH = 480*screenScale;
#ifdef USE_SDL2
if(flags&SDL_WINDOW_FULLSCREEN || flags&SDL_WINDOW_FULLSCREEN_DESKTOP)
#else
if(flags&SDL_FULLSCREEN)
#endif
SDL_ShowCursor(SDL_DISABLE);
glViewport(screenX, screenY, screenW, screenH);
glMatrixMode(GL_PROJECTION);
Expand Down Expand Up @@ -2127,7 +2186,11 @@ int main(int argc, const char** argv)
run = process_events();
OnFrameMove( &pd3dDevice, fTime, fTime - fLastTime, NULL );
OnFrameRender( &pd3dDevice, fTime, fTime - fLastTime, NULL );
#ifdef USE_SDL2
SDL_GL_SwapWindow(window);
#else
SDL_GL_SwapBuffers();
#endif

int32_t timetowait = (1.0f/50.0f - (fTime-fLastTime))*1000;
//int32_t timetowait = (1.0f/60.0f - (fTime-fLastTime))*1000;
Expand Down
4 changes: 4 additions & 0 deletions XBOXController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

// We need the Windows Header and the XInput Header
#ifdef linux
#ifdef USE_SDL2
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h>
#endif
#define XINPUT_STATE int
#else
#include <windows.h>
Expand Down
6 changes: 6 additions & 0 deletions dx_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#ifdef USE_SDL2
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_image.h>
#else
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_image.h>
#endif
#include <AL/al.h>
#include <wchar.h>
#define USEGLM
Expand Down
4 changes: 4 additions & 0 deletions sound_openal.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifdef linux

#include "dx_linux.h"
#ifdef USE_SDL2
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h>
#endif
#include <AL/al.h>
#include <AL/alc.h>
#include <math.h>
Expand Down

0 comments on commit 4ae4ff7

Please sign in to comment.