Giter VIP home page Giter VIP logo

ruby-glfw3's Introduction

ruby-glfw3

$ gem install glfw3

Intro

GLFW 3 bindings gem for Ruby 2.x.

To install the gem, you'll need GLFW 3 built and installed where pkg-config can find it. You may also want to grab some OpenGL bindings as well.

Once that's taken care of, you can install it simply by installing the gem via RubyGems.org using

$ gem install glfw3

Or by building and installing the gem, making note of the version so you know the gem package to install, like so:

$ gem build glfw3.gemspec
$ gem install glfw3-VERSION-HERE.gemspec

After that, write a quick script to toy with it. For example:

require 'glfw3'
require 'opengl-core'

# Initialize GLFW 3
Glfw.init

# Create a window
window = Glfw::Window.new(800, 600, "Foobar")

# Set some callbacks
window.set_key_callback do |window, key, code, action, mods|
  window.should_close = true if key == Glfw::KEY_ESCAPE
end

window.set_close_callback do |window|
  window.should_close = true
end

# Make the window's context current
window.make_context_current
loop do
  # And do stuff
  Glfw.wait_events
  GL.glClear(GL::GL_COLOR_BUFFER_BIT | GL::GL_DEPTH_BUFFER_BIT)
  window.swap_buffers
  break if window.should_close?
end

# Explicitly destroy the window when done with it.
window.destroy

License

ruby-glfw3 is licensed under a simplified BSD license because it seems the most reasonable. If there's a problem with that, let me know.

Copyright (c) 2013, Noel Raymond Cower <[email protected]>.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ruby-glfw3's People

Contributors

davll avatar jstenhouse avatar nilium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ruby-glfw3's Issues

Depend on a separate ruby-libglfw3 gem (like libv8)

Instead of depending on this gem's end-user installing glfw3 himself, having a separate gem for glfw3 itself is a nice approach. See how e.g. therubyracer has libv8 as a gem. This makes it incredibly easy to have things "just work", have many versions installed in parallel, handle glfw API changes by making this gem depend on the matching version, manage libglfw3 version with the Gemfile, even optionally provide prebuilt binaries per OS (possibly going as far as removing the need for a C compiler to be installed)...

Of note is that gogl/glfw also does that (although they bundle it straight into the gogl/glfw package). It really makes things easier. Splitting the lib gem from this one (like rubygems/libv8) is better overall though.

I can help in getting things going if you want a hand.

Gamma ramp functions aren't implemented

This is mainly because I haven't decided how I want to implement them. Should it take a hash like

monitor.gamma_ramp = { :red => [...], :green => ... }

or an array or something else. I don't know. I mean it's kind of a one-time call so it doesn't have to be really fast, I just want it to not suck to write the call to set/get gamma ramps.

Add GLFW 3.1 constants

  • GLFW_DONT_CARE
  • GLFW_DOUBLEBUFFER
  • GLFW_CONTEXT_RELEASE_BEHAVIOR
  • GLFW_ANY_RELEASE_BEHAVIOR
  • GLFW_RELEASE_BEHAVIOR_FLUSH
  • GLFW_RELEASE_BEHAVIOR_NONE
  • GLFW_FLOATING
  • GLFW_FOCUSED
  • GLFW_AUTO_ICONIFY

Add little "guide" on how to let pkg-config find glfw3

I think you should add a little explanation on how to do this.

I tried now copying the "glfw-3.2.1" folder in every single path that has todo with pkg-config. I also tried renaming every folder to "glfw3". It did not worked.

Im on Windows.

GLFWcursor support

ruby-glfw3 should support the GLFWcursor additions.

  • glfwCreateCursor
  • glfwCreateStandardCursor
  • glfwDestroyCursor
  • glfwSetCursor

Won't build on platforms where SIZEOF_INT == SIZEOF_LONG

glfw3.c requires rb_num2uint, one of several functions created by ruby if and only if an int is smaller than a long. Check line 2072 of numeric.c:

#if SIZEOF_INT < SIZEOF_LONG

I recommend adding the same #if statement, with your code at line 535 within it. Add an #else statement and change all three calls to rb_num2uint, to rb_num2int. It compiled correctly then, with a warning on signed/unsigned integer conversion.

Edit: Also forgot to mention, I do believe that $LDFLAGS should be changed to $LIBS in extconf.rb, or you'll recieve all sorts of undefined references? At least I did...

how to install on windows os

E:\DemoWorkspace\opengl-> gem install glfw3
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing glfw3:
ERROR: Failed to build gem native extension.

C:/Ruby/Ruby22/bin/ruby.exe -r ./siteconf20160903-9556-1c8soc4.rb extconf.rb

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby/Ruby22/bin/$(RUBY_BASE_NAME)
extconf.rb:3:in ``': No such file or directory - pkg-config --static --libs glfw3 (Errno::ENOENT)
from extconf.rb:3:in`

'

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby/Ruby22/lib/ruby/gems/2.2.0/gems/glfw3-0.4.8 for inspection.
Results logged to C:/Ruby/Ruby22/lib/ruby/gems/2.2.0/extensions/x86-mingw32/2.2.0/glfw3-0.4.8/gem_make.out

i cant install this gem on windows , and how to install glfw3 and make it to be found by pkg-config

Error installing the gem

I installed GLFW per the steps here, but now I get the following errors when trying to install this gem. Do you have any advice?

By the way, the test program from GLFW works just fine.

Building native extensions.  This could take a while...
ERROR:  Error installing glfw3:
    ERROR: Failed to build gem native extension.

    /home/marc/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
creating Makefile

make "DESTDIR="
compiling glfw3.c
glfw3.c: In function ‘rb_glfw_init’:
glfw3.c:85:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c: In function ‘rb_monitor_position’:
glfw3.c:205:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c: In function ‘rb_monitor_physical_size’:
glfw3.c:225:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c: In function ‘rb_monitor_video_modes’:
glfw3.c:368:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c:375:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c: In function ‘rb_monitor_video_mode’:
glfw3.c:396:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c:398:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c: In function ‘rb_monitor_set_gamma_ramp’:
glfw3.c:513:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c: In function ‘rb_window_new’:
glfw3.c:667:28: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
glfw3.c: In function ‘rb_window_destroy’:
glfw3.c:685:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
glfw3.c:686:32: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
glfw3.c: In function ‘rb_monitor_get_gamma_ramp’:
glfw3.c:442:16: warning: ‘ramp’ is used uninitialized in this function [-Wuninitialized]
linking shared-object glfw3/glfw3.so
/usr/bin/ld: /usr/local/lib/libglfw3.a(context.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libglfw3.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [glfw3.so] Error 1

Test with MRI 2.2.0

Currently untested with 2.2.x, need to make time for that. C API had some stuff stripped out and being the hot garbage that the Ruby C API is, I have no idea if this still builds or if I need to rewrite some stuff to retain compatibility.

GLFW 3.1 support

With GLFW 3.1 out the door, support for it needs to be added.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.