mirror of
https://github.com/aap/librw.git
synced 2024-11-25 05:05:42 +00:00
Add support for SDL2
This commit is contained in:
parent
75dbb7e67e
commit
86571b650b
@ -1,28 +1,36 @@
|
||||
image: Visual Studio 2017
|
||||
configuration: Release
|
||||
platform:
|
||||
- win-amd64-null
|
||||
- win-amd64-gl3
|
||||
- win-amd64-d3d9
|
||||
environment:
|
||||
APPVEYOR_SAVE_CACHE_ON_ERROR: true
|
||||
GLFW_BASE: glfw-3.2.1.bin.WIN64
|
||||
GLFW_URL: https://github.com/glfw/glfw/releases/download/3.2.1/%GLFW_BASE%.zip
|
||||
GLEW_BASE: glew-2.1.0
|
||||
GLEW_URL: https://github.com/nigels-com/glew/releases/download/glew-2.1.0/%GLEW_BASE%-win32.zip
|
||||
GLFW_BASE: glfw-3.2.1.bin.WIN64
|
||||
GLFW_URL: https://github.com/glfw/glfw/releases/download/3.2.1/%GLFW_BASE%.zip
|
||||
SDL2_BASE: SDL2-devel-2.0.8-VC
|
||||
SDL2_URL: https://www.libsdl.org/release/%SDL2_BASE%.zip
|
||||
SDL2_DIRAME: SDL2-2.0.8
|
||||
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-windows.zip
|
||||
matrix:
|
||||
- PLATFORM: win-amd64-null
|
||||
- PLATFORM: win-amd64-gl3
|
||||
PREMAKE5_EXTRA_ARGS: --gfxlib=glfw
|
||||
- PLATFORM: win-amd64-gl3
|
||||
PREMAKE5_EXTRA_ARGS: --gfxlib=sdl2
|
||||
- PLATFORM: win-amd64-d3d9
|
||||
|
||||
install:
|
||||
- appveyor DownloadFile %GLFW_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE%.zip"
|
||||
- 7z x "%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE%.zip"
|
||||
- appveyor DownloadFile %GLEW_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE%.zip"
|
||||
- 7z x "%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE%.zip"
|
||||
- appveyor DownloadFile %SDL2_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%SDL2_BASE%.zip"
|
||||
- 7z x "%APPVEYOR_BUILD_FOLDER%/%SDL2_BASE%.zip"
|
||||
- appveyor DownloadFile %PREMAKE5_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/premake5.zip"
|
||||
- mkdir "%APPVEYOR_BUILD_FOLDER%/bin" && cd "%APPVEYOR_BUILD_FOLDER%/bin" && 7z x "%APPVEYOR_BUILD_FOLDER%/premake5.zip"
|
||||
- set PATH=%APPVEYOR_BUILD_FOLDER%/bin;%PATH%
|
||||
before_build:
|
||||
- mkdir "%APPVEYOR_BUILD_FOLDER%/build"
|
||||
- cd "%APPVEYOR_BUILD_FOLDER%"
|
||||
- premake5 vs2017 --glfwdir=%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE% --glewdir=%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE%
|
||||
- premake5 vs2017 --glewdir=%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE% --glfwdir=%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE% --sdl2dir=%APPVEYOR_BUILD_FOLDER%/%SDL2_DIRAME% %PREMAKE5_EXTRA_ARGS%
|
||||
build:
|
||||
project: c:\projects\librw\build\librw.sln
|
||||
verbosity: minimal
|
||||
|
18
.travis.yml
18
.travis.yml
@ -3,7 +3,7 @@ language: cpp
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
env: TARGET="release_linux-amd64-null"
|
||||
env: TARGET=release_linux-amd64-null
|
||||
script:
|
||||
- mkdir -p "$TRAVIS_BUILD_DIR/build"
|
||||
#- docker build -t librw "$TRAVIS_BUILD_DIR"
|
||||
@ -12,7 +12,7 @@ matrix:
|
||||
- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity
|
||||
- docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1"
|
||||
- os: linux
|
||||
env: TARGET="release_linux-amd64-gl3"
|
||||
env: TARGET=release_linux-amd64-gl3 GFXLIB=glfw
|
||||
services: docker
|
||||
script:
|
||||
- mkdir -p "$TRAVIS_BUILD_DIR/build"
|
||||
@ -20,9 +20,19 @@ matrix:
|
||||
#- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity
|
||||
- docker pull librw/librw
|
||||
- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity
|
||||
- docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1"
|
||||
- docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 --gfxlib=$GFXLIB gmake && cd /librw/build && make config=$TARGET verbose=1"
|
||||
- os: linux
|
||||
env: TARGET="release_ps2"
|
||||
env: TARGET=release_linux-amd64-gl3 GFXLIB=sdl2
|
||||
services: docker
|
||||
script:
|
||||
- mkdir -p "$TRAVIS_BUILD_DIR/build"
|
||||
#- docker build -t librw "$TRAVIS_BUILD_DIR"
|
||||
#- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity
|
||||
- docker pull librw/librw
|
||||
- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity
|
||||
- docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 --gfxlib=$GFXLIB gmake && cd /librw/build && make config=$TARGET verbose=1"
|
||||
- os: linux
|
||||
env: TARGET=release_ps2
|
||||
services: docker
|
||||
script:
|
||||
- mkdir -p "$TRAVIS_BUILD_DIR/build"
|
||||
|
@ -30,6 +30,7 @@ RUN mkdir -p "$PS2DEV" "$PS2SDK" \
|
||||
zlib1g-dev \
|
||||
libglew-dev \
|
||||
libglfw3-dev \
|
||||
libsdl2-dev \
|
||||
&& git clone -b $TOOLCHAIN_GIT_BRANCH $TOOLCHAIN_GIT_URL /toolchain \
|
||||
&& cd /toolchain \
|
||||
&& ./toolchain.sh \
|
||||
|
45
premake5.lua
45
premake5.lua
@ -1,17 +1,35 @@
|
||||
newoption {
|
||||
trigger = "glewdir",
|
||||
value = "path",
|
||||
value = "PATH",
|
||||
description = "Directory of GLEW",
|
||||
default = "C:/Users/aap/src/glew-2.1.0",
|
||||
}
|
||||
|
||||
newoption {
|
||||
trigger = "gfxlib",
|
||||
value = "LIBRARY",
|
||||
description = "Choose a particular development library",
|
||||
default = "glfw",
|
||||
allowed = {
|
||||
{ "glfw", "GLFW" },
|
||||
{ "sdl2", "SDL2" },
|
||||
},
|
||||
}
|
||||
|
||||
newoption {
|
||||
trigger = "glfwdir",
|
||||
value = "path",
|
||||
value = "PATH",
|
||||
description = "Directory of glfw",
|
||||
default = "C:/Users/aap/src/glfw-3.2.1.bin.WIN64",
|
||||
}
|
||||
|
||||
newoption {
|
||||
trigger = "sdl2dir",
|
||||
value = "PATH",
|
||||
description = "Directory of sdl2",
|
||||
default = "C:/Users/aap/src/SDL2-2.0.8",
|
||||
}
|
||||
|
||||
workspace "librw"
|
||||
location "build"
|
||||
language "C++"
|
||||
@ -25,6 +43,9 @@ workspace "librw"
|
||||
platforms { "linux-x86-null", "linux-x86-gl3",
|
||||
"linux-amd64-null", "linux-amd64-gl3",
|
||||
"ps2" }
|
||||
if _OPTIONS["gfxlib"] == "sdl2" then
|
||||
includedirs { "/usr/include/SDL2" }
|
||||
end
|
||||
filter {}
|
||||
|
||||
filter "configurations:Debug"
|
||||
@ -40,6 +61,9 @@ workspace "librw"
|
||||
defines { "RW_NULL" }
|
||||
filter { "platforms:*gl3" }
|
||||
defines { "RW_GL3" }
|
||||
if _OPTIONS["gfxlib"] == "sdl2" then
|
||||
defines { "LIBRW_SDL2" }
|
||||
end
|
||||
filter { "platforms:*d3d9" }
|
||||
defines { "RW_D3D9" }
|
||||
filter { "platforms:ps2" }
|
||||
@ -64,6 +88,7 @@ workspace "librw"
|
||||
defines { "GLEW_STATIC" }
|
||||
includedirs { path.join(_OPTIONS["glewdir"], "include") }
|
||||
includedirs { path.join(_OPTIONS["glfwdir"], "include") }
|
||||
includedirs { path.join(_OPTIONS["sdl2dir"], "include") }
|
||||
|
||||
filter "action:vs*"
|
||||
buildoptions { "/wd4996", "/wd4244" }
|
||||
@ -91,16 +116,28 @@ project "dumprwtree"
|
||||
|
||||
function findlibs()
|
||||
filter { "platforms:linux*gl3" }
|
||||
links { "GL", "GLEW", "glfw" }
|
||||
links { "GL", "GLEW" }
|
||||
if _OPTIONS["gfxlib"] == "glfw" then
|
||||
links { "glfw" }
|
||||
else
|
||||
links { "SDL2" }
|
||||
end
|
||||
filter { "platforms:win*gl3" }
|
||||
defines { "GLEW_STATIC" }
|
||||
filter { "platforms:win-amd64-gl3" }
|
||||
libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/x64") }
|
||||
libdirs { path.join(_OPTIONS["glfwdir"], "lib-vc2015") }
|
||||
libdirs { path.join(_OPTIONS["sdl2dir"], "lib/x64") }
|
||||
filter { "platforms:win-x86-gl3" }
|
||||
libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/Win32") }
|
||||
libdirs { path.join(_OPTIONS["sdl2dir"], "lib/x86") }
|
||||
filter { "platforms:win*gl3" }
|
||||
links { "glew32s", "glfw3", "opengl32" }
|
||||
links { "glew32s", "opengl32" }
|
||||
if _OPTIONS["gfxlib"] == "glfw" then
|
||||
links { "glfw3" }
|
||||
else
|
||||
links { "SDL2" }
|
||||
end
|
||||
filter { "platforms:*d3d9" }
|
||||
links { "d3d9", "Xinput9_1_0" }
|
||||
filter {}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#ifndef LIBRW_SDL2
|
||||
|
||||
#include <rw.h>
|
||||
#include "skeleton.h"
|
||||
|
||||
@ -257,3 +259,4 @@ SetMousePosition(int x, int y)
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
325
skeleton/sdl2.cpp
Normal file
325
skeleton/sdl2.cpp
Normal file
@ -0,0 +1,325 @@
|
||||
#ifdef LIBRW_SDL2
|
||||
|
||||
#include <rw.h>
|
||||
#include "skeleton.h"
|
||||
|
||||
using namespace sk;
|
||||
using namespace rw;
|
||||
|
||||
#ifdef RW_OPENGL
|
||||
|
||||
SDL_Window *window;
|
||||
|
||||
static int keyCodeToSkKey(SDL_Keycode keycode) {
|
||||
switch (keycode) {
|
||||
case SDLK_SPACE: return ' ';
|
||||
case SDLK_QUOTE: return '\'';
|
||||
case SDLK_COMMA: return ',';
|
||||
case SDLK_MINUS: return '-';
|
||||
case SDLK_PERIOD: return '.';
|
||||
case SDLK_SLASH: return '/';
|
||||
|
||||
case SDLK_0: return '0';
|
||||
case SDLK_1: return '1';
|
||||
case SDLK_2: return '2';
|
||||
case SDLK_3: return '3';
|
||||
case SDLK_4: return '4';
|
||||
case SDLK_5: return '5';
|
||||
case SDLK_6: return '6';
|
||||
case SDLK_7: return '7';
|
||||
case SDLK_8: return '8';
|
||||
case SDLK_9: return '9';
|
||||
|
||||
case SDLK_SEMICOLON: return ';';
|
||||
case SDLK_EQUALS: return '=';
|
||||
|
||||
case SDLK_a: return 'A';
|
||||
case SDLK_b: return 'B';
|
||||
case SDLK_c: return 'C';
|
||||
case SDLK_d: return 'D';
|
||||
case SDLK_e: return 'E';
|
||||
case SDLK_f: return 'F';
|
||||
case SDLK_g: return 'G';
|
||||
case SDLK_h: return 'H';
|
||||
case SDLK_i: return 'I';
|
||||
case SDLK_j: return 'J';
|
||||
case SDLK_k: return 'K';
|
||||
case SDLK_l: return 'L';
|
||||
case SDLK_m: return 'M';
|
||||
case SDLK_n: return 'N';
|
||||
case SDLK_o: return 'O';
|
||||
case SDLK_p: return 'P';
|
||||
case SDLK_q: return 'Q';
|
||||
case SDLK_r: return 'R';
|
||||
case SDLK_s: return 'S';
|
||||
case SDLK_t: return 'T';
|
||||
case SDLK_u: return 'U';
|
||||
case SDLK_v: return 'V';
|
||||
case SDLK_w: return 'W';
|
||||
case SDLK_x: return 'X';
|
||||
case SDLK_y: return 'Y';
|
||||
case SDLK_z: return 'Z';
|
||||
|
||||
case SDLK_LEFTBRACKET: return '[';
|
||||
case SDLK_BACKSLASH: return '\\';
|
||||
case SDLK_RIGHTBRACKET: return ']';
|
||||
case SDLK_BACKQUOTE: return '`';
|
||||
case SDLK_ESCAPE: return KEY_ESC;
|
||||
case SDLK_RETURN: return KEY_ENTER;
|
||||
case SDLK_TAB: return KEY_TAB;
|
||||
case SDLK_BACKSPACE: return KEY_BACKSP;
|
||||
case SDLK_INSERT: return KEY_INS;
|
||||
case SDLK_DELETE: return KEY_DEL;
|
||||
case SDLK_RIGHT: return KEY_RIGHT;
|
||||
case SDLK_DOWN: return KEY_DOWN;
|
||||
case SDLK_UP: return KEY_UP;
|
||||
case SDLK_PAGEUP: return KEY_PGUP;
|
||||
case SDLK_PAGEDOWN: return KEY_PGDN;
|
||||
case SDLK_HOME: return KEY_HOME;
|
||||
case SDLK_END: return KEY_END;
|
||||
case SDLK_CAPSLOCK: return KEY_CAPSLK;
|
||||
case SDLK_SCROLLLOCK: return KEY_NULL;
|
||||
case SDLK_NUMLOCKCLEAR: return KEY_NULL;
|
||||
case SDLK_PRINTSCREEN: return KEY_NULL;
|
||||
case SDLK_PAUSE: return KEY_NULL;
|
||||
|
||||
case SDLK_F1: return KEY_F1;
|
||||
case SDLK_F2: return KEY_F2;
|
||||
case SDLK_F3: return KEY_F3;
|
||||
case SDLK_F4: return KEY_F4;
|
||||
case SDLK_F5: return KEY_F5;
|
||||
case SDLK_F6: return KEY_F6;
|
||||
case SDLK_F7: return KEY_F7;
|
||||
case SDLK_F8: return KEY_F8;
|
||||
case SDLK_F9: return KEY_F9;
|
||||
case SDLK_F10: return KEY_F10;
|
||||
case SDLK_F11: return KEY_F11;
|
||||
case SDLK_F12: return KEY_F12;
|
||||
case SDLK_F13: return KEY_NULL;
|
||||
case SDLK_F14: return KEY_NULL;
|
||||
case SDLK_F15: return KEY_NULL;
|
||||
case SDLK_F16: return KEY_NULL;
|
||||
case SDLK_F17: return KEY_NULL;
|
||||
case SDLK_F18: return KEY_NULL;
|
||||
case SDLK_F19: return KEY_NULL;
|
||||
case SDLK_F20: return KEY_NULL;
|
||||
case SDLK_F21: return KEY_NULL;
|
||||
case SDLK_F22: return KEY_NULL;
|
||||
case SDLK_F23: return KEY_NULL;
|
||||
case SDLK_F24: return KEY_NULL;
|
||||
|
||||
case SDLK_KP_0: return KEY_NULL;
|
||||
case SDLK_KP_1: return KEY_NULL;
|
||||
case SDLK_KP_2: return KEY_NULL;
|
||||
case SDLK_KP_3: return KEY_NULL;
|
||||
case SDLK_KP_4: return KEY_NULL;
|
||||
case SDLK_KP_5: return KEY_NULL;
|
||||
case SDLK_KP_6: return KEY_NULL;
|
||||
case SDLK_KP_7: return KEY_NULL;
|
||||
case SDLK_KP_8: return KEY_NULL;
|
||||
case SDLK_KP_9: return KEY_NULL;
|
||||
case SDLK_KP_DECIMAL: return KEY_NULL;
|
||||
case SDLK_KP_DIVIDE: return KEY_NULL;
|
||||
case SDLK_KP_MULTIPLY: return KEY_NULL;
|
||||
case SDLK_KP_MINUS: return KEY_NULL;
|
||||
case SDLK_KP_PLUS: return KEY_NULL;
|
||||
case SDLK_KP_ENTER: return KEY_NULL;
|
||||
case SDLK_KP_EQUALS: return KEY_NULL;
|
||||
|
||||
case SDLK_LSHIFT: return KEY_LSHIFT;
|
||||
case SDLK_LCTRL: return KEY_LCTRL;
|
||||
case SDLK_LALT: return KEY_LALT;
|
||||
case SDLK_LGUI: return KEY_NULL;
|
||||
case SDLK_RSHIFT: return KEY_RSHIFT;
|
||||
case SDLK_RCTRL: return KEY_RCTRL;
|
||||
case SDLK_RALT: return KEY_RALT;
|
||||
case SDLK_RGUI: return KEY_NULL;
|
||||
case SDLK_MENU: return KEY_NULL;
|
||||
}
|
||||
return KEY_NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
keypress(SDL_Window *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if(key >= 0 && key <= GLFW_KEY_LAST){
|
||||
if(action == GLFW_RELEASE) KeyUp(keymap[key]);
|
||||
else if(action == GLFW_PRESS) KeyDown(keymap[key]);
|
||||
else if(action == GLFW_REPEAT) KeyDown(keymap[key]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
charinput(GLFWwindow *window, unsigned int c)
|
||||
{
|
||||
EventHandler(CHARINPUT, (void*)(uintptr)c);
|
||||
}
|
||||
|
||||
static void
|
||||
resize(GLFWwindow *window, int w, int h)
|
||||
{
|
||||
rw::Rect r;
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.w = w;
|
||||
r.h = h;
|
||||
EventHandler(RESIZE, &r);
|
||||
}
|
||||
|
||||
static void
|
||||
mousebtn(GLFWwindow *window, int button, int action, int mods)
|
||||
{
|
||||
static int buttons = 0;
|
||||
sk::MouseState ms;
|
||||
|
||||
switch(button){
|
||||
case GLFW_MOUSE_BUTTON_LEFT:
|
||||
if(action == GLFW_PRESS)
|
||||
buttons |= 1;
|
||||
else
|
||||
buttons &= ~1;
|
||||
break;
|
||||
case GLFW_MOUSE_BUTTON_MIDDLE:
|
||||
if(action == GLFW_PRESS)
|
||||
buttons |= 2;
|
||||
else
|
||||
buttons &= ~2;
|
||||
break;
|
||||
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||
if(action == GLFW_PRESS)
|
||||
buttons |= 4;
|
||||
else
|
||||
buttons &= ~4;
|
||||
break;
|
||||
}
|
||||
|
||||
sk::MouseState ms;
|
||||
ms.buttons = buttons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
}
|
||||
#endif
|
||||
|
||||
enum mousebutton {
|
||||
BUTTON_LEFT = 0x1,
|
||||
BUTTON_MIDDLE = 0x2,
|
||||
BUTTON_RIGHT = 0x4,
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
|
||||
if(EventHandler(INITIALIZE, nil) == EVENTERROR)
|
||||
return 0;
|
||||
|
||||
engineStartParams.width = sk::globals.width;
|
||||
engineStartParams.height = sk::globals.height;
|
||||
engineStartParams.windowtitle = sk::globals.windowtitle;
|
||||
engineStartParams.window = &window;
|
||||
|
||||
if(EventHandler(RWINITIALIZE, nil) == EVENTERROR)
|
||||
return 0;
|
||||
|
||||
float lastTime = SDL_GetTicks();
|
||||
SDL_Event event;
|
||||
int mouseButtons = 0;
|
||||
|
||||
SDL_StartTextInput();
|
||||
|
||||
while(!sk::globals.quit){
|
||||
while(SDL_PollEvent(&event)){
|
||||
switch(event.type){
|
||||
case SDL_QUIT:
|
||||
sk::globals.quit = true;
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED: {
|
||||
rw::Rect r;
|
||||
SDL_GetWindowPosition(window, &r.x, &r.y);
|
||||
r.w = event.window.data1;
|
||||
r.h = event.window.data2;
|
||||
EventHandler(RESIZE, &r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KEYUP: {
|
||||
int c = keyCodeToSkKey(event.key.keysym.sym);
|
||||
EventHandler(KEYUP, &c);
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN: {
|
||||
int c = keyCodeToSkKey(event.key.keysym.sym);
|
||||
EventHandler(KEYDOWN, &c);
|
||||
break;
|
||||
}
|
||||
case SDL_TEXTINPUT: {
|
||||
char *c = event.text.text;
|
||||
while (int ci = *c) {
|
||||
EventHandler(CHARINPUT, (void*)(uintptr)ci);
|
||||
++c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEMOTION: {
|
||||
sk::MouseState ms;
|
||||
ms.posx = event.motion.x;
|
||||
ms.posy = event.motion.y;
|
||||
EventHandler(MOUSEMOVE, &ms);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: mouseButtons |= BUTTON_LEFT; break;
|
||||
case SDL_BUTTON_MIDDLE: mouseButtons |= BUTTON_MIDDLE; break;
|
||||
case SDL_BUTTON_RIGHT: mouseButtons |= BUTTON_RIGHT; break;
|
||||
}
|
||||
sk::MouseState ms;
|
||||
ms.buttons = mouseButtons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: mouseButtons &= ~BUTTON_LEFT; break;
|
||||
case SDL_BUTTON_MIDDLE: mouseButtons &= ~BUTTON_MIDDLE; break;
|
||||
case SDL_BUTTON_RIGHT: mouseButtons &= ~BUTTON_RIGHT; break;
|
||||
}
|
||||
sk::MouseState ms;
|
||||
ms.buttons = mouseButtons;
|
||||
EventHandler(MOUSEBTN, &ms);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
float currTime = SDL_GetTicks();
|
||||
float timeDelta = (currTime - lastTime) * 0.001f;
|
||||
|
||||
EventHandler(IDLE, &timeDelta);
|
||||
|
||||
lastTime = currTime;
|
||||
}
|
||||
|
||||
SDL_StopTextInput();
|
||||
|
||||
EventHandler(RWTERMINATE, nil);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace sk {
|
||||
|
||||
void
|
||||
SetMousePosition(int x, int y)
|
||||
{
|
||||
SDL_WarpMouseInWindow(*engineStartParams.window, x, y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -12,7 +12,11 @@
|
||||
#include "../rwobjects.h"
|
||||
#ifdef RW_OPENGL
|
||||
#include <GL/glew.h>
|
||||
#ifdef LIBRW_SDL2
|
||||
#include <SDL.h>
|
||||
#else
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
#include "rwgl3.h"
|
||||
#include "rwgl3shader.h"
|
||||
#include "rwgl3impl.h"
|
||||
@ -24,7 +28,12 @@ namespace gl3 {
|
||||
|
||||
struct GlGlobals
|
||||
{
|
||||
#ifdef LIBRW_SDL2
|
||||
SDL_Window *window;
|
||||
SDL_GLContext glcontext;
|
||||
#else
|
||||
GLFWwindow *window;
|
||||
#endif
|
||||
int presentWidth, presentHeight;
|
||||
} glGlobals;
|
||||
|
||||
@ -625,7 +634,11 @@ static void
|
||||
showRaster(Raster *raster)
|
||||
{
|
||||
// TODO: do this properly!
|
||||
#ifdef LIBRW_SDL2
|
||||
SDL_GL_SwapWindow(glGlobals.window);
|
||||
#else
|
||||
glfwSwapBuffers(glGlobals.window);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
@ -701,7 +714,11 @@ beginUpdate(Camera *cam)
|
||||
}
|
||||
|
||||
int w, h;
|
||||
#ifdef LIBRW_SDL2
|
||||
SDL_GetWindowSize(glGlobals.window, &w, &h);
|
||||
#else
|
||||
glfwGetWindowSize(glGlobals.window, &w, &h);
|
||||
#endif
|
||||
if(w != glGlobals.presentWidth || h != glGlobals.presentHeight){
|
||||
glViewport(0, 0, w, h);
|
||||
glGlobals.presentWidth = w;
|
||||
@ -709,6 +726,74 @@ beginUpdate(Camera *cam)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LIBRW_SDL2
|
||||
static int
|
||||
openSDL2(EngineStartParams *startparams)
|
||||
{
|
||||
if (!startparams){
|
||||
RWERROR((ERR_GENERAL, "startparams invalid"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLenum status;
|
||||
SDL_Window *win;
|
||||
SDL_GLContext ctx;
|
||||
|
||||
/* Init SDL */
|
||||
if(SDL_InitSubSystem(SDL_INIT_VIDEO)){
|
||||
RWERROR((ERR_ENGINEOPEN, SDL_GetError()));
|
||||
return 0;
|
||||
}
|
||||
SDL_ClearHints();
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
|
||||
int flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL;
|
||||
if (startparams->fullscreen)
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
win = SDL_CreateWindow(startparams->windowtitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, startparams->width, startparams->height, flags);
|
||||
if(win == nil){
|
||||
RWERROR((ERR_ENGINEOPEN, SDL_GetError()));
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
return 0;
|
||||
}
|
||||
ctx = SDL_GL_CreateContext(win);
|
||||
|
||||
/* Init GLEW */
|
||||
glewExperimental = GL_TRUE;
|
||||
status = glewInit();
|
||||
if(status != GLEW_OK){
|
||||
RWERROR((ERR_ENGINEOPEN, glewGetErrorString(status)));
|
||||
SDL_GL_DeleteContext(ctx);
|
||||
SDL_DestroyWindow(win);
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
return 0;
|
||||
}
|
||||
if(!GLEW_VERSION_3_3){
|
||||
RWERROR((ERR_VERSION, "OpenGL 3.3 needed"));
|
||||
SDL_GL_DeleteContext(ctx);
|
||||
SDL_DestroyWindow(win);
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
return 0;
|
||||
}
|
||||
glGlobals.window = win;
|
||||
glGlobals.glcontext = ctx;
|
||||
*startparams->window = win;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
closeSDL2(void)
|
||||
{
|
||||
SDL_GL_DeleteContext(glGlobals.glcontext);
|
||||
SDL_DestroyWindow(glGlobals.window);
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
static int
|
||||
openGLFW(EngineStartParams *startparams)
|
||||
{
|
||||
@ -732,6 +817,14 @@ openGLFW(EngineStartParams *startparams)
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
if(startparams->fullscreen){
|
||||
int nbmonitors;
|
||||
auto monitors = glfwGetMonitors(&nbmonitors);
|
||||
if (nbmonitors){
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(monitors[0]);
|
||||
glfwSetWindowMonitor(win, monitors[0], 0, 0, mode->width, mode->height, mode->refreshRate);
|
||||
}
|
||||
}
|
||||
glfwMakeContextCurrent(win);
|
||||
|
||||
/* Init GLEW */
|
||||
@ -761,6 +854,7 @@ closeGLFW(void)
|
||||
glfwTerminate();
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
initOpenGL(void)
|
||||
@ -836,9 +930,17 @@ deviceSystem(DeviceReq req, void *arg0)
|
||||
{
|
||||
switch(req){
|
||||
case DEVICEOPEN:
|
||||
#ifdef LIBRW_SDL2
|
||||
return openSDL2((EngineStartParams*)arg0);
|
||||
#else
|
||||
return openGLFW((EngineStartParams*)arg0);
|
||||
#endif
|
||||
case DEVICECLOSE:
|
||||
#ifdef LIBRW_SDL2
|
||||
return closeSDL2();
|
||||
#else
|
||||
return closeGLFW();
|
||||
#endif
|
||||
|
||||
case DEVICEINIT:
|
||||
return initOpenGL();
|
||||
|
@ -1,15 +1,24 @@
|
||||
#ifdef RW_GL3
|
||||
#include <GL/glew.h>
|
||||
#ifdef LIBRW_SDL2
|
||||
#include <SDL.h>
|
||||
#else
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace rw {
|
||||
|
||||
#ifdef RW_GL3
|
||||
struct EngineStartParams
|
||||
{
|
||||
#ifdef LIBRW_SDL2
|
||||
SDL_Window **window;
|
||||
#else
|
||||
GLFWwindow **window;
|
||||
#endif
|
||||
int width, height;
|
||||
bool32 fullscreen;
|
||||
const char *windowtitle;
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user