mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-22 21:04:18 +08:00
Merge branch 'sdl2-gears' into 'master'
Sdl2 adjustments and sdl2 gears demo See merge request redox-os/cookbook!207
This commit is contained in:
commit
43eeb7e5fd
@ -22,6 +22,7 @@ function recipe_build {
|
||||
--host="$HOST" \
|
||||
--prefix='' \
|
||||
--disable-server \
|
||||
--enable-ipv6=no \
|
||||
--enable-client=sdl \
|
||||
--enable-fcmp=cli \
|
||||
--with-sdl-prefix="$sysroot" \
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
VERSION=2.0.9
|
||||
TAR=https://www.libsdl.org/release/SDL2-$VERSION.tar.gz
|
||||
BUILD_DEPENDS=(liborbital)
|
||||
GIT=https://gitlab.redox-os.org/fabiao/sdl2-src.git
|
||||
BUILD_DEPENDS=(liborbital mesa)
|
||||
|
||||
function recipe_version {
|
||||
echo "$VERSION"
|
||||
@ -26,7 +26,7 @@ function recipe_build {
|
||||
--disable-video-x11 \
|
||||
--disable-loadso \
|
||||
--disable-sdl-dlopen \
|
||||
--disable-threads \
|
||||
--enable-threads \
|
||||
--enable-audio \
|
||||
--enable-dummyaudio \
|
||||
--enable-video-orbital \
|
||||
|
||||
@ -1,919 +0,0 @@
|
||||
diff -ruwN source/configure.in source-new/configure.in
|
||||
--- source/configure.in 2018-10-31 09:07:22.000000000 -0600
|
||||
+++ source-new/configure.in 2019-01-06 17:29:39.198302773 -0700
|
||||
@@ -1222,6 +1222,18 @@
|
||||
fi
|
||||
}
|
||||
|
||||
+dnl Set up the Redox Audio driver
|
||||
+CheckRedoxAudio()
|
||||
+{
|
||||
+ AC_ARG_ENABLE(redoxaudio,
|
||||
+AC_HELP_STRING([--enable-redoxaudio], [support the redox audio driver [[default=yes]]]),
|
||||
+ , enable_redoxaudio=yes)
|
||||
+ if test x$enable_audio = xyes -a x$enable_redoxaudio = xyes; then
|
||||
+ AC_DEFINE(SDL_AUDIO_DRIVER_REDOX)
|
||||
+ SOURCES="$SOURCES $srcdir/src/audio/redox/*.c"
|
||||
+ fi
|
||||
+}
|
||||
+
|
||||
dnl rcg07142001 See if the user wants the disk writer audio driver...
|
||||
CheckDiskAudio()
|
||||
{
|
||||
@@ -2282,6 +2294,20 @@
|
||||
fi
|
||||
}
|
||||
|
||||
+dnl Set up the Orbital video driver.
|
||||
+CheckOrbitalVideo()
|
||||
+{
|
||||
+ AC_ARG_ENABLE(video-orbital,
|
||||
+AC_HELP_STRING([--enable-video-orbital], [use orbital video driver [[default=yes]]]),
|
||||
+ , enable_video_orbital=yes)
|
||||
+ if test x$enable_video_orbital = xyes; then
|
||||
+ AC_DEFINE(SDL_VIDEO_DRIVER_ORBITAL)
|
||||
+ SOURCES="$SOURCES $srcdir/src/video/orbital/*.c"
|
||||
+ SDL_LIBS="$SDL_LIBS -Wl,--gc-sections -lorbital"
|
||||
+ have_video=yes
|
||||
+ fi
|
||||
+}
|
||||
+
|
||||
dnl Set up the QNX video driver if enabled
|
||||
CheckQNXVideo()
|
||||
{
|
||||
@@ -2789,6 +2815,10 @@
|
||||
AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]]),
|
||||
, enable_pthread_sem=yes)
|
||||
case "$host" in
|
||||
+ *-*-redox*)
|
||||
+ pthread_cflags="-D_REENTRANT"
|
||||
+ pthread_lib="-lpthread"
|
||||
+ ;;
|
||||
*-*-android*)
|
||||
pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
|
||||
pthread_lib=""
|
||||
@@ -3362,7 +3392,7 @@
|
||||
|
||||
dnl Set up the configuration based on the host platform!
|
||||
case "$host" in
|
||||
- *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*|*-*-nto*)
|
||||
+ *-*-linux*|*-*-uclinux*|*-*-redox*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*|*-*-nto*)
|
||||
case "$host" in
|
||||
*-*-android*)
|
||||
# Android
|
||||
@@ -3383,6 +3413,7 @@
|
||||
;;
|
||||
*-*-linux*) ARCH=linux ;;
|
||||
*-*-uclinux*) ARCH=linux ;;
|
||||
+ *-*-redox*) ARCH=redox ;;
|
||||
*-*-kfreebsd*-gnu) ARCH=kfreebsd-gnu ;;
|
||||
*-*-knetbsd*-gnu) ARCH=knetbsd-gnu ;;
|
||||
*-*-kopenbsd*-gnu) ARCH=kopenbsd-gnu ;;
|
||||
@@ -3404,6 +3435,8 @@
|
||||
CheckVisibilityHidden
|
||||
CheckDeclarationAfterStatement
|
||||
CheckDummyVideo
|
||||
+ CheckOrbitalVideo
|
||||
+ CheckRedoxAudio
|
||||
CheckDiskAudio
|
||||
CheckDummyAudio
|
||||
CheckDLOPEN
|
||||
diff -ruwN source/include/SDL_config.h.in source-new/include/SDL_config.h.in
|
||||
--- source/include/SDL_config.h.in 2018-10-31 09:07:22.000000000 -0600
|
||||
+++ source-new/include/SDL_config.h.in 2018-12-31 14:01:08.736950947 -0700
|
||||
@@ -263,6 +263,7 @@
|
||||
#undef SDL_AUDIO_DRIVER_PULSEAUDIO
|
||||
#undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_QSA
|
||||
+#undef SDL_AUDIO_DRIVER_REDOX
|
||||
#undef SDL_AUDIO_DRIVER_SNDIO
|
||||
#undef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_SUNAUDIO
|
||||
@@ -320,6 +321,7 @@
|
||||
#undef SDL_VIDEO_DRIVER_DIRECTFB
|
||||
#undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
|
||||
#undef SDL_VIDEO_DRIVER_DUMMY
|
||||
+#undef SDL_VIDEO_DRIVER_ORBITAL
|
||||
#undef SDL_VIDEO_DRIVER_WINDOWS
|
||||
#undef SDL_VIDEO_DRIVER_WAYLAND
|
||||
#undef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
|
||||
diff -ruwN source/src/audio/redox/SDL_redoxaudio.c source-new/src/audio/redox/SDL_redoxaudio.c
|
||||
--- source/src/audio/redox/SDL_redoxaudio.c 1969-12-31 17:00:00.000000000 -0700
|
||||
+++ source-new/src/audio/redox/SDL_redoxaudio.c 2018-12-31 14:01:08.736950947 -0700
|
||||
@@ -0,0 +1,169 @@
|
||||
+/*
|
||||
+ SDL - Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2012 Sam Lantinga
|
||||
+
|
||||
+ This library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ This library 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
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with this library; if not, write to the Free Software
|
||||
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+ Sam Lantinga
|
||||
+ slouken@libsdl.org
|
||||
+
|
||||
+ This file written by Ryan C. Gordon (icculus@icculus.org)
|
||||
+*/
|
||||
+#include "SDL_config.h"
|
||||
+
|
||||
+/* Output raw audio data to a file. */
|
||||
+
|
||||
+#include <fcntl.h>
|
||||
+#include <stdio.h>
|
||||
+#include <unistd.h>
|
||||
+
|
||||
+#include "SDL_timer.h"
|
||||
+#include "SDL_audio.h"
|
||||
+#include "../SDL_audiomem.h"
|
||||
+#include "../SDL_audio_c.h"
|
||||
+#include "../SDL_audiodev_c.h"
|
||||
+#include "SDL_redoxaudio.h"
|
||||
+
|
||||
+/* The tag name used by REDOX audio */
|
||||
+#define REDOXAUD_DRIVER_NAME "redox"
|
||||
+
|
||||
+/* Audio driver functions */
|
||||
+static int REDOXAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
|
||||
+static void REDOXAUD_WaitAudio(_THIS);
|
||||
+static void REDOXAUD_PlayAudio(_THIS);
|
||||
+static Uint8 *REDOXAUD_GetAudioBuf(_THIS);
|
||||
+static void REDOXAUD_CloseAudio(_THIS);
|
||||
+
|
||||
+/* Audio driver bootstrap functions */
|
||||
+static int REDOXAUD_Available(void)
|
||||
+{
|
||||
+ return(1);
|
||||
+}
|
||||
+
|
||||
+static void REDOXAUD_DeleteDevice(SDL_AudioDevice *device)
|
||||
+{
|
||||
+ SDL_free(device->hidden);
|
||||
+ SDL_free(device);
|
||||
+}
|
||||
+
|
||||
+static SDL_AudioDevice *REDOXAUD_CreateDevice(int devindex)
|
||||
+{
|
||||
+ SDL_AudioDevice *this;
|
||||
+ const char *envr;
|
||||
+
|
||||
+ /* Initialize all variables that we clean on shutdown */
|
||||
+ this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
|
||||
+ if ( this ) {
|
||||
+ SDL_memset(this, 0, (sizeof *this));
|
||||
+ this->hidden = (struct SDL_PrivateAudioData *)
|
||||
+ SDL_malloc((sizeof *this->hidden));
|
||||
+ }
|
||||
+ if ( (this == NULL) || (this->hidden == NULL) ) {
|
||||
+ SDL_OutOfMemory();
|
||||
+ if ( this ) {
|
||||
+ SDL_free(this);
|
||||
+ }
|
||||
+ return(0);
|
||||
+ }
|
||||
+ SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
+
|
||||
+ this->hidden->output = -1;
|
||||
+
|
||||
+ /* Set the function pointers */
|
||||
+ this->OpenAudio = REDOXAUD_OpenAudio;
|
||||
+ this->WaitAudio = REDOXAUD_WaitAudio;
|
||||
+ this->PlayAudio = REDOXAUD_PlayAudio;
|
||||
+ this->GetAudioBuf = REDOXAUD_GetAudioBuf;
|
||||
+ this->CloseAudio = REDOXAUD_CloseAudio;
|
||||
+
|
||||
+ this->free = REDOXAUD_DeleteDevice;
|
||||
+
|
||||
+ return this;
|
||||
+}
|
||||
+
|
||||
+AudioBootStrap REDOXAUD_bootstrap = {
|
||||
+ REDOXAUD_DRIVER_NAME, "Redox audio",
|
||||
+ REDOXAUD_Available, REDOXAUD_CreateDevice
|
||||
+};
|
||||
+
|
||||
+/* This function waits until it is possible to write a full sound buffer */
|
||||
+static void REDOXAUD_WaitAudio(_THIS)
|
||||
+{}
|
||||
+
|
||||
+static void REDOXAUD_PlayAudio(_THIS)
|
||||
+{
|
||||
+ int written;
|
||||
+
|
||||
+ /* Write the audio data */
|
||||
+ written = write(this->hidden->output,
|
||||
+ this->hidden->mixbuf,
|
||||
+ this->hidden->mixlen);
|
||||
+
|
||||
+ /* If we couldn't write, assume fatal error for now */
|
||||
+ if ( (Uint32)written != this->hidden->mixlen ) {
|
||||
+ this->enabled = 0;
|
||||
+ }
|
||||
+#ifdef DEBUG_AUDIO
|
||||
+ fprintf(stderr, "Wrote %d bytes of audio data\n", written);
|
||||
+#endif
|
||||
+}
|
||||
+
|
||||
+static Uint8 *REDOXAUD_GetAudioBuf(_THIS)
|
||||
+{
|
||||
+ return(this->hidden->mixbuf);
|
||||
+}
|
||||
+
|
||||
+static void REDOXAUD_CloseAudio(_THIS)
|
||||
+{
|
||||
+ if ( this->hidden->mixbuf != NULL ) {
|
||||
+ SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||
+ this->hidden->mixbuf = NULL;
|
||||
+ }
|
||||
+ if ( this->hidden->output >= 0 ) {
|
||||
+ close(this->hidden->output);
|
||||
+ this->hidden->output = -1;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static int REDOXAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
||||
+{
|
||||
+ fprintf(stderr, "WARNING: You are using the SDL redox audio driver!\n");
|
||||
+
|
||||
+ /* Open the audio device */
|
||||
+ this->hidden->output = open("audio:", O_WRONLY);
|
||||
+ if ( this->hidden->output < 0 ) {
|
||||
+ perror("failed to open audio:");
|
||||
+ return(-1);
|
||||
+ }
|
||||
+
|
||||
+ spec->freq = 44100;
|
||||
+ spec->format = AUDIO_S16;
|
||||
+ spec->channels = 2;
|
||||
+ SDL_CalculateAudioSpec(spec);
|
||||
+
|
||||
+ /* Allocate mixing buffer */
|
||||
+ this->hidden->mixlen = spec->size;
|
||||
+ this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||
+ if ( this->hidden->mixbuf == NULL ) {
|
||||
+ perror("failed to allocate audio memory");
|
||||
+ return(-1);
|
||||
+ }
|
||||
+ SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
|
||||
+
|
||||
+ fprintf(stderr, "openaudio success\n");
|
||||
+
|
||||
+ /* We're ready to rock and roll. :-) */
|
||||
+ return(0);
|
||||
+}
|
||||
diff -ruwN source/src/audio/redox/SDL_redoxaudio.h source-new/src/audio/redox/SDL_redoxaudio.h
|
||||
--- source/src/audio/redox/SDL_redoxaudio.h 1969-12-31 17:00:00.000000000 -0700
|
||||
+++ source-new/src/audio/redox/SDL_redoxaudio.h 2018-12-31 14:01:08.736950947 -0700
|
||||
@@ -0,0 +1,40 @@
|
||||
+/*
|
||||
+ SDL - Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2012 Sam Lantinga
|
||||
+
|
||||
+ This library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ This library 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
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with this library; if not, write to the Free Software
|
||||
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+ Sam Lantinga
|
||||
+ slouken@libsdl.org
|
||||
+*/
|
||||
+#include "SDL_config.h"
|
||||
+
|
||||
+#ifndef _SDL_redoxaudio_h
|
||||
+#define _SDL_redoxaudio_h
|
||||
+
|
||||
+#include "SDL_rwops.h"
|
||||
+#include "../SDL_sysaudio.h"
|
||||
+
|
||||
+/* Hidden "this" pointer for the video functions */
|
||||
+#define _THIS SDL_AudioDevice *this
|
||||
+
|
||||
+struct SDL_PrivateAudioData {
|
||||
+ /* The file descriptor for the audio device */
|
||||
+ int output;
|
||||
+ Uint8 *mixbuf;
|
||||
+ Uint32 mixlen;
|
||||
+};
|
||||
+
|
||||
+#endif /* _SDL_redoxaudio_h */
|
||||
diff -ruwN source/src/audio/SDL_audio.c source-new/src/audio/SDL_audio.c
|
||||
--- source/src/audio/SDL_audio.c 2018-10-31 09:07:22.000000000 -0600
|
||||
+++ source-new/src/audio/SDL_audio.c 2018-12-31 14:01:08.736950947 -0700
|
||||
@@ -35,6 +35,9 @@
|
||||
|
||||
/* Available audio drivers */
|
||||
static const AudioBootStrap *const bootstrap[] = {
|
||||
+#if SDL_AUDIO_DRIVER_REDOX
|
||||
+ &REDOXAUD_bootstrap,
|
||||
+#endif
|
||||
#if SDL_AUDIO_DRIVER_PULSEAUDIO
|
||||
&PULSEAUDIO_bootstrap,
|
||||
#endif
|
||||
diff -ruwN source/src/audio/SDL_sysaudio.h source-new/src/audio/SDL_sysaudio.h
|
||||
--- source/src/audio/SDL_sysaudio.h 2018-10-31 09:07:22.000000000 -0600
|
||||
+++ source-new/src/audio/SDL_sysaudio.h 2018-12-31 14:01:08.736950947 -0700
|
||||
@@ -183,6 +183,7 @@
|
||||
} AudioBootStrap;
|
||||
|
||||
/* Not all of these are available in a given build. Use #ifdefs, etc. */
|
||||
+extern AudioBootStrap REDOXAUD_bootstrap;
|
||||
extern AudioBootStrap PULSEAUDIO_bootstrap;
|
||||
extern AudioBootStrap ALSA_bootstrap;
|
||||
extern AudioBootStrap JACK_bootstrap;
|
||||
diff -ruwN source/src/dynapi/SDL_dynapi.h source-new/src/dynapi/SDL_dynapi.h
|
||||
--- source/src/dynapi/SDL_dynapi.h 2018-10-31 09:07:22.000000000 -0600
|
||||
+++ source-new/src/dynapi/SDL_dynapi.h 2018-12-31 14:01:08.736950947 -0700
|
||||
@@ -55,6 +55,8 @@
|
||||
#define SDL_DYNAMIC_API 0
|
||||
#elif defined(__clang_analyzer__)
|
||||
#define SDL_DYNAMIC_API 0 /* Turn off for static analysis, so reports are more clear. */
|
||||
+#elif defined(__redox__)
|
||||
+#define SDL_DYNAMIC_API 0
|
||||
#endif
|
||||
|
||||
/* everyone else. This is where we turn on the API if nothing forced it off. */
|
||||
diff -ruwN source/src/thread/pthread/SDL_systhread.c source-new/src/thread/pthread/SDL_systhread.c
|
||||
--- source/src/thread/pthread/SDL_systhread.c 2018-10-31 09:07:22.000000000 -0600
|
||||
+++ source-new/src/thread/pthread/SDL_systhread.c 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -165,7 +165,11 @@
|
||||
for (i = 0; sig_list[i]; ++i) {
|
||||
sigaddset(&mask, sig_list[i]);
|
||||
}
|
||||
+ #if defined(__redox__)
|
||||
+ sigprocmask(SIG_BLOCK, &mask, 0);
|
||||
+ #else
|
||||
pthread_sigmask(SIG_BLOCK, &mask, 0);
|
||||
+ #endif
|
||||
#endif /* !__NACL__ */
|
||||
|
||||
|
||||
diff -ruwN source/src/video/orbital/SDL_orbitalevents.c source-new/src/video/orbital/SDL_orbitalevents.c
|
||||
--- source/src/video/orbital/SDL_orbitalevents.c 1969-12-31 17:00:00.000000000 -0700
|
||||
+++ source-new/src/video/orbital/SDL_orbitalevents.c 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -0,0 +1,192 @@
|
||||
+/*
|
||||
+ SDL - Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2012 Sam Lantinga
|
||||
+
|
||||
+ This library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ This library 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
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with this library; if not, write to the Free Software
|
||||
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+ Sam Lantinga
|
||||
+ slouken@libsdl.org
|
||||
+*/
|
||||
+#include "SDL_config.h"
|
||||
+
|
||||
+#include "SDL.h"
|
||||
+#include "../../events/SDL_sysevents.h"
|
||||
+#include "../../events/SDL_events_c.h"
|
||||
+
|
||||
+#include <orbital.h>
|
||||
+#include "SDL_orbitalvideo.h"
|
||||
+#include "SDL_orbitalevents_c.h"
|
||||
+
|
||||
+#include <unistd.h>
|
||||
+
|
||||
+static SDL_Keycode keymap[128];
|
||||
+
|
||||
+/* Static variables so only changes are reported */
|
||||
+static bool last_button_left = false;
|
||||
+static bool last_button_middle = false;
|
||||
+static bool last_button_right = false;
|
||||
+
|
||||
+void ORBITAL_PumpEvents(_THIS)
|
||||
+{
|
||||
+ SDL_Keysym keysym;
|
||||
+
|
||||
+ SDL_Mouse *mouse = SDL_GetMouse();
|
||||
+
|
||||
+ void* event_iter = orb_window_events(this->hidden->window);
|
||||
+ OrbEventOption oeo = orb_events_next(event_iter);
|
||||
+
|
||||
+ while (oeo.tag != OrbEventOption_None) {
|
||||
+ switch (oeo.tag) {
|
||||
+ case OrbEventOption_Key:
|
||||
+ keysym.scancode = oeo.key.scancode;
|
||||
+ keysym.sym = keymap[oeo.key.scancode];
|
||||
+ keysym.mod = KMOD_NONE;
|
||||
+
|
||||
+ SDL_SendKeyboardKey(oeo.key.pressed ? SDL_PRESSED : SDL_RELEASED, &keysym);
|
||||
+ break;
|
||||
+ case OrbEventOption_Mouse:
|
||||
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, oeo.mouse.x, oeo.mouse.y);
|
||||
+ break;
|
||||
+ case OrbEventOption_Button:
|
||||
+ if (oeo.button.left ^ last_button_left)
|
||||
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, oeo.button.left ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0);
|
||||
+ if (oeo.button.middle ^ last_button_middle)
|
||||
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, oeo.button.middle ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0);
|
||||
+ if (oeo.button.right ^ last_button_right)
|
||||
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, oeo.button.right ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0);
|
||||
+
|
||||
+ last_button_left = oeo.button.left;
|
||||
+ last_button_middle = oeo.button.middle;
|
||||
+ last_button_right = oeo.button.right;
|
||||
+ break;
|
||||
+ case OrbEventOption_Scroll:
|
||||
+ SDL_SendMouseWheel(mouse->focus, mouse->mouseID, oeo.scroll.x, oeo.scroll.y, SDL_MOUSEWHEEL_NORMAL);
|
||||
+ break;
|
||||
+ case OrbEventOption_Quit:
|
||||
+ SDL_PrivateQuit();
|
||||
+ break;
|
||||
+ case OrbEventOption_Focus:
|
||||
+ SDL_PrivateAppActive(oeo.focus.focused, SDL_APPMOUSEFOCUS);
|
||||
+ break;
|
||||
+ case OrbEventOption_Move:
|
||||
+ // oeo.move.x, oeo.move.y
|
||||
+ break;
|
||||
+ case OrbEventOption_Resize:
|
||||
+ SDL_PrivateResize(oeo.resize.width, oeo.resize.height);
|
||||
+ break;
|
||||
+ case OrbEventOption_Screen:
|
||||
+ // oeo.screen.width, oeo.screen.height
|
||||
+ break;
|
||||
+ case OrbEventOption_Unknown:
|
||||
+ // oeo.unknown.code, oeo.unknown.a, oeo.unknown.b
|
||||
+ break;
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ oeo = orb_events_next(event_iter);
|
||||
+ }
|
||||
+
|
||||
+ orb_events_destroy(event_iter);
|
||||
+}
|
||||
+
|
||||
+void ORBITAL_InitOSKeymap(_THIS)
|
||||
+{
|
||||
+ int i;
|
||||
+ for ( i = 0; i < SDL_arraysize(keymap); ++i )
|
||||
+ keymap[i] = SDLK_UNKNOWN;
|
||||
+
|
||||
+ keymap[ORB_KEY_ESC] = SDLK_ESCAPE;
|
||||
+ keymap[ORB_KEY_1] = SDLK_1;
|
||||
+ keymap[ORB_KEY_2] = SDLK_2;
|
||||
+ keymap[ORB_KEY_3] = SDLK_3;
|
||||
+ keymap[ORB_KEY_4] = SDLK_4;
|
||||
+ keymap[ORB_KEY_5] = SDLK_5;
|
||||
+ keymap[ORB_KEY_6] = SDLK_6;
|
||||
+ keymap[ORB_KEY_7] = SDLK_7;
|
||||
+ keymap[ORB_KEY_8] = SDLK_8;
|
||||
+ keymap[ORB_KEY_9] = SDLK_9;
|
||||
+ keymap[ORB_KEY_0] = SDLK_0;
|
||||
+ keymap[ORB_KEY_MINUS] = SDLK_MINUS;
|
||||
+ keymap[ORB_KEY_EQUALS] = SDLK_EQUALS;
|
||||
+ keymap[ORB_KEY_BKSP] = SDLK_BACKSPACE;
|
||||
+ keymap[ORB_KEY_TAB] = SDLK_TAB;
|
||||
+ keymap[ORB_KEY_Q] = SDLK_q;
|
||||
+ keymap[ORB_KEY_W] = SDLK_w;
|
||||
+ keymap[ORB_KEY_E] = SDLK_e;
|
||||
+ keymap[ORB_KEY_R] = SDLK_r;
|
||||
+ keymap[ORB_KEY_T] = SDLK_t;
|
||||
+ keymap[ORB_KEY_Y] = SDLK_y;
|
||||
+ keymap[ORB_KEY_U] = SDLK_u;
|
||||
+ keymap[ORB_KEY_I] = SDLK_i;
|
||||
+ keymap[ORB_KEY_O] = SDLK_o;
|
||||
+ keymap[ORB_KEY_P] = SDLK_p;
|
||||
+ keymap[ORB_KEY_BRACE_OPEN] = SDLK_LEFTBRACKET;
|
||||
+ keymap[ORB_KEY_BRACE_CLOSE] = SDLK_RIGHTBRACKET;
|
||||
+ keymap[ORB_KEY_ENTER] = SDLK_RETURN;
|
||||
+ keymap[ORB_KEY_CTRL] = SDLK_LCTRL;
|
||||
+ keymap[ORB_KEY_A] = SDLK_a;
|
||||
+ keymap[ORB_KEY_S] = SDLK_s;
|
||||
+ keymap[ORB_KEY_D] = SDLK_d;
|
||||
+ keymap[ORB_KEY_F] = SDLK_f;
|
||||
+ keymap[ORB_KEY_G] = SDLK_g;
|
||||
+ keymap[ORB_KEY_H] = SDLK_h;
|
||||
+ keymap[ORB_KEY_J] = SDLK_j;
|
||||
+ keymap[ORB_KEY_K] = SDLK_k;
|
||||
+ keymap[ORB_KEY_L] = SDLK_l;
|
||||
+ keymap[ORB_KEY_SEMICOLON] = SDLK_SEMICOLON;
|
||||
+ keymap[ORB_KEY_QUOTE] = SDLK_QUOTE;
|
||||
+ keymap[ORB_KEY_TICK] = SDLK_BACKQUOTE;
|
||||
+ keymap[ORB_KEY_LEFT_SHIFT] = SDLK_LSHIFT;
|
||||
+ keymap[ORB_KEY_RIGHT_SHIFT] = SDLK_RSHIFT;
|
||||
+ keymap[ORB_KEY_BACKSLASH] = SDLK_BACKSLASH;
|
||||
+ keymap[ORB_KEY_Z] = SDLK_z;
|
||||
+ keymap[ORB_KEY_X] = SDLK_x;
|
||||
+ keymap[ORB_KEY_C] = SDLK_c;
|
||||
+ keymap[ORB_KEY_V] = SDLK_v;
|
||||
+ keymap[ORB_KEY_B] = SDLK_b;
|
||||
+ keymap[ORB_KEY_N] = SDLK_n;
|
||||
+ keymap[ORB_KEY_M] = SDLK_m;
|
||||
+ keymap[ORB_KEY_COMMA] = SDLK_COMMA;
|
||||
+ keymap[ORB_KEY_PERIOD] = SDLK_PERIOD;
|
||||
+ keymap[ORB_KEY_SLASH] = SDLK_SLASH;
|
||||
+ keymap[ORB_KEY_ALT] = SDLK_LALT;
|
||||
+ keymap[ORB_KEY_SPACE] = SDLK_SPACE;
|
||||
+ keymap[ORB_KEY_CAPS] = SDLK_CAPSLOCK;
|
||||
+ keymap[ORB_KEY_F1] = SDLK_F1;
|
||||
+ keymap[ORB_KEY_F2] = SDLK_F2;
|
||||
+ keymap[ORB_KEY_F3] = SDLK_F3;
|
||||
+ keymap[ORB_KEY_F4] = SDLK_F4;
|
||||
+ keymap[ORB_KEY_F5] = SDLK_F5;
|
||||
+ keymap[ORB_KEY_F6] = SDLK_F6;
|
||||
+ keymap[ORB_KEY_F7] = SDLK_F7;
|
||||
+ keymap[ORB_KEY_F8] = SDLK_F8;
|
||||
+ keymap[ORB_KEY_F9] = SDLK_F9;
|
||||
+ keymap[ORB_KEY_F10] = SDLK_F10;
|
||||
+ keymap[ORB_KEY_F11] = SDLK_F11;
|
||||
+ keymap[ORB_KEY_F12] = SDLK_F12;
|
||||
+ keymap[ORB_KEY_HOME] = SDLK_HOME;
|
||||
+ keymap[ORB_KEY_UP] = SDLK_UP;
|
||||
+ keymap[ORB_KEY_PGUP] = SDLK_PAGEUP;
|
||||
+ keymap[ORB_KEY_LEFT] = SDLK_LEFT;
|
||||
+ keymap[ORB_KEY_RIGHT] = SDLK_RIGHT;
|
||||
+ keymap[ORB_KEY_END] = SDLK_END;
|
||||
+ keymap[ORB_KEY_DOWN] = SDLK_DOWN;
|
||||
+ keymap[ORB_KEY_PGDN] = SDLK_PAGEDOWN;
|
||||
+ keymap[ORB_KEY_INSERT] = SDLK_INSERT;
|
||||
+ keymap[ORB_KEY_DEL] = SDLK_DELETE;
|
||||
+}
|
||||
+
|
||||
+/* end of SDL_orbitalevents.c ... */
|
||||
diff -ruwN source/src/video/orbital/SDL_orbitalevents_c.h source-new/src/video/orbital/SDL_orbitalevents_c.h
|
||||
--- source/src/video/orbital/SDL_orbitalevents_c.h 1969-12-31 17:00:00.000000000 -0700
|
||||
+++ source-new/src/video/orbital/SDL_orbitalevents_c.h 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -0,0 +1,32 @@
|
||||
+/*
|
||||
+ SDL - Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2012 Sam Lantinga
|
||||
+
|
||||
+ This library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ This library 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
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with this library; if not, write to the Free Software
|
||||
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+ Sam Lantinga
|
||||
+ slouken@libsdl.org
|
||||
+*/
|
||||
+#include "SDL_config.h"
|
||||
+
|
||||
+#include "SDL_orbitalvideo.h"
|
||||
+
|
||||
+/* Variables and functions exported by SDL_sysevents.c to other parts
|
||||
+ of the native video subsystem (SDL_sysvideo.c)
|
||||
+*/
|
||||
+extern void ORBITAL_InitOSKeymap(_THIS);
|
||||
+extern void ORBITAL_PumpEvents(_THIS);
|
||||
+
|
||||
+/* end of SDL_orbitalevents_c.h ... */
|
||||
diff -ruwN source/src/video/orbital/SDL_orbitalmouse.c source-new/src/video/orbital/SDL_orbitalmouse.c
|
||||
--- source/src/video/orbital/SDL_orbitalmouse.c 1969-12-31 17:00:00.000000000 -0700
|
||||
+++ source-new/src/video/orbital/SDL_orbitalmouse.c 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -0,0 +1,33 @@
|
||||
+/*
|
||||
+ SDL - Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2012 Sam Lantinga
|
||||
+
|
||||
+ This library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ This library 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
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with this library; if not, write to the Free Software
|
||||
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+ Sam Lantinga
|
||||
+ slouken@libsdl.org
|
||||
+*/
|
||||
+#include "SDL_config.h"
|
||||
+
|
||||
+#include "SDL_mouse.h"
|
||||
+#include "../../events/SDL_events_c.h"
|
||||
+
|
||||
+#include "SDL_orbitalmouse_c.h"
|
||||
+
|
||||
+
|
||||
+/* The implementation dependent data for the window manager cursor */
|
||||
+struct WMcursor {
|
||||
+ int unused;
|
||||
+};
|
||||
diff -ruwN source/src/video/orbital/SDL_orbitalmouse_c.h source-new/src/video/orbital/SDL_orbitalmouse_c.h
|
||||
--- source/src/video/orbital/SDL_orbitalmouse_c.h 1969-12-31 17:00:00.000000000 -0700
|
||||
+++ source-new/src/video/orbital/SDL_orbitalmouse_c.h 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -0,0 +1,26 @@
|
||||
+/*
|
||||
+ SDL - Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2012 Sam Lantinga
|
||||
+
|
||||
+ This library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ This library 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
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with this library; if not, write to the Free Software
|
||||
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+ Sam Lantinga
|
||||
+ slouken@libsdl.org
|
||||
+*/
|
||||
+#include "SDL_config.h"
|
||||
+
|
||||
+#include "SDL_orbitalvideo.h"
|
||||
+
|
||||
+/* Functions to be exported */
|
||||
diff -ruwN source/src/video/orbital/SDL_orbitalvideo.c source-new/src/video/orbital/SDL_orbitalvideo.c
|
||||
--- source/src/video/orbital/SDL_orbitalvideo.c 1969-12-31 17:00:00.000000000 -0700
|
||||
+++ source-new/src/video/orbital/SDL_orbitalvideo.c 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -0,0 +1,182 @@
|
||||
+/*
|
||||
+ SDL - Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2012 Sam Lantinga
|
||||
+
|
||||
+ This library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ This library 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
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with this library; if not, write to the Free Software
|
||||
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+ Sam Lantinga
|
||||
+ slouken@libsdl.org
|
||||
+*/
|
||||
+#include "SDL_config.h"
|
||||
+
|
||||
+/* Orbital SDL video driver implementation
|
||||
+ *
|
||||
+ * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
|
||||
+ * of this was cut-and-pasted from Stephane Peter's work in the AAlib
|
||||
+ * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
|
||||
+ * Repurposed to ORBITAL by Jeremy Soller.
|
||||
+ */
|
||||
+
|
||||
+#include "SDL_video.h"
|
||||
+#include "SDL_mouse.h"
|
||||
+#include "../SDL_sysvideo.h"
|
||||
+#include "../SDL_pixels_c.h"
|
||||
+#include "../../events/SDL_events_c.h"
|
||||
+
|
||||
+#include <orbital.h>
|
||||
+#include "SDL_orbitalvideo.h"
|
||||
+#include "SDL_orbitalevents_c.h"
|
||||
+#include "SDL_orbitalmouse_c.h"
|
||||
+
|
||||
+#include <fcntl.h>
|
||||
+#include <sys/types.h>
|
||||
+#include <sys/stat.h>
|
||||
+#include <unistd.h>
|
||||
+
|
||||
+#define ORBITALVID_DRIVER_NAME "orbital"
|
||||
+
|
||||
+/* Initialization/Query functions */
|
||||
+static int ORBITAL_VideoInit(_THIS);
|
||||
+static void ORBITAL_VideoQuit(_THIS);
|
||||
+
|
||||
+/* ORBITAL driver bootstrap functions */
|
||||
+
|
||||
+static int ORBITAL_Available(void)
|
||||
+{
|
||||
+ return(1);
|
||||
+}
|
||||
+
|
||||
+static void ORBITAL_DeleteDevice(SDL_VideoDevice *device)
|
||||
+{
|
||||
+ SDL_free(device->hidden);
|
||||
+ SDL_free(device);
|
||||
+}
|
||||
+
|
||||
+static SDL_VideoDevice *ORBITAL_CreateDevice(int devindex)
|
||||
+{
|
||||
+ SDL_VideoDevice *device;
|
||||
+
|
||||
+ /* Initialize all variables that we clean on shutdown */
|
||||
+ device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
|
||||
+ if ( device ) {
|
||||
+ SDL_memset(device, 0, (sizeof *device));
|
||||
+ device->hidden = (struct SDL_PrivateVideoData *)
|
||||
+ SDL_malloc((sizeof *device->hidden));
|
||||
+ }
|
||||
+ if ( (device == NULL) || (device->hidden == NULL) ) {
|
||||
+ SDL_OutOfMemory();
|
||||
+ if ( device ) {
|
||||
+ SDL_free(device);
|
||||
+ }
|
||||
+ return(0);
|
||||
+ }
|
||||
+ SDL_memset(device->hidden, 0, (sizeof *device->hidden));
|
||||
+
|
||||
+ /* Set the function pointers */
|
||||
+ device->VideoInit = ORBITAL_VideoInit;
|
||||
+ device->VideoQuit = ORBITAL_VideoQuit;
|
||||
+ device->InitOSKeymap = ORBITAL_InitOSKeymap;
|
||||
+ device->PumpEvents = ORBITAL_PumpEvents;
|
||||
+
|
||||
+ device->free = ORBITAL_DeleteDevice;
|
||||
+
|
||||
+ return device;
|
||||
+}
|
||||
+
|
||||
+VideoBootStrap ORBITAL_bootstrap = {
|
||||
+ ORBITALVID_DRIVER_NAME, "SDL orbital video driver",
|
||||
+ ORBITAL_Available, ORBITAL_CreateDevice
|
||||
+};
|
||||
+
|
||||
+
|
||||
+int ORBITAL_VideoInit(_THIS)
|
||||
+{
|
||||
+ fprintf(stderr, "WARNING: You are using the SDL orbital video driver!\n");
|
||||
+
|
||||
+ /* We're done! */
|
||||
+ return(0);
|
||||
+}
|
||||
+
|
||||
+/* Note: If we are terminated, this could be called in the middle of
|
||||
+ another SDL video routine -- notably UpdateRects.
|
||||
+*/
|
||||
+void ORBITAL_VideoQuit(_THIS)
|
||||
+{
|
||||
+ if (this->hidden->window) {
|
||||
+ orb_window_destroy(this->hidden->window);
|
||||
+ this->hidden->window = NULL;
|
||||
+ this->screen->pixels = NULL;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+#if 0
|
||||
+SDL_Surface *ORBITAL_SetVideoMode(_THIS, SDL_Surface *current,
|
||||
+ int width, int height, int bpp, Uint32 flags)
|
||||
+{
|
||||
+ if ( bpp != 32 ) {
|
||||
+ SDL_SetError("Unsupported color depth - must use 32-bits per pixel");
|
||||
+ return(NULL);
|
||||
+ }
|
||||
+
|
||||
+ if (this->hidden->window) {
|
||||
+ orb_window_set_size(this->hidden->window, width, height);
|
||||
+ } else {
|
||||
+ uint32_t orb_flags = ORB_WINDOW_ASYNC;
|
||||
+ if (flags & SDL_RESIZABLE)
|
||||
+ orb_flags |= ORB_WINDOW_RESIZABLE;
|
||||
+
|
||||
+ this->hidden->window = orb_window_new_flags(-1, -1, width, height, "SDL", orb_flags);
|
||||
+ if (!this->hidden->window) {
|
||||
+ SDL_SetError("Couldn't create window for requested mode");
|
||||
+ return(NULL);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ fprintf(stderr, "Setting mode %dx%d@%d\n", width, height, bpp);
|
||||
+
|
||||
+ /* Allocate the new pixel format for the screen */
|
||||
+ if ( ! SDL_ReallocFormat(current, bpp, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000) ) {
|
||||
+ orb_window_destroy(this->hidden->window);
|
||||
+ this->hidden->window = NULL;
|
||||
+
|
||||
+ SDL_SetError("Couldn't allocate new pixel format for requested mode");
|
||||
+ return(NULL);
|
||||
+ }
|
||||
+
|
||||
+ /* Set up the new mode framebuffer */
|
||||
+ current->flags = flags /*& SDL_FULLSCREEN*/;
|
||||
+ current->w = width;
|
||||
+ current->h = height;
|
||||
+ current->pitch = width * (bpp / 8);
|
||||
+ current->pixels = orb_window_data(this->hidden->window);
|
||||
+
|
||||
+ /* We're done */
|
||||
+ return(current);
|
||||
+}
|
||||
+
|
||||
+static void ORBITAL_SetCaption(_THIS, const char *title, const char *icon)
|
||||
+{
|
||||
+ if (this->hidden->window)
|
||||
+ orb_window_set_title(this->hidden->window, title);
|
||||
+}
|
||||
+
|
||||
+static void ORBITAL_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
|
||||
+{
|
||||
+ if (this->hidden->window) {
|
||||
+ SDL_SetAlphaChannel(this->screen, SDL_ALPHA_OPAQUE);
|
||||
+ orb_window_sync(this->hidden->window);
|
||||
+ }
|
||||
+}
|
||||
+#endif
|
||||
diff -ruwN source/src/video/orbital/SDL_orbitalvideo.h source-new/src/video/orbital/SDL_orbitalvideo.h
|
||||
--- source/src/video/orbital/SDL_orbitalvideo.h 1969-12-31 17:00:00.000000000 -0700
|
||||
+++ source-new/src/video/orbital/SDL_orbitalvideo.h 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -0,0 +1,39 @@
|
||||
+/*
|
||||
+ SDL - Simple DirectMedia Layer
|
||||
+ Copyright (C) 1997-2012 Sam Lantinga
|
||||
+
|
||||
+ This library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ This library 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
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with this library; if not, write to the Free Software
|
||||
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+
|
||||
+ Sam Lantinga
|
||||
+ slouken@libsdl.org
|
||||
+*/
|
||||
+#include "SDL_config.h"
|
||||
+
|
||||
+#ifndef _SDL_orbitalvideo_h
|
||||
+#define _SDL_orbitalvideo_h
|
||||
+
|
||||
+#include "../SDL_sysvideo.h"
|
||||
+
|
||||
+/* Hidden "this" pointer for the video functions */
|
||||
+#define _THIS SDL_VideoDevice *this
|
||||
+
|
||||
+
|
||||
+/* Private display data */
|
||||
+
|
||||
+struct SDL_PrivateVideoData {
|
||||
+ void *window;
|
||||
+};
|
||||
+
|
||||
+#endif /* _SDL_orbitalvideo_h */
|
||||
diff -ruwN source/src/video/SDL_sysvideo.h source-new/src/video/SDL_sysvideo.h
|
||||
--- source/src/video/SDL_sysvideo.h 2018-10-31 09:07:22.000000000 -0600
|
||||
+++ source-new/src/video/SDL_sysvideo.h 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -416,6 +416,7 @@
|
||||
extern VideoBootStrap PSP_bootstrap;
|
||||
extern VideoBootStrap RPI_bootstrap;
|
||||
extern VideoBootStrap KMSDRM_bootstrap;
|
||||
+extern VideoBootStrap ORBITAL_bootstrap;
|
||||
extern VideoBootStrap DUMMY_bootstrap;
|
||||
extern VideoBootStrap Wayland_bootstrap;
|
||||
extern VideoBootStrap NACL_bootstrap;
|
||||
diff -ruwN source/src/video/SDL_video.c source-new/src/video/SDL_video.c
|
||||
--- source/src/video/SDL_video.c 2018-10-31 09:07:22.000000000 -0600
|
||||
+++ source-new/src/video/SDL_video.c 2018-12-31 14:01:08.740951021 -0700
|
||||
@@ -112,6 +112,9 @@
|
||||
#if SDL_VIDEO_DRIVER_QNX
|
||||
&QNX_bootstrap,
|
||||
#endif
|
||||
+#if SDL_VIDEO_DRIVER_ORBITAL
|
||||
+ &ORBITAL_bootstrap,
|
||||
+#endif
|
||||
#if SDL_VIDEO_DRIVER_DUMMY
|
||||
&DUMMY_bootstrap,
|
||||
#endif
|
||||
359
recipes/sdl2_gears/gears.c
Normal file
359
recipes/sdl2_gears/gears.c
Normal file
@ -0,0 +1,359 @@
|
||||
/* gears.c */
|
||||
|
||||
/*
|
||||
* 3-D gear wheels. This program is in the public domain.
|
||||
*
|
||||
* Brian Paul
|
||||
*/
|
||||
|
||||
/* Conversion to GLUT by Mark J. Kilgard */
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Draw a gear wheel. You'll probably want to call this function when
|
||||
building a display list since we do a lot of trig here.
|
||||
|
||||
Input: inner_radius - radius of hole at center
|
||||
outer_radius - radius at center of teeth
|
||||
width - width of gear
|
||||
teeth - number of teeth
|
||||
tooth_depth - depth of tooth
|
||||
|
||||
**/
|
||||
|
||||
static void
|
||||
gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
|
||||
GLint teeth, GLfloat tooth_depth)
|
||||
{
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth / 2.0;
|
||||
r2 = outer_radius + tooth_depth / 2.0;
|
||||
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
|
||||
/* draw front face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for (i = 0; i < teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f(0.0, 0.0, -1.0);
|
||||
|
||||
/* draw back face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for (i = 0; i < teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i < teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
u = r2 * cos(angle + da) - r1 * cos(angle);
|
||||
v = r2 * sin(angle + da) - r1 * sin(angle);
|
||||
len = sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
|
||||
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
}
|
||||
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glNormal3f(-cos(angle), -sin(angle), 0.0);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static int width = 800;
|
||||
static int height = 600;
|
||||
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_GLContext context = NULL;
|
||||
|
||||
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
|
||||
static GLint gear1, gear2, gear3;
|
||||
static GLfloat angle = 0.0;
|
||||
static GLfloat delta = 2.0f;
|
||||
|
||||
static void
|
||||
draw(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(view_rotx, 1.0, 0.0, 0.0);
|
||||
glRotatef(view_roty, 0.0, 1.0, 0.0);
|
||||
glRotatef(view_rotz, 0.0, 0.0, 1.0);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.0, -2.0, 0.0);
|
||||
glRotatef(angle, 0.0, 0.0, 1.0);
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(3.1, -2.0, 0.0);
|
||||
glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.1, 4.2, 0.0);
|
||||
glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glFinish();
|
||||
}
|
||||
|
||||
static void
|
||||
idle(void)
|
||||
{
|
||||
angle += delta;
|
||||
if (angle > 360.0f)
|
||||
angle -= 360.0f;
|
||||
|
||||
draw();
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
/* new window size or exposure */
|
||||
static void
|
||||
reshape(int width, int height)
|
||||
{
|
||||
GLfloat h = (GLfloat)height / (GLfloat)width;
|
||||
|
||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0, 0.0, -40.0);
|
||||
}
|
||||
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
static GLfloat pos[4] =
|
||||
{5.0, 5.0, 10.0, 0.0};
|
||||
static GLfloat red[4] =
|
||||
{0.8, 0.1, 0.0, 1.0};
|
||||
static GLfloat green[4] =
|
||||
{0.0, 0.8, 0.2, 1.0};
|
||||
static GLfloat blue[4] =
|
||||
{0.2, 0.2, 1.0, 1.0};
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(1.0, 4.0, 1.0, 20, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
|
||||
gear(0.5, 2.0, 2.0, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
gear(1.3, 2.0, 0.5, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
}
|
||||
|
||||
void CheckSDLError(int line)
|
||||
{
|
||||
const char* error = SDL_GetError();
|
||||
if (error != "")
|
||||
{
|
||||
printf("SLD Error: %s\n", error);
|
||||
|
||||
if (line != -1)
|
||||
printf("\nLine: %d\n", line);
|
||||
|
||||
SDL_ClearError();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("Initializing SDL\n");
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
{
|
||||
printf("Failed to init SDL\n");
|
||||
CheckSDLError(__LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Creating SDL window\n");
|
||||
window = SDL_CreateWindow(
|
||||
"Gears",
|
||||
-1,
|
||||
-1,
|
||||
width,
|
||||
height,
|
||||
SDL_WINDOW_OPENGL
|
||||
);
|
||||
if (window == NULL)
|
||||
{
|
||||
printf("Unable to create window\n");
|
||||
CheckSDLError(__LINE__);
|
||||
return -1;
|
||||
}
|
||||
printf("SDL window created %p\n", window);
|
||||
|
||||
printf("Creating SDL GL context\n");
|
||||
context = SDL_GL_CreateContext(window);
|
||||
if (context == NULL)
|
||||
{
|
||||
printf("Unable to create SDL GL context\n");
|
||||
CheckSDLError(__LINE__);
|
||||
return -1;
|
||||
}
|
||||
printf("SDL GL context created %p\n", context);
|
||||
|
||||
init();
|
||||
|
||||
reshape(width, height);
|
||||
|
||||
int running = 1;
|
||||
SDL_Event event;
|
||||
while (running)
|
||||
{
|
||||
idle();
|
||||
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
if (event.type == SDL_QUIT)
|
||||
running = 0;
|
||||
|
||||
if (event.type == SDL_KEYDOWN)
|
||||
{
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_a:
|
||||
delta += 1.0f;
|
||||
break;
|
||||
case SDLK_s:
|
||||
delta -= 1.0f;
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
running = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GL_DeleteContext(context);
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
// Shutdown SDL 2
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
42
recipes/sdl2_gears/recipe.sh
Normal file
42
recipes/sdl2_gears/recipe.sh
Normal file
@ -0,0 +1,42 @@
|
||||
BUILD_DEPENDS=(sdl2 liborbital llvm mesa mesa_glu zlib)
|
||||
|
||||
function recipe_version {
|
||||
printf "1.0.0"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_update {
|
||||
echo "skipping update"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_prepare {
|
||||
rm -rf source
|
||||
mkdir source
|
||||
cp gears.c source
|
||||
}
|
||||
|
||||
function recipe_build {
|
||||
sysroot="$(realpath ../sysroot)"
|
||||
set -x
|
||||
"${CXX}" -O2 -I "$sysroot/include" -L "$sysroot/lib" gears.c -o sdl2_gears -lSDL2 -lorbital $("${PKG_CONFIG}" --libs glu) -lglapi -lz
|
||||
set +x
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_test {
|
||||
echo "skipping test"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_clean {
|
||||
make clean
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_stage {
|
||||
dest="$(realpath $1)"
|
||||
mkdir -pv "$dest/bin"
|
||||
cp -v "sdl2_gears" "$dest/bin/sdl2_gears"
|
||||
skip=1
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user