rubygl 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +13 -5
  2. data/.travis/push-rdoc-to-gh-pages.sh +22 -0
  3. data/.travis.yml +18 -0
  4. data/Gemfile +7 -0
  5. data/Gemfile.lock +12 -0
  6. data/LICENSE +21 -21
  7. data/README.md +40 -0
  8. data/Rakefile +98 -83
  9. data/bin/ffi_code_gen.rb +166 -166
  10. data/bin/gl_code_gen.rb +458 -458
  11. data/examples/faceted_example.rb +71 -64
  12. data/examples/instanced_example.rb +135 -127
  13. data/examples/phong_example.rb +80 -71
  14. data/ext/windows/RubyGL.so +0 -0
  15. data/lib/rubygl/event.rb +64 -0
  16. data/lib/{RubyGL → rubygl}/geometry.rb +216 -211
  17. data/lib/{RubyGL → rubygl}/math.rb +300 -300
  18. data/lib/{RubyGL → rubygl}/memory.rb +125 -121
  19. data/lib/rubygl/native/all_enums.rb +641 -0
  20. data/lib/{RubyGL/Native → rubygl/native}/glcontext.rb +23 -47
  21. data/lib/{RubyGL/Native → rubygl/native}/include/GLContext.h +36 -36
  22. data/lib/{RubyGL/Native → rubygl/native}/include/Input.h +15 -15
  23. data/lib/{RubyGL/Native → rubygl/native}/include/Window.h +27 -27
  24. data/lib/rubygl/native/input.rb +247 -0
  25. data/lib/{RubyGL/Native → rubygl/native}/opengl.rb +2808 -2032
  26. data/lib/{RubyGL/Native → rubygl/native}/src/GLContext.c +72 -72
  27. data/lib/{RubyGL/Native → rubygl/native}/src/Input.c +25 -25
  28. data/lib/{RubyGL/Native → rubygl/native}/src/Window.c +57 -57
  29. data/lib/{RubyGL/Native → rubygl/native}/window.rb +24 -24
  30. data/lib/{RubyGL → rubygl}/setup.rb +50 -50
  31. data/lib/{RubyGL → rubygl}/shader.rb +203 -203
  32. data/lib/{RubyGL → rubygl}/util.rb +77 -77
  33. data/lib/rubygl.rb +49 -48
  34. data/{RubyGL.gemspec → rubygl.gemspec} +20 -23
  35. data/test/test_util.rb +19 -0
  36. metadata +36 -33
  37. data/lib/RubyGL/Native/input.rb +0 -13
  38. data/lib/RubyGL/callback.rb +0 -10
