GithubHelp home page GithubHelp logo

groogy / crystal_lib_glfw3 Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 10 KB

libglfw3 bindings for Crystal

Home Page: https://github.com/jellymann/crystal_lib_glfw3

License: MIT License

Crystal 100.00%

crystal_lib_glfw3's Introduction

Crystal LibGLFW3

Note: Original binding was done by jellyman. I have however made a fork with fixes needed as it seems this user is not active anymore on this repo and I can't get my pull requests approved. Hence why this fork is independent of the original.

libglfw3 bindings for Crystal. See also my Idiomatic API which makes these bindings more accessible for Crystalists.

Installation

Add to your shards.yml:

dependencies:
  lib_glfw3:
    github: Groogy/crystal_lib_glfw3
    version: 0.1.1

Make sure you have libglfw3 installed on your system

On macOS you can install with homebrew:

brew install glfw3

Usage

Example code for creating a window (tested on macOS 10.11)

require "lib_glfw3"

if LibGLFW3.init != 0
  error_callback = ->(error : Int32, description : Int8*) {
    puts "Error #{error}: #{String.new(description.as(UInt8*))}"
  }
  LibGLFW3.setErrorCallback(error_callback)

  LibGLFW3.windowHint(LibGLFW3::OPENGL_PROFILE, LibGLFW3::OPENGL_CORE_PROFILE)
  LibGLFW3.windowHint(LibGLFW3::OPENGL_FORWARD_COMPAT, 1)
  LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MAJOR, 3)
  LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MINOR, 3)

  window = LibGLFW3.createWindow(800, 600, "Hello Crystal!", nil, nil)

  if window
    LibGLFW3.makeContextCurrent(window)
    LibGLFW3.swapInterval(1)

    while LibGLFW3.windowShouldClose(window) == 0
      LibGLFW3.swapBuffers(window)
      LibGLFW3.pollEvents
    end

    LibGLFW3.destroyWindow(window)
  else
    puts "Failed to create window"
  end

  LibGLFW3.terminate
else
  puts "GLFW failed to initialize"
end

See Also

  1. LibGL bindings for Crystal
  2. Idiomatic Crystal API for GLFW (makes lib_glfw3 nicer to work with)
  3. Crystal OpenGL Samples

Contributing

  1. Fork it ( https://github.com/Groogy/crystal_lib_glfw3/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • jellymann Daniel Smith - creator, maintainer
  • Groogy Henrik Valter Vogelius Hansson - forker

crystal_lib_glfw3's People

Contributors

groogy avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.