ruby2d 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/README.md +7 -9
- data/assets/Rakefile +85 -0
- data/assets/include/SDL2/SDL.h +1 -1
- data/assets/include/SDL2/SDL_assert.h +1 -1
- data/assets/include/SDL2/SDL_atomic.h +20 -2
- data/assets/include/SDL2/SDL_audio.h +47 -14
- data/assets/include/SDL2/SDL_bits.h +10 -1
- data/assets/include/SDL2/SDL_blendmode.h +7 -7
- data/assets/include/SDL2/SDL_clipboard.h +1 -1
- data/assets/include/SDL2/SDL_config.h +24 -390
- data/assets/include/SDL2/SDL_config_android.h +178 -0
- data/assets/include/SDL2/SDL_config_iphoneos.h +201 -0
- data/assets/include/SDL2/SDL_config_macosx.h +240 -0
- data/assets/include/SDL2/SDL_config_minimal.h +85 -0
- data/assets/include/SDL2/SDL_config_os2.h +170 -0
- data/assets/include/SDL2/SDL_config_pandora.h +133 -0
- data/assets/include/SDL2/SDL_config_psp.h +164 -0
- data/assets/include/SDL2/SDL_config_windows.h +257 -0
- data/assets/include/SDL2/SDL_config_winrt.h +240 -0
- data/assets/include/SDL2/SDL_config_wiz.h +146 -0
- data/assets/include/SDL2/SDL_copying.h +20 -0
- data/assets/include/SDL2/SDL_cpuinfo.h +90 -8
- data/assets/include/SDL2/SDL_egl.h +1 -1
- data/assets/include/SDL2/SDL_endian.h +1 -1
- data/assets/include/SDL2/SDL_error.h +1 -1
- data/assets/include/SDL2/SDL_events.h +4 -1
- data/assets/include/SDL2/SDL_filesystem.h +1 -1
- data/assets/include/SDL2/SDL_gamecontroller.h +1 -1
- data/assets/include/SDL2/SDL_gesture.h +1 -1
- data/assets/include/SDL2/SDL_haptic.h +1 -1
- data/assets/include/SDL2/SDL_hints.h +145 -14
- data/assets/include/SDL2/SDL_image.h +2 -2
- data/assets/include/SDL2/SDL_joystick.h +1 -1
- data/assets/include/SDL2/SDL_keyboard.h +1 -1
- data/assets/include/SDL2/SDL_keycode.h +1 -1
- data/assets/include/SDL2/SDL_loadso.h +1 -1
- data/assets/include/SDL2/SDL_log.h +1 -1
- data/assets/include/SDL2/SDL_main.h +28 -16
- data/assets/include/SDL2/SDL_messagebox.h +1 -1
- data/assets/include/SDL2/SDL_mouse.h +1 -1
- data/assets/include/SDL2/SDL_mutex.h +1 -1
- data/assets/include/SDL2/SDL_name.h +1 -1
- data/assets/include/SDL2/SDL_opengl.h +1 -1
- data/assets/include/SDL2/SDL_opengles.h +1 -1
- data/assets/include/SDL2/SDL_opengles2.h +1 -1
- data/assets/include/SDL2/SDL_pixels.h +3 -3
- data/assets/include/SDL2/SDL_platform.h +1 -1
- data/assets/include/SDL2/SDL_power.h +1 -1
- data/assets/include/SDL2/SDL_quit.h +1 -1
- data/assets/include/SDL2/SDL_rect.h +29 -3
- data/assets/include/SDL2/SDL_render.h +168 -1
- data/assets/include/SDL2/SDL_revision.h +2 -2
- data/assets/include/SDL2/SDL_rwops.h +50 -13
- data/assets/include/SDL2/SDL_scancode.h +2 -2
- data/assets/include/SDL2/SDL_sensor.h +4 -4
- data/assets/include/SDL2/SDL_shape.h +1 -1
- data/assets/include/SDL2/SDL_stdinc.h +1 -1
- data/assets/include/SDL2/SDL_surface.h +2 -1
- data/assets/include/SDL2/SDL_system.h +1 -1
- data/assets/include/SDL2/SDL_syswm.h +11 -8
- data/assets/include/SDL2/SDL_test.h +1 -1
- data/assets/include/SDL2/SDL_test_assert.h +1 -1
- data/assets/include/SDL2/SDL_test_common.h +22 -5
- data/assets/include/SDL2/SDL_test_compare.h +1 -1
- data/assets/include/SDL2/SDL_test_crc32.h +1 -1
- data/assets/include/SDL2/SDL_test_font.h +1 -1
- data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
- data/assets/include/SDL2/SDL_test_harness.h +1 -1
- data/assets/include/SDL2/SDL_test_images.h +1 -1
- data/assets/include/SDL2/SDL_test_log.h +1 -1
- data/assets/include/SDL2/SDL_test_md5.h +1 -1
- data/assets/include/SDL2/SDL_test_memory.h +3 -3
- data/assets/include/SDL2/SDL_test_random.h +1 -1
- data/assets/include/SDL2/SDL_thread.h +1 -1
- data/assets/include/SDL2/SDL_timer.h +1 -1
- data/assets/include/SDL2/SDL_touch.h +17 -1
- data/assets/include/SDL2/SDL_types.h +1 -1
- data/assets/include/SDL2/SDL_version.h +2 -2
- data/assets/include/SDL2/SDL_video.h +1 -1
- data/assets/include/SDL2/SDL_vulkan.h +3 -3
- data/assets/include/SDL2/begin_code.h +4 -1
- data/assets/include/SDL2/close_code.h +4 -1
- data/assets/include/simple2d.h +22 -0
- data/assets/linux/simple2d/Makefile +11 -8
- data/assets/linux/simple2d/bin/simple2d.sh +13 -7
- data/assets/linux/simple2d/include/simple2d.h +22 -0
- data/assets/linux/simple2d/src/gl.c +17 -13
- data/assets/linux/simple2d/src/gl3.c +105 -32
- data/assets/linux/simple2d/src/sound.c +37 -0
- data/assets/linux/simple2d/src/window.c +11 -0
- data/assets/macos/lib/libFLAC.a +0 -0
- data/assets/macos/lib/libSDL2.a +0 -0
- data/assets/macos/lib/libSDL2_image.a +0 -0
- data/assets/macos/lib/libSDL2_mixer.a +0 -0
- data/assets/macos/lib/libSDL2_ttf.a +0 -0
- data/assets/macos/lib/libfreetype.a +0 -0
- data/assets/macos/lib/libjpeg.a +0 -0
- data/assets/macos/lib/libmpg123.a +0 -0
- data/assets/macos/lib/libogg.a +0 -0
- data/assets/macos/lib/libpng16.a +0 -0
- data/assets/macos/lib/libsimple2d.a +0 -0
- data/assets/macos/lib/libtiff.a +0 -0
- data/assets/macos/lib/libwebp.a +0 -0
- data/assets/mingw/bin/SDL2.dll +0 -0
- data/assets/mingw/bin/SDL2_image.dll +0 -0
- data/assets/mingw/bin/libpng16-16.dll +0 -0
- data/assets/mingw/bin/libtiff-5.dll +0 -0
- data/assets/mingw/bin/libwebp-7.dll +0 -0
- data/assets/mingw/lib/libSDL2.a +0 -0
- data/assets/mingw/lib/libSDL2.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_image.a +0 -0
- data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_test.a +0 -0
- data/assets/mingw/lib/libSDL2main.a +0 -0
- data/assets/mingw/lib/libsimple2d.a +0 -0
- data/ext/ruby2d/extconf.rb +1 -1
- data/lib/ruby2d/version.rb +1 -1
- metadata +14 -2
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
Simple DirectMedia Layer
|
3
|
-
Copyright (C) 1997-
|
3
|
+
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
4
4
|
|
5
5
|
This software is provided 'as-is', without any express or implied
|
6
6
|
warranty. In no event will the authors be held liable for any damages
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
Simple DirectMedia Layer
|
3
|
-
Copyright (C) 1997-
|
3
|
+
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
4
4
|
|
5
5
|
This software is provided 'as-is', without any express or implied
|
6
6
|
warranty. In no event will the authors be held liable for any damages
|
@@ -59,7 +59,7 @@ typedef struct SDL_version
|
|
59
59
|
*/
|
60
60
|
#define SDL_MAJOR_VERSION 2
|
61
61
|
#define SDL_MINOR_VERSION 0
|
62
|
-
#define SDL_PATCHLEVEL
|
62
|
+
#define SDL_PATCHLEVEL 10
|
63
63
|
|
64
64
|
/**
|
65
65
|
* \brief Macro to determine SDL version program was compiled against.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
Simple DirectMedia Layer
|
3
|
-
Copyright (C) 1997-
|
3
|
+
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
4
4
|
|
5
5
|
This software is provided 'as-is', without any express or implied
|
6
6
|
warranty. In no event will the authors be held liable for any damages
|
@@ -98,8 +98,8 @@ typedef VkSurfaceKHR SDL_vulkanSurface; /* for compatibility with Tizen */
|
|
98
98
|
* applications to link with libvulkan (and historically MoltenVK was
|
99
99
|
* provided as a static library). If it is not found then, on macOS, SDL
|
100
100
|
* will attempt to load \c vulkan.framework/vulkan, \c libvulkan.1.dylib,
|
101
|
-
*
|
102
|
-
* On iOS SDL will attempt to load \c
|
101
|
+
* followed by \c libvulkan.dylib, in that order.
|
102
|
+
* On iOS SDL will attempt to load \c libvulkan.dylib only. Applications
|
103
103
|
* using a dynamic framework or .dylib must ensure it is included in its
|
104
104
|
* application bundle.
|
105
105
|
*
|
@@ -153,7 +153,7 @@ extern DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
|
|
153
153
|
* is smaller than the number of required extensions, \c SDL_FALSE will be
|
154
154
|
* returned instead of \c SDL_TRUE, to indicate that not all the required
|
155
155
|
* extensions were returned.
|
156
|
-
*
|
156
|
+
*
|
157
157
|
* \note If \c window is not NULL, it will be checked against its creation
|
158
158
|
* flags to ensure that the Vulkan flag is present. This parameter
|
159
159
|
* will be removed in a future major release.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
Simple DirectMedia Layer
|
3
|
-
Copyright (C) 1997-
|
3
|
+
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
4
4
|
|
5
5
|
This software is provided 'as-is', without any express or implied
|
6
6
|
warranty. In no event will the authors be held liable for any damages
|
@@ -105,6 +105,9 @@
|
|
105
105
|
#ifdef _MSC_VER
|
106
106
|
#pragma warning(disable: 4103)
|
107
107
|
#endif
|
108
|
+
#ifdef __clang__
|
109
|
+
#pragma clang diagnostic ignored "-Wpragma-pack"
|
110
|
+
#endif
|
108
111
|
#ifdef __BORLANDC__
|
109
112
|
#pragma nopackwarning
|
110
113
|
#endif
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
Simple DirectMedia Layer
|
3
|
-
Copyright (C) 1997-
|
3
|
+
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
4
4
|
|
5
5
|
This software is provided 'as-is', without any express or implied
|
6
6
|
warranty. In no event will the authors be held liable for any damages
|
@@ -26,6 +26,9 @@
|
|
26
26
|
* after you finish any function and structure declarations in your headers
|
27
27
|
*/
|
28
28
|
|
29
|
+
#ifndef _begin_code_h
|
30
|
+
#error close_code.h included without matching begin_code.h
|
31
|
+
#endif
|
29
32
|
#undef _begin_code_h
|
30
33
|
|
31
34
|
/* Reset structure packing at previous byte alignment */
|
data/assets/include/simple2d.h
CHANGED
@@ -536,6 +536,26 @@ S2D_Sound *S2D_CreateSound(const char *path);
|
|
536
536
|
*/
|
537
537
|
void S2D_PlaySound(S2D_Sound *snd);
|
538
538
|
|
539
|
+
/*
|
540
|
+
* Get the sound's volume
|
541
|
+
*/
|
542
|
+
int S2D_GetSoundVolume(S2D_Sound *snd);
|
543
|
+
|
544
|
+
/*
|
545
|
+
* Set the sound's volume a given percentage
|
546
|
+
*/
|
547
|
+
void S2D_SetSoundVolume(S2D_Sound *snd, int volume);
|
548
|
+
|
549
|
+
/*
|
550
|
+
* Get the sound mixer volume
|
551
|
+
*/
|
552
|
+
int S2D_GetSoundMixVolume();
|
553
|
+
|
554
|
+
/*
|
555
|
+
* Set the sound mixer volume a given percentage
|
556
|
+
*/
|
557
|
+
void S2D_SetSoundMixVolume(int volume);
|
558
|
+
|
539
559
|
/*
|
540
560
|
* Free the sound
|
541
561
|
*/
|
@@ -687,6 +707,7 @@ void S2D_GL_DrawSprite(S2D_Sprite *spr);
|
|
687
707
|
void S2D_GL_DrawText(S2D_Text *txt);
|
688
708
|
void S2D_GL_FreeTexture(GLuint *id);
|
689
709
|
void S2D_GL_Clear(S2D_Color clr);
|
710
|
+
void S2D_GL_FlushBuffers();
|
690
711
|
|
691
712
|
// OpenGL & GLES Internal Functions ////////////////////////////////////////////
|
692
713
|
|
@@ -728,6 +749,7 @@ void S2D_GL_Clear(S2D_Color clr);
|
|
728
749
|
void S2D_GL3_DrawSprite(S2D_Sprite *spr);
|
729
750
|
void S2D_GL2_DrawText(S2D_Text *txt);
|
730
751
|
void S2D_GL3_DrawText(S2D_Text *txt);
|
752
|
+
void S2D_GL3_FlushBuffers();
|
731
753
|
#endif
|
732
754
|
|
733
755
|
#ifdef __cplusplus
|
@@ -46,7 +46,7 @@ OBJECTS=$(addprefix build/,$(notdir $(SOURCES:.c=.o)))
|
|
46
46
|
VERSION=$(shell bash bin/simple2d.sh -v)
|
47
47
|
|
48
48
|
# Release directories and archive filenames
|
49
|
-
APPLE_RELEASE=simple2d-apple
|
49
|
+
APPLE_RELEASE=simple2d-apple-$(VERSION)
|
50
50
|
MINGW_RELEASE=simple2d-windows-mingw-$(VERSION)
|
51
51
|
|
52
52
|
# Helper functions
|
@@ -124,8 +124,8 @@ endif
|
|
124
124
|
mkdir -p build/tvos/Simple2D.framework/Headers
|
125
125
|
cp include/simple2d.h build/ios/Simple2D.framework/Headers
|
126
126
|
cp include/simple2d.h build/tvos/Simple2D.framework/Headers
|
127
|
-
cp -R deps/
|
128
|
-
cp -R deps/
|
127
|
+
cp -R deps/headers/SDL2 build/ios/Simple2D.framework/Headers
|
128
|
+
cp -R deps/headers/SDL2 build/tvos/Simple2D.framework/Headers
|
129
129
|
cp deps/xcode/Info.plist build/ios/Simple2D.framework/Info.plist
|
130
130
|
cp deps/xcode/Info.plist build/tvos/Simple2D.framework/Info.plist
|
131
131
|
mv build/ios/Simple2D build/ios/Simple2D.framework
|
@@ -148,13 +148,16 @@ endif
|
|
148
148
|
|
149
149
|
ifeq ($(PLATFORM),apple)
|
150
150
|
release: clean frameworks
|
151
|
+
$(call task_msg,Building macOS release)
|
152
|
+
mkdir -p build/$(APPLE_RELEASE)/macOS
|
153
|
+
cp build/libsimple2d.a build/$(APPLE_RELEASE)/macOS
|
151
154
|
$(call task_msg,Building iOS and tvOS release)
|
152
|
-
mkdir -p build/$(APPLE_RELEASE)/
|
153
|
-
mkdir -p build/$(APPLE_RELEASE)/
|
154
|
-
cp -R build/ios/* build/$(APPLE_RELEASE)/
|
155
|
-
cp -R build/tvos/* build/$(APPLE_RELEASE)/
|
155
|
+
mkdir -p build/$(APPLE_RELEASE)/iOS
|
156
|
+
mkdir -p build/$(APPLE_RELEASE)/tvOS
|
157
|
+
cp -R build/ios/* build/$(APPLE_RELEASE)/iOS/
|
158
|
+
cp -R build/tvos/* build/$(APPLE_RELEASE)/tvOS/
|
156
159
|
cd build; zip -rq $(APPLE_RELEASE).zip $(APPLE_RELEASE)
|
157
|
-
$(call info_msg,
|
160
|
+
$(call info_msg,Apple release zipped at \`build/$(APPLE_RELEASE).zip\`)
|
158
161
|
endif
|
159
162
|
|
160
163
|
ifeq ($(PLATFORM),mingw)
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# Set Constants ################################################################
|
13
13
|
|
14
14
|
# The installed version
|
15
|
-
VERSION='1.
|
15
|
+
VERSION='1.2.0'
|
16
16
|
|
17
17
|
# URL to this script in the repo
|
18
18
|
SCRIPT_URL="https://raw.githubusercontent.com/simple2d/simple2d/master/bin/simple2d.sh"
|
@@ -27,16 +27,16 @@ SDL_MIN_VERSION='2.0.4'
|
|
27
27
|
# SDL download paths
|
28
28
|
libsdl_url="https://www.libsdl.org"
|
29
29
|
|
30
|
-
sdl_fname="SDL2-2.0.
|
30
|
+
sdl_fname="SDL2-2.0.10"
|
31
31
|
sdl_url="${libsdl_url}/release/${sdl_fname}.tar.gz"
|
32
32
|
|
33
|
-
image_fname="SDL2_image-2.0.
|
33
|
+
image_fname="SDL2_image-2.0.5"
|
34
34
|
image_url="${libsdl_url}/projects/SDL_image/release/${image_fname}.tar.gz"
|
35
35
|
|
36
36
|
mixer_fname="SDL2_mixer-2.0.4"
|
37
37
|
mixer_url="${libsdl_url}/projects/SDL_mixer/release/${mixer_fname}.tar.gz"
|
38
38
|
|
39
|
-
ttf_fname="SDL2_ttf-2.0.
|
39
|
+
ttf_fname="SDL2_ttf-2.0.15"
|
40
40
|
ttf_url="${libsdl_url}/projects/SDL_ttf/release/${ttf_fname}.tar.gz"
|
41
41
|
|
42
42
|
# SDL config
|
@@ -202,14 +202,20 @@ build() {
|
|
202
202
|
# If no input, print build usage
|
203
203
|
if [[ $1 == '' ]]; then print_usage_build; exit; fi
|
204
204
|
|
205
|
-
# If C
|
206
|
-
|
207
|
-
if [[ ${1: -2} == '.c' || ${1: -4} == '.cpp' ]]; then
|
205
|
+
# If C source file given, e.g.: build app.c
|
206
|
+
if [[ ${1: -2} == '.c' ]]; then
|
208
207
|
# Compile
|
209
208
|
gcc -std=c11 $1 `simple2d --libs` -o ${1%.*}
|
210
209
|
exit
|
211
210
|
fi
|
212
211
|
|
212
|
+
# If C++ source file given, e.g.: build app.cpp
|
213
|
+
if [[ ${1: -4} == '.cpp' ]]; then
|
214
|
+
# Compile
|
215
|
+
g++ -std=c++11 $1 `simple2d --libs` -o ${1%.*}
|
216
|
+
exit
|
217
|
+
fi
|
218
|
+
|
213
219
|
# Check if current directory has an Xcode project
|
214
220
|
has_xcodeproj?() {
|
215
221
|
if [[ $(ls *.xcodeproj 2>/dev/null) ]]; then
|
@@ -536,6 +536,26 @@ S2D_Sound *S2D_CreateSound(const char *path);
|
|
536
536
|
*/
|
537
537
|
void S2D_PlaySound(S2D_Sound *snd);
|
538
538
|
|
539
|
+
/*
|
540
|
+
* Get the sound's volume
|
541
|
+
*/
|
542
|
+
int S2D_GetSoundVolume(S2D_Sound *snd);
|
543
|
+
|
544
|
+
/*
|
545
|
+
* Set the sound's volume a given percentage
|
546
|
+
*/
|
547
|
+
void S2D_SetSoundVolume(S2D_Sound *snd, int volume);
|
548
|
+
|
549
|
+
/*
|
550
|
+
* Get the sound mixer volume
|
551
|
+
*/
|
552
|
+
int S2D_GetSoundMixVolume();
|
553
|
+
|
554
|
+
/*
|
555
|
+
* Set the sound mixer volume a given percentage
|
556
|
+
*/
|
557
|
+
void S2D_SetSoundMixVolume(int volume);
|
558
|
+
|
539
559
|
/*
|
540
560
|
* Free the sound
|
541
561
|
*/
|
@@ -687,6 +707,7 @@ void S2D_GL_DrawSprite(S2D_Sprite *spr);
|
|
687
707
|
void S2D_GL_DrawText(S2D_Text *txt);
|
688
708
|
void S2D_GL_FreeTexture(GLuint *id);
|
689
709
|
void S2D_GL_Clear(S2D_Color clr);
|
710
|
+
void S2D_GL_FlushBuffers();
|
690
711
|
|
691
712
|
// OpenGL & GLES Internal Functions ////////////////////////////////////////////
|
692
713
|
|
@@ -728,6 +749,7 @@ void S2D_GL_Clear(S2D_Color clr);
|
|
728
749
|
void S2D_GL3_DrawSprite(S2D_Sprite *spr);
|
729
750
|
void S2D_GL2_DrawText(S2D_Text *txt);
|
730
751
|
void S2D_GL3_DrawText(S2D_Text *txt);
|
752
|
+
void S2D_GL3_FlushBuffers();
|
731
753
|
#endif
|
732
754
|
|
733
755
|
#ifdef __cplusplus
|
@@ -47,6 +47,7 @@ void S2D_GL_PrintContextInfo(S2D_Window *window) {
|
|
47
47
|
* Store info about the current OpenGL context
|
48
48
|
*/
|
49
49
|
void S2D_GL_StoreContextInfo(S2D_Window *window) {
|
50
|
+
|
50
51
|
window->S2D_GL_VENDOR = glGetString(GL_VENDOR);
|
51
52
|
window->S2D_GL_RENDERER = glGetString(GL_RENDERER);
|
52
53
|
window->S2D_GL_VERSION = glGetString(GL_VERSION);
|
@@ -70,11 +71,8 @@ void S2D_GL_StoreContextInfo(S2D_Window *window) {
|
|
70
71
|
*/
|
71
72
|
GLuint S2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName) {
|
72
73
|
|
73
|
-
GLuint shader;
|
74
|
-
GLint compiled;
|
75
|
-
|
76
74
|
// Create the shader object
|
77
|
-
shader = glCreateShader(type);
|
75
|
+
GLuint shader = glCreateShader(type);
|
78
76
|
|
79
77
|
if (shader == 0) {
|
80
78
|
S2D_GL_PrintError("Failed to create shader program");
|
@@ -88,21 +86,17 @@ GLuint S2D_GL_LoadShader(GLenum type, const GLchar *shaderSrc, char *shaderName)
|
|
88
86
|
glCompileShader(shader);
|
89
87
|
|
90
88
|
// Check the compile status
|
89
|
+
GLint compiled;
|
91
90
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
92
91
|
|
93
92
|
if (!compiled) {
|
94
|
-
|
95
93
|
GLint infoLen = 0;
|
96
|
-
|
97
94
|
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
|
98
95
|
|
99
96
|
if (infoLen > 1) {
|
100
|
-
|
101
97
|
char *infoLog = malloc(sizeof(char) * infoLen);
|
102
|
-
|
103
98
|
glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
|
104
99
|
printf("Error compiling shader \"%s\":\n%s\n", shaderName, infoLog);
|
105
|
-
|
106
100
|
free(infoLog);
|
107
101
|
}
|
108
102
|
|
@@ -123,17 +117,13 @@ int S2D_GL_CheckLinked(GLuint program, char *name) {
|
|
123
117
|
glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
124
118
|
|
125
119
|
if (!linked) {
|
126
|
-
|
127
120
|
GLint infoLen = 0;
|
128
121
|
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen);
|
129
122
|
|
130
123
|
if (infoLen > 1) {
|
131
|
-
|
132
124
|
char *infoLog = malloc(sizeof(char) * infoLen);
|
133
|
-
|
134
125
|
glGetProgramInfoLog(program, infoLen, NULL, infoLog);
|
135
126
|
printf("Error linking program `%s`: %s\n", name, infoLog);
|
136
|
-
|
137
127
|
free(infoLog);
|
138
128
|
}
|
139
129
|
|
@@ -231,6 +221,7 @@ int S2D_GL_Init(S2D_Window *window) {
|
|
231
221
|
if (FORCE_GL2) {
|
232
222
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
233
223
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
224
|
+
|
234
225
|
// Request an OpenGL 3.3 forward-compatible core profile
|
235
226
|
} else {
|
236
227
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
@@ -417,6 +408,19 @@ void S2D_GL_DrawText(S2D_Text *txt) {
|
|
417
408
|
}
|
418
409
|
|
419
410
|
|
411
|
+
/*
|
412
|
+
* Render and flush OpenGL buffers
|
413
|
+
*/
|
414
|
+
void S2D_GL_FlushBuffers() {
|
415
|
+
// Only implemented in our OpenGL 3.3+ and ES 2.0 renderers
|
416
|
+
#if GLES
|
417
|
+
// TODO: S2D_GLES_FlushBuffers();
|
418
|
+
#else
|
419
|
+
if (!S2D_GL2) S2D_GL3_FlushBuffers();
|
420
|
+
#endif
|
421
|
+
}
|
422
|
+
|
423
|
+
|
420
424
|
/*
|
421
425
|
* Clear buffers to given color values
|
422
426
|
*/
|
@@ -1,12 +1,19 @@
|
|
1
|
-
// OpenGL 3.3
|
1
|
+
// OpenGL 3.3+
|
2
2
|
|
3
3
|
#include "../include/simple2d.h"
|
4
4
|
|
5
|
+
// Skip this file if OpenGL ES
|
5
6
|
#if !GLES
|
6
7
|
|
7
|
-
static GLuint
|
8
|
-
static GLuint
|
9
|
-
static
|
8
|
+
static GLuint vbo; // our primary vertex buffer object (VBO)
|
9
|
+
static GLuint vboSize; // size of the VBO in bytes
|
10
|
+
static GLfloat *vboData; // pointer to the VBO data
|
11
|
+
static GLfloat *vboDataCurrent; // pointer to the data for the current vertices
|
12
|
+
static GLuint vboDataIndex = 0; // index of the current object being rendered
|
13
|
+
static GLuint vboObjCapacity = 2500; // number of objects the VBO can store
|
14
|
+
static GLuint shaderProgram; // triangle shader program
|
15
|
+
static GLuint texShaderProgram; // texture shader program
|
16
|
+
static GLuint indices[] = // indices for rendering textured quads
|
10
17
|
{ 0, 1, 2,
|
11
18
|
2, 3, 0 };
|
12
19
|
|
@@ -19,6 +26,7 @@ void S2D_GL3_ApplyProjection(GLfloat orthoMatrix[16]) {
|
|
19
26
|
// Use the program object
|
20
27
|
glUseProgram(shaderProgram);
|
21
28
|
|
29
|
+
// Apply the projection matrix to the triangle shader
|
22
30
|
glUniformMatrix4fv(
|
23
31
|
glGetUniformLocation(shaderProgram, "u_mvpMatrix"),
|
24
32
|
1, GL_FALSE, orthoMatrix
|
@@ -27,6 +35,7 @@ void S2D_GL3_ApplyProjection(GLfloat orthoMatrix[16]) {
|
|
27
35
|
// Use the texture program object
|
28
36
|
glUseProgram(texShaderProgram);
|
29
37
|
|
38
|
+
// Apply the projection matrix to the texture shader
|
30
39
|
glUniformMatrix4fv(
|
31
40
|
glGetUniformLocation(texShaderProgram, "u_mvpMatrix"),
|
32
41
|
1, GL_FALSE, orthoMatrix
|
@@ -45,50 +54,63 @@ int S2D_GL3_Init() {
|
|
45
54
|
|
46
55
|
// Vertex shader source string
|
47
56
|
GLchar vertexSource[] =
|
48
|
-
"#version 150 core\n"
|
49
|
-
|
50
|
-
"
|
51
|
-
|
52
|
-
|
53
|
-
"
|
54
|
-
"
|
57
|
+
"#version 150 core\n" // shader version
|
58
|
+
|
59
|
+
"uniform mat4 u_mvpMatrix;" // projection matrix
|
60
|
+
|
61
|
+
// Input attributes to the vertex shader
|
62
|
+
"in vec4 position;" // position value
|
63
|
+
"in vec4 color;" // vertex color
|
64
|
+
"in vec2 texcoord;" // texture coordinates
|
65
|
+
|
66
|
+
// Outputs to the fragment shader
|
67
|
+
"out vec4 Color;" // vertex color
|
68
|
+
"out vec2 Texcoord;" // texture coordinates
|
69
|
+
|
55
70
|
"void main() {"
|
71
|
+
// Send the color and texture coordinates right through to the fragment shader
|
56
72
|
" Color = color;"
|
57
73
|
" Texcoord = texcoord;"
|
74
|
+
// Transform the vertex position using the projection matrix
|
58
75
|
" gl_Position = u_mvpMatrix * position;"
|
59
76
|
"}";
|
60
77
|
|
61
78
|
// Fragment shader source string
|
62
79
|
GLchar fragmentSource[] =
|
63
|
-
"#version 150 core\n"
|
64
|
-
"in vec4 Color;"
|
65
|
-
"out vec4 outColor;"
|
80
|
+
"#version 150 core\n" // shader version
|
81
|
+
"in vec4 Color;" // input color from vertex shader
|
82
|
+
"out vec4 outColor;" // output fragment color
|
83
|
+
|
66
84
|
"void main() {"
|
67
|
-
" outColor = Color;"
|
85
|
+
" outColor = Color;" // pass the color right through
|
68
86
|
"}";
|
69
87
|
|
70
88
|
// Fragment shader source string for textures
|
71
89
|
GLchar texFragmentSource[] =
|
72
|
-
"#version 150 core\n"
|
73
|
-
"in vec4 Color;"
|
74
|
-
"in vec2 Texcoord;"
|
75
|
-
"out vec4 outColor;"
|
76
|
-
"uniform sampler2D tex;"
|
90
|
+
"#version 150 core\n" // shader version
|
91
|
+
"in vec4 Color;" // input color from vertex shader
|
92
|
+
"in vec2 Texcoord;" // input texture coordinates
|
93
|
+
"out vec4 outColor;" // output fragment color
|
94
|
+
"uniform sampler2D tex;" // 2D texture unit
|
95
|
+
|
77
96
|
"void main() {"
|
97
|
+
// Apply the texture unit, texture coordinates, and color
|
78
98
|
" outColor = texture(tex, Texcoord) * Color;"
|
79
99
|
"}";
|
80
100
|
|
81
|
-
// Create
|
101
|
+
// Create a vertex array object
|
82
102
|
GLuint vao;
|
83
103
|
glGenVertexArrays(1, &vao);
|
84
104
|
glBindVertexArray(vao);
|
85
105
|
|
86
|
-
// Create
|
87
|
-
GLuint vbo;
|
106
|
+
// Create a vertex buffer object and allocate data
|
88
107
|
glGenBuffers(1, &vbo);
|
89
108
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
109
|
+
vboSize = vboObjCapacity * sizeof(GLfloat) * 24;
|
110
|
+
vboData = (GLfloat *) malloc(vboSize);
|
111
|
+
vboDataCurrent = vboData;
|
90
112
|
|
91
|
-
// Create an element
|
113
|
+
// Create an element buffer object
|
92
114
|
GLuint ebo;
|
93
115
|
glGenBuffers(1, &ebo);
|
94
116
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
@@ -98,6 +120,8 @@ int S2D_GL3_Init() {
|
|
98
120
|
GLuint fragmentShader = S2D_GL_LoadShader(GL_FRAGMENT_SHADER, fragmentSource, "GL3 Fragment");
|
99
121
|
GLuint texFragmentShader = S2D_GL_LoadShader(GL_FRAGMENT_SHADER, texFragmentSource, "GL3 Texture Fragment");
|
100
122
|
|
123
|
+
// Triangle Shader //
|
124
|
+
|
101
125
|
// Create the shader program object
|
102
126
|
shaderProgram = glCreateProgram();
|
103
127
|
|
@@ -111,7 +135,7 @@ int S2D_GL3_Init() {
|
|
111
135
|
glAttachShader(shaderProgram, vertexShader);
|
112
136
|
glAttachShader(shaderProgram, fragmentShader);
|
113
137
|
|
114
|
-
// Bind the
|
138
|
+
// Bind the output color variable to the fragment shader color number
|
115
139
|
glBindFragDataLocation(shaderProgram, 0, "outColor");
|
116
140
|
|
117
141
|
// Link the shader program
|
@@ -120,14 +144,17 @@ int S2D_GL3_Init() {
|
|
120
144
|
// Check if linked
|
121
145
|
S2D_GL_CheckLinked(shaderProgram, "GL3 shader");
|
122
146
|
|
123
|
-
// Specify the layout of the vertex data
|
147
|
+
// Specify the layout of the position vertex data...
|
124
148
|
GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
|
125
|
-
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0);
|
126
149
|
glEnableVertexAttribArray(posAttrib);
|
150
|
+
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0);
|
127
151
|
|
152
|
+
// ...and the color vertex data
|
128
153
|
GLint colAttrib = glGetAttribLocation(shaderProgram, "color");
|
129
|
-
glVertexAttribPointer(colAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));
|
130
154
|
glEnableVertexAttribArray(colAttrib);
|
155
|
+
glVertexAttribPointer(colAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));
|
156
|
+
|
157
|
+
// Texture Shader //
|
131
158
|
|
132
159
|
// Create the texture shader program object
|
133
160
|
texShaderProgram = glCreateProgram();
|
@@ -138,25 +165,30 @@ int S2D_GL3_Init() {
|
|
138
165
|
return GL_FALSE;
|
139
166
|
}
|
140
167
|
|
168
|
+
// Attach the shader objects to the program object
|
141
169
|
glAttachShader(texShaderProgram, vertexShader);
|
142
170
|
glAttachShader(texShaderProgram, texFragmentShader);
|
143
171
|
|
172
|
+
// Bind the output color variable to the fragment shader color number
|
144
173
|
glBindFragDataLocation(texShaderProgram, 0, "outColor");
|
145
174
|
|
175
|
+
// Link the shader program
|
146
176
|
glLinkProgram(texShaderProgram);
|
147
177
|
|
148
178
|
// Check if linked
|
149
179
|
S2D_GL_CheckLinked(texShaderProgram, "GL3 texture shader");
|
150
180
|
|
151
|
-
// Specify the layout of the vertex data
|
181
|
+
// Specify the layout of the position vertex data...
|
152
182
|
posAttrib = glGetAttribLocation(texShaderProgram, "position");
|
153
183
|
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0);
|
154
184
|
glEnableVertexAttribArray(posAttrib);
|
155
185
|
|
186
|
+
// ...and the color vertex data...
|
156
187
|
colAttrib = glGetAttribLocation(texShaderProgram, "color");
|
157
188
|
glVertexAttribPointer(colAttrib, 4, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));
|
158
189
|
glEnableVertexAttribArray(colAttrib);
|
159
190
|
|
191
|
+
// ...and the texture coordinates
|
160
192
|
GLint texAttrib = glGetAttribLocation(texShaderProgram, "texcoord");
|
161
193
|
glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (void*)(6 * sizeof(GLfloat)));
|
162
194
|
glEnableVertexAttribArray(texAttrib);
|
@@ -166,10 +198,33 @@ int S2D_GL3_Init() {
|
|
166
198
|
glDeleteShader(fragmentShader);
|
167
199
|
glDeleteShader(texFragmentShader);
|
168
200
|
|
201
|
+
// If successful, return true
|
169
202
|
return GL_TRUE;
|
170
203
|
}
|
171
204
|
|
172
205
|
|
206
|
+
/*
|
207
|
+
* Render the vertex buffer and reset it
|
208
|
+
*/
|
209
|
+
void S2D_GL3_FlushBuffers() {
|
210
|
+
|
211
|
+
// Use the triangle shader program
|
212
|
+
glUseProgram(shaderProgram);
|
213
|
+
|
214
|
+
// Bind to the vertex buffer object and update its data
|
215
|
+
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
216
|
+
glBufferData(GL_ARRAY_BUFFER, vboSize, NULL, GL_DYNAMIC_DRAW);
|
217
|
+
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLfloat) * vboDataIndex * 24, vboData);
|
218
|
+
|
219
|
+
// Render all the triangles in the buffer
|
220
|
+
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)(vboDataIndex * 3));
|
221
|
+
|
222
|
+
// Reset the buffer object index and data pointer
|
223
|
+
vboDataIndex = 0;
|
224
|
+
vboDataCurrent = vboData;
|
225
|
+
}
|
226
|
+
|
227
|
+
|
173
228
|
/*
|
174
229
|
* Draw triangle
|
175
230
|
*/
|
@@ -180,14 +235,21 @@ void S2D_GL3_DrawTriangle(GLfloat x1, GLfloat y1,
|
|
180
235
|
GLfloat x3, GLfloat y3,
|
181
236
|
GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3) {
|
182
237
|
|
238
|
+
// If buffer is full, flush it
|
239
|
+
if (vboDataIndex >= vboObjCapacity) S2D_GL3_FlushBuffers();
|
240
|
+
|
241
|
+
// Set the triangle data into a formatted array
|
183
242
|
GLfloat vertices[] =
|
184
243
|
{ x1, y1, r1, g1, b1, a1, 0, 0,
|
185
244
|
x2, y2, r2, g2, b2, a2, 0, 0,
|
186
245
|
x3, y3, r3, g3, b3, a3, 0, 0 };
|
187
246
|
|
188
|
-
|
189
|
-
|
190
|
-
|
247
|
+
// Copy the vertex data into the current position of the buffer
|
248
|
+
memcpy(vboDataCurrent, vertices, sizeof(vertices));
|
249
|
+
|
250
|
+
// Increment the buffer object index and the vertex data pointer for next use
|
251
|
+
vboDataIndex++;
|
252
|
+
vboDataCurrent = (GLfloat *)((char *)vboDataCurrent + (sizeof(GLfloat) * 24));
|
191
253
|
}
|
192
254
|
|
193
255
|
|
@@ -201,6 +263,11 @@ static void S2D_GL3_DrawTexture(int x, int y, int w, int h,
|
|
201
263
|
GLfloat tx3, GLfloat ty3, GLfloat tx4, GLfloat ty4,
|
202
264
|
GLuint texture_id) {
|
203
265
|
|
266
|
+
// Currently, textures are not buffered, so we have to flush all buffers so
|
267
|
+
// textures get rendered in the correct Z order
|
268
|
+
S2D_GL3_FlushBuffers();
|
269
|
+
|
270
|
+
// Set up the vertex points
|
204
271
|
S2D_GL_Point v1 = { .x = x, .y = y };
|
205
272
|
S2D_GL_Point v2 = { .x = x + w, .y = y };
|
206
273
|
S2D_GL_Point v3 = { .x = x + w, .y = y + h };
|
@@ -214,6 +281,7 @@ static void S2D_GL3_DrawTexture(int x, int y, int w, int h,
|
|
214
281
|
v4 = S2D_RotatePoint(v4, angle, rx, ry);
|
215
282
|
}
|
216
283
|
|
284
|
+
// Set the textured quad data into a formatted array
|
217
285
|
GLfloat vertices[] =
|
218
286
|
// vertex coords | colors | x, y texture coords
|
219
287
|
{ v1.x, v1.y, r, g, b, a, tx1, ty1, // Top-left
|
@@ -221,12 +289,17 @@ static void S2D_GL3_DrawTexture(int x, int y, int w, int h,
|
|
221
289
|
v3.x, v3.y, r, g, b, a, tx3, ty3, // Bottom-right
|
222
290
|
v4.x, v4.y, r, g, b, a, tx4, ty4 }; // Bottom-left
|
223
291
|
|
292
|
+
// Use the texture shader program
|
224
293
|
glUseProgram(texShaderProgram);
|
294
|
+
|
295
|
+
// Bind the texture using the provided ID
|
225
296
|
glBindTexture(GL_TEXTURE_2D, texture_id);
|
226
297
|
|
298
|
+
// Create and Initialize the vertex data and array indices
|
227
299
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
228
300
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
|
229
301
|
|
302
|
+
// Render the textured quad
|
230
303
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
231
304
|
}
|
232
305
|
|