@@ -1,73 +1,73 @@
1
- #include "GLContext.h"
2
-
3
- const SDL_GLattr RED_SIZE = SDL_GL_RED_SIZE,
4
- GREEN_SIZE = SDL_GL_GREEN_SIZE,
5
- BLUE_SIZE = SDL_GL_BLUE_SIZE,
6
- ALPHA_SIZE = SDL_GL_ALPHA_SIZE,
7
- BUFFER_SIZE = SDL_GL_BUFFER_SIZE,
8
- DOUBLEBUFFER = SDL_GL_DOUBLEBUFFER,
9
- DEPTH_SIZE = SDL_GL_DEPTH_SIZE,
10
- STENCIL_SIZE = SDL_GL_STENCIL_SIZE,
11
- ACCUM_RED_SIZE = SDL_GL_ACCUM_RED_SIZE,
12
- ACCUM_GREEN_SIZE = SDL_GL_ACCUM_GREEN_SIZE,
13
- ACCUM_BLUE_SIZE = SDL_GL_ACCUM_BLUE_SIZE,
14
- ACCUM_ALPHA_SIZE = SDL_GL_ACCUM_ALPHA_SIZE,
15
- STEREO = SDL_GL_STEREO,
16
- MULTISAMPLEBUFFERS = SDL_GL_MULTISAMPLEBUFFERS,
17
- MULTISAMPLESAMPLES = SDL_GL_MULTISAMPLESAMPLES,
18
- ACCELERATED_VISUAL = SDL_GL_ACCELERATED_VISUAL,
19
- CONTEXT_MAJOR_VERSION = SDL_GL_CONTEXT_MAJOR_VERSION,
20
- CONTEXT_MINOR_VERSION = SDL_GL_CONTEXT_MINOR_VERSION,
21
- CONTEXT_FLAGS = SDL_GL_CONTEXT_FLAGS,
22
- CONTEXT_PROFILE_MASK = SDL_GL_CONTEXT_PROFILE_MASK,
23
- SHARE_WITH_CURRENT_CONTEXT = SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
24
- FRAMEBUFFER_SRGB_CAPABLE = SDL_GL_FRAMEBUFFER_SRGB_CAPABLE;
25
-
26
- const SDL_GLcontextFlag CONTEXT_DEBUG_FLAG = SDL_GL_CONTEXT_DEBUG_FLAG,
27
- CONTEXT_FORWARD_COMPATIBLE_FLAG = SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG,
28
- CONTEXT_ROBUST_ACCESS_FLAG = SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG,
29
- CONTEXT_RESET_ISOLATION_FLAG = SDL_GL_CONTEXT_RESET_ISOLATION_FLAG;
30
-
31
- const SDL_GLprofile CONTEXT_PROFILE_CORE = SDL_GL_CONTEXT_PROFILE_CORE,
32
- CONTEXT_PROFILE_COMPATIBILITY = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY,
33
- CONTEXT_PROFILE_ES = SDL_GL_CONTEXT_PROFILE_ES;
34
-
35
- int loadLibrary(const char* path)
36
- {
37
- return SDL_GL_LoadLibrary(path);
38
- }
39
-
40
- void unloadLibrary(void)
41
- {
42
- SDL_GL_UnloadLibrary();
43
- }
44
-
45
- SDL_GLContext createContext(SDL_Window* window)
46
- {
47
- return SDL_GL_CreateContext(window);
48
- }
49
-
50
- void deleteContext(SDL_GLContext context)
51
- {
52
- SDL_GL_DeleteContext(context);
53
- }
54
-
55
- int setAttribute(SDL_GLattr attr, int value)
56
- {
57
- return SDL_GL_SetAttribute(attr, value);
58
- }
59
-
60
- int makeCurrent(SDL_Window* window, SDL_GLContext context)
61
- {
62
- return SDL_GL_MakeCurrent(window, context);
63
- }
64
-
65
- int setSwapInterval(int interval)
66
- {
67
- return SDL_GL_SetSwapInterval(interval);
68
- }
69
-
70
- void swapWindow(SDL_Window* window)
71
- {
72
- SDL_GL_SwapWindow(window);
1
+ #include "GLContext.h"
2
+
3
+ const SDL_GLattr RED_SIZE = SDL_GL_RED_SIZE,
4
+ GREEN_SIZE = SDL_GL_GREEN_SIZE,
5
+ BLUE_SIZE = SDL_GL_BLUE_SIZE,
6
+ ALPHA_SIZE = SDL_GL_ALPHA_SIZE,
7
+ BUFFER_SIZE = SDL_GL_BUFFER_SIZE,
8
+ DOUBLEBUFFER = SDL_GL_DOUBLEBUFFER,
9
+ DEPTH_SIZE = SDL_GL_DEPTH_SIZE,
10
+ STENCIL_SIZE = SDL_GL_STENCIL_SIZE,
11
+ ACCUM_RED_SIZE = SDL_GL_ACCUM_RED_SIZE,
12
+ ACCUM_GREEN_SIZE = SDL_GL_ACCUM_GREEN_SIZE,
13
+ ACCUM_BLUE_SIZE = SDL_GL_ACCUM_BLUE_SIZE,
14
+ ACCUM_ALPHA_SIZE = SDL_GL_ACCUM_ALPHA_SIZE,
15
+ STEREO = SDL_GL_STEREO,
16
+ MULTISAMPLEBUFFERS = SDL_GL_MULTISAMPLEBUFFERS,
17
+ MULTISAMPLESAMPLES = SDL_GL_MULTISAMPLESAMPLES,
18
+ ACCELERATED_VISUAL = SDL_GL_ACCELERATED_VISUAL,
19
+ CONTEXT_MAJOR_VERSION = SDL_GL_CONTEXT_MAJOR_VERSION,
20
+ CONTEXT_MINOR_VERSION = SDL_GL_CONTEXT_MINOR_VERSION,
21
+ CONTEXT_FLAGS = SDL_GL_CONTEXT_FLAGS,
22
+ CONTEXT_PROFILE_MASK = SDL_GL_CONTEXT_PROFILE_MASK,
23
+ SHARE_WITH_CURRENT_CONTEXT = SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
24
+ FRAMEBUFFER_SRGB_CAPABLE = SDL_GL_FRAMEBUFFER_SRGB_CAPABLE;
25
+
26
+ const SDL_GLcontextFlag CONTEXT_DEBUG_FLAG = SDL_GL_CONTEXT_DEBUG_FLAG,
27
+ CONTEXT_FORWARD_COMPATIBLE_FLAG = SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG,
28
+ CONTEXT_ROBUST_ACCESS_FLAG = SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG,
29
+ CONTEXT_RESET_ISOLATION_FLAG = SDL_GL_CONTEXT_RESET_ISOLATION_FLAG;
30
+
31
+ const SDL_GLprofile CONTEXT_PROFILE_CORE = SDL_GL_CONTEXT_PROFILE_CORE,
32
+ CONTEXT_PROFILE_COMPATIBILITY = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY,
33
+ CONTEXT_PROFILE_ES = SDL_GL_CONTEXT_PROFILE_ES;
34
+
35
+ int loadLibrary(const char* path)
36
+ {
37
+ return SDL_GL_LoadLibrary(path);
38
+ }
39
+
40
+ void unloadLibrary(void)
41
+ {
42
+ SDL_GL_UnloadLibrary();
43
+ }
44
+
45
+ SDL_GLContext createContext(SDL_Window* window)
46
+ {
47
+ return SDL_GL_CreateContext(window);
48
+ }
49
+
50
+ void deleteContext(SDL_GLContext context)
51
+ {
52
+ SDL_GL_DeleteContext(context);
53
+ }
54
+
55
+ int setAttribute(SDL_GLattr attr, int value)
56
+ {
57
+ return SDL_GL_SetAttribute(attr, value);
58
+ }
59
+
60
+ int makeCurrent(SDL_Window* window, SDL_GLContext context)
61
+ {
62
+ return SDL_GL_MakeCurrent(window, context);
63
+ }
64
+
65
+ int setSwapInterval(int interval)
66
+ {
67
+ return SDL_GL_SetSwapInterval(interval);
68
+ }
69
+
70
+ void swapWindow(SDL_Window* window)
71
+ {
72
+ SDL_GL_SwapWindow(window);
73
73
  }
@@ -1,26 +1,26 @@
1
- #include "Input.h"
2
-
3
- int initInput()
4
- {
5
- return SDL_InitSubSystem(SDL_INIT_EVENTS);
6
- }
7
-
8
- void quitInput()
9
- {
10
- SDL_QuitSubSystem(SDL_INIT_EVENTS);
11
- }
12
-
13
- void addEventWatch(SDL_EventFilter filter, void* userdata)
14
- {
15
- SDL_AddEventWatch(filter, userdata);
16
- }
17
-
18
- void deleteEventWatch(SDL_EventFilter filter, void* userdata)
19
- {
20
- SDL_DelEventWatch(filter, userdata);
21
- }
22
-
23
- void pumpEvents(void)
24
- {
25
- SDL_PumpEvents();
1
+ #include "Input.h"
2
+
3
+ int initInput()
4
+ {
5
+ return SDL_InitSubSystem(SDL_INIT_EVENTS);
6
+ }
7
+
8
+ void quitInput()
9
+ {
10
+ SDL_QuitSubSystem(SDL_INIT_EVENTS);
11
+ }
12
+
13
+ void addEventWatch(SDL_EventFilter filter, void* userdata)
14
+ {
15
+ SDL_AddEventWatch(filter, userdata);
16
+ }
17
+
18
+ void deleteEventWatch(SDL_EventFilter filter, void* userdata)
19
+ {
20
+ SDL_DelEventWatch(filter, userdata);
21
+ }
22
+
23
+ void pumpEvents(void)
24
+ {
25
+ SDL_PumpEvents();
26
26
  }
@@ -1,58 +1,58 @@
1
- #include "Window.h"
2
-
3
- const SDL_WindowFlags FULLSCREEN = SDL_WINDOW_FULLSCREEN,
4
- OPENGL = SDL_WINDOW_OPENGL,
5
- SHOWN = SDL_WINDOW_SHOWN,
6
- HIDDEN = SDL_WINDOW_HIDDEN,
7
- BORDERLESS = SDL_WINDOW_BORDERLESS,
8
- RESIZABLE = SDL_WINDOW_RESIZABLE,
9
- MINIMIZED = SDL_WINDOW_MINIMIZED,
10
- MAXIMIZED = SDL_WINDOW_MAXIMIZED,
11
- INPUT_GRABBED = SDL_WINDOW_INPUT_GRABBED,
12
- INPUT_FOCUS = SDL_WINDOW_INPUT_FOCUS,
13
- MOUSE_FOCUS = SDL_WINDOW_MOUSE_FOCUS,
14
- FULLSCREEN_DESKTOP = SDL_WINDOW_FULLSCREEN_DESKTOP,
15
- FOREIGN = SDL_WINDOW_FOREIGN,
16
- ALLOW_HIGHDPI = SDL_WINDOW_ALLOW_HIGHDPI;
17
-
18
- int initWindow()
19
- {
20
- return SDL_InitSubSystem(SDL_INIT_VIDEO);
21
- }
22
-
23
- void quitWindow()
24
- {
25
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
26
- }
27
-
28
- SDL_Window* createWindow(const char* title, int x, int y, int w, int h,
29
- Uint32 flags)
30
- {
31
- return SDL_CreateWindow(title, x, y, w, h, flags);
32
- }
33
-
34
- void destroyWindow(SDL_Window* window)
35
- {
36
- SDL_DestroyWindow(window);
37
- }
38
-
39
- void hideWindow(SDL_Window* window)
40
- {
41
- SDL_HideWindow(window);
42
- }
43
-
44
- void showWindow(SDL_Window* window)
45
- {
46
- SDL_ShowWindow(window);
47
- }
48
-
49
- int setWindowBrightness(SDL_Window* window, float brightness)
50
- {
51
- return SDL_SetWindowBrightness(window, brightness);
52
- }
53
-
54
- int showSimpleMessageBox(Uint32 flags, const char* title, const char* message,
55
- SDL_Window* window)
56
- {
57
- return SDL_ShowSimpleMessageBox(flags, title, message, window);
1
+ #include "Window.h"
2
+
3
+ const SDL_WindowFlags FULLSCREEN = SDL_WINDOW_FULLSCREEN,
4
+ OPENGL = SDL_WINDOW_OPENGL,
5
+ SHOWN = SDL_WINDOW_SHOWN,
6
+ HIDDEN = SDL_WINDOW_HIDDEN,
7
+ BORDERLESS = SDL_WINDOW_BORDERLESS,
8
+ RESIZABLE = SDL_WINDOW_RESIZABLE,
9
+ MINIMIZED = SDL_WINDOW_MINIMIZED,
10
+ MAXIMIZED = SDL_WINDOW_MAXIMIZED,
11
+ INPUT_GRABBED = SDL_WINDOW_INPUT_GRABBED,
12
+ INPUT_FOCUS = SDL_WINDOW_INPUT_FOCUS,
13
+ MOUSE_FOCUS = SDL_WINDOW_MOUSE_FOCUS,
14
+ FULLSCREEN_DESKTOP = SDL_WINDOW_FULLSCREEN_DESKTOP,
15
+ FOREIGN = SDL_WINDOW_FOREIGN,
16
+ ALLOW_HIGHDPI = SDL_WINDOW_ALLOW_HIGHDPI;
17
+
18
+ int initWindow()
19
+ {
20
+ return SDL_InitSubSystem(SDL_INIT_VIDEO);
21
+ }
22
+
23
+ void quitWindow()
24
+ {
25
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
26
+ }
27
+
28
+ SDL_Window* createWindow(const char* title, int x, int y, int w, int h,
29
+ Uint32 flags)
30
+ {
31
+ return SDL_CreateWindow(title, x, y, w, h, flags);
32
+ }
33
+
34
+ void destroyWindow(SDL_Window* window)
35
+ {
36
+ SDL_DestroyWindow(window);
37
+ }
38
+
39
+ void hideWindow(SDL_Window* window)
40
+ {
41
+ SDL_HideWindow(window);
42
+ }
43
+
44
+ void showWindow(SDL_Window* window)
45
+ {
46
+ SDL_ShowWindow(window);
47
+ }
48
+
49
+ int setWindowBrightness(SDL_Window* window, float brightness)
50
+ {
51
+ return SDL_SetWindowBrightness(window, brightness);
52
+ }
53
+
54
+ int showSimpleMessageBox(Uint32 flags, const char* title, const char* message,
55
+ SDL_Window* window)
56
+ {
57
+ return SDL_ShowSimpleMessageBox(flags, title, message, window);
58
58
  }
@@ -1,25 +1,25 @@
1
- require 'ffi'
2
-
3
- module RubyGL::Native
4
- attach_function :initWindow, [], :int
5
- attach_function :quitWindow, [], :void
6
- attach_function :createWindow, [:string, :int, :int, :int, :int, :uint32], :pointer
7
- attach_function :destroyWindow, [:pointer], :void
8
- attach_function :hideWindow, [:pointer], :void
9
- attach_function :showWindow, [:pointer], :void
10
- attach_function :setWindowBrightness, [:pointer, :float], :int
11
- attach_function :showSimpleMessageBox, [:uint32, :string, :string, :pointer], :int
12
-
13
- attach_variable :FULLSCREEN, :int
14
- attach_variable :OPENGL, :int
15
- attach_variable :SHOWN, :int
16
- attach_variable :HIDDEN, :int
17
- attach_variable :BORDERLESS, :int
18
- attach_variable :RESIZABLE, :int
19
- attach_variable :MINIMIZED, :int
20
- attach_variable :MAXIMIZED, :int
21
- attach_variable :INPUT_FOCUS, :int
22
- attach_variable :MOUSE_FOCUS, :int
23
- attach_variable :FULLSCREEN_DESKTOP, :int
24
- attach_variable :ALLOW_HIGHDPI, :int
1
+ require 'ffi'
2
+
3
+ module RubyGL::Native
4
+ attach_function :initWindow, [], :int
5
+ attach_function :quitWindow, [], :void
6
+ attach_function :createWindow, [:string, :int, :int, :int, :int, :uint32], :pointer
7
+ attach_function :destroyWindow, [:pointer], :void
8
+ attach_function :hideWindow, [:pointer], :void
9
+ attach_function :showWindow, [:pointer], :void
10
+ attach_function :setWindowBrightness, [:pointer, :float], :int
11
+ attach_function :showSimpleMessageBox, [:uint32, :string, :string, :pointer], :int
12
+
13
+ attach_variable :FULLSCREEN, :int
14
+ attach_variable :OPENGL, :int
15
+ attach_variable :SHOWN, :int
16
+ attach_variable :HIDDEN, :int
17
+ attach_variable :BORDERLESS, :int
18
+ attach_variable :RESIZABLE, :int
19
+ attach_variable :MINIMIZED, :int
20
+ attach_variable :MAXIMIZED, :int
21
+ attach_variable :INPUT_FOCUS, :int
22
+ attach_variable :MOUSE_FOCUS, :int
23
+ attach_variable :FULLSCREEN_DESKTOP, :int
24
+ attach_variable :ALLOW_HIGHDPI, :int
25
25
  end
@@ -1,51 +1,51 @@
1
- require_relative './native/glcontext'
2
- require_relative './native/window'
3
-
4
- module RubyGL
5
-
6
- class DefaultSetup
7
- # The args hash accepts position and size values to be applied to the window.
8
- # :x, :y, :width, :height
9
- def initialize(args = {})
10
- RubyGL::Native.initWindow
11
- RubyGL::Native.initInput
12
- RubyGL::Native.loadLibrary(FFI::Pointer::NULL)
13
-
14
- RubyGL::Native.setAttribute(:context_major_version, 4)
15
- RubyGL::Native.setAttribute(:context_minor_version, 2)
16
- RubyGL::Native.setAttribute(:context_profile_mask, RubyGL::Native.CONTEXT_PROFILE_COMPATIBILITY)
17
-
18
- RubyGL::Native.setAttribute(:depth_size, 24)
19
- RubyGL::Native.setAttribute(:doublebuffer, 1)
20
-
21
- @window = RubyGL::Native.createWindow("RubyGL Window",
22
- args[:x] || 50, args[:y] || 50,
23
- args[:width] || 500, args[:height] || 500,
24
- RubyGL::Native.OPENGL)
25
- @context = RubyGL::Native.createContext(@window)
26
-
27
- RubyGL::Native.makeCurrent(@window, @context)
28
- RubyGL::Native.setSwapInterval(1)
29
- end
30
-
31
- def show_dialog(title, message)
32
- RubyGL::Native.showSimpleMessageBox(0, title, message, @window)
33
- end
34
-
35
- def end_frame()
36
- RubyGL::Native.swapWindow(@window)
37
-
38
- RubyGL::Native.pumpEvents()
39
- end
40
-
41
- def teardown()
42
- RubyGL::Native.deleteContext(@context)
43
- RubyGL::Native.destroyWindow(@window)
44
-
45
- RubyGL::Native.unloadLibrary()
46
- RubyGL::Native.quitWindow()
47
- RubyGL::Native.quitInput()
48
- end
49
- end
50
-
1
+ require_relative './native/glcontext'
2
+ require_relative './native/window'
3
+
4
+ module RubyGL
5
+
6
+ class DefaultSetup
7
+ # The args hash accepts position and size values to be applied to the window.
8
+ # :x, :y, :width, :height
9
+ def initialize(args = {})
10
+ RubyGL::Native.initWindow
11
+ RubyGL::Native.initInput
12
+ RubyGL::Native.loadLibrary(FFI::Pointer::NULL)
13
+
14
+ RubyGL::Native.setAttribute(:context_major_version, 4)
15
+ RubyGL::Native.setAttribute(:context_minor_version, 2)
16
+ RubyGL::Native.setAttribute(:context_profile_mask, RubyGL::Native.CONTEXT_PROFILE_COMPATIBILITY)
17
+
18
+ RubyGL::Native.setAttribute(:depth_size, 24)
19
+ RubyGL::Native.setAttribute(:doublebuffer, 1)
20
+
21
+ @window = RubyGL::Native.createWindow("RubyGL Window",
22
+ args[:x] || 50, args[:y] || 50,
23
+ args[:width] || 500, args[:height] || 500,
24
+ RubyGL::Native.OPENGL)
25
+ @context = RubyGL::Native.createContext(@window)
26
+
27
+ RubyGL::Native.makeCurrent(@window, @context)
28
+ RubyGL::Native.setSwapInterval(1)
29
+ end
30
+
31
+ def show_dialog(title, message)
32
+ RubyGL::Native.showSimpleMessageBox(0, title, message, @window)
33
+ end
34
+
35
+ def end_frame()
36
+ RubyGL::Native.swapWindow(@window)
37
+
38
+ RubyGL::Native.pumpEvents()
39
+ end
40
+
41
+ def teardown()
42
+ RubyGL::Native.deleteContext(@context)
43
+ RubyGL::Native.destroyWindow(@window)
44
+
45
+ RubyGL::Native.unloadLibrary()
46
+ RubyGL::Native.quitWindow()
47
+ RubyGL::Native.quitInput()
48
+ end
49
+ end
50
+
51
51
  end