Giter Club home page Giter Club logo

glutin's Introduction

glutin - OpenGL, UTilities, and INput

A low-level library for OpenGL context creation.

Docs.rs

[dependencies]
glutin = "0.31.3"

Contact Us

Join us in any of these:

Matrix Libera.Chat

Usage Examples

Warning: These are examples for master. You can find examples for the latest released version here.

The examples use gl_generator to generate OpenGL bindings.

Try it!

git clone https://github.com/rust-windowing/glutin
cd glutin
cargo run --example window

Usage

Glutin is an OpenGL context creation library, and doesn't directly provide OpenGL bindings for you.

For examples, please look here.

Note that glutin aims at being a low-level brick in your rendering infrastructure. You are encouraged to write another layer of abstraction between glutin and your application.

Glutin follows winit's MSRV policy.

Platform-specific notes

Android

Be sure to handle Android's lifecycle correctly when using a winit window by only creating a GL surface after winit raises Event::Resumed, and destroy it again upon receiving Event::Suspended. See this in action in the android.rs example.

To compile and run the Android example on your device, install cargo-apk and start the app using:

$ cargo apk r -p glutin_examples --example android

glutin's People

Contributors

aceeri avatar atouchet avatar bjwbell avatar brendanzab avatar bvssvni avatar chrisduerr avatar daggerbot avatar eijebong avatar elinorbgr avatar emilio avatar fkaa avatar francesca64 avatar fredriknoren avatar frewsxcv avatar goddessfreya avatar gw3583 avatar kchibisov avatar kvark avatar madsmtm avatar marijns95 avatar mbrubeck avatar mitchmindtree avatar osspial avatar ozkriff avatar paulrouget avatar pixelpirate avatar plasticcaz avatar ryanstew avatar ssheldon avatar tomaka 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glutin's Issues

Put GetMessage and PeekMessage in its own thread

GetMessage and PeekMessage must be called in the same o/s thread as the one where we called CreateWindow.

For the moment, win32's Window struct has a NoSend marker, but this is only correct for native threads. In case of green threads, it is possible that a task switches from an o/s thread to another.

Segfault in XQueryExtension() on 64-bit Linux

I am attempting to compile and run a minimal program from the gfx-rs triangle example. I have modified the source to only use gl-init-rs and no glfw code. When running the output program, a window appears and the program immediately segfaults:

0x00007ffff77a5ae8 in XQueryExtension () from /usr/lib/x86_64-linux-gnu/libX11.so.6

I am using rustc 0.12.0-pre-nightly (c4a63fabe 2014-08-10 21:56:11 +0000). From my Cargo.lock I can see I am running against gl-init-rs.git#87d62e5b6f38ab34586c0c9b5f41f1558e51cd14.

uname --all: Linux Luna 3.10.6-031006-generic #201308112316 SMP Mon Aug 12 03:17:33 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux.

And the full source code to reproduce the crash:

#![feature(phase)]
#![crate_name = "shiny"]

#[phase(plugin)]
extern crate gfx_macros;
extern crate getopts;
extern crate gfx;
extern crate glinit = "gl-init-rs";
extern crate gl_init_platform;
extern crate native;

#[vertex_format]
struct Vertex {
    pos: [f32, ..2],
    color: [f32, ..3],
}

static VERTEX_SRC: gfx::ShaderSource = shaders! {
GLSL_120: b"
    #version 120
    attribute vec2 pos;
    attribute vec3 color;
    varying vec4 v_Color;
    void main() {
        v_Color = vec4(color, 1.0);
        gl_Position = vec4(pos, 0.0, 1.0);
    }
"
GLSL_150: b"
    #version 150 core
    in vec2 pos;
    in vec3 color;
    out vec4 v_Color;
    void main() {
        v_Color = vec4(color, 1.0);
        gl_Position = vec4(pos, 0.0, 1.0);
    }
"
};

static FRAGMENT_SRC: gfx::ShaderSource = shaders! {
GLSL_120: b"
    #version 120
    varying vec4 v_Color;
    void main() {
        gl_FragColor = v_Color;
    }
"
GLSL_150: b"
    #version 150 core
    in vec4 v_Color;
    out vec4 o_Color;
    void main() {
        o_Color = v_Color;
    }
"
};

// We need to run on the main thread for GLFW, so ensure we are using the `native` runtime. This is
// technically not needed, since this is the default, but it's not guaranteed.
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
     native::start(argc, argv, main)
}

fn main() {
    let window = gl_init_platform::Window::new().unwrap();
    window.set_title("[gl-init] Triangle example #gfx-rs!");
    unsafe { window.make_current() };

    let (w, h) = window.get_inner_size().unwrap();

    let mut device = gfx::build()
        .with_context(&window)
        .with_provider(&window)
        .with_queue_size(1)
        .spawn(proc(r) render(r, w as u16, h as u16))
        .unwrap();

    'main: loop {
        // quit when Esc is pressed.
        for event in window.poll_events() {
            match event {
                glinit::Pressed(glinit::Escape) => break 'main,
                glinit::Closed => break 'main,
                _ => {},
            }
        }
        device.update();
    }
}

fn render(mut renderer: gfx::Renderer, width: u16, height: u16) {
    let frame = gfx::Frame::new(width as u16, height as u16);
    let state = gfx::DrawState::new();

    let vertex_data = vec![
        Vertex { pos: [ -0.5, -0.5 ], color: [1.0, 0.0, 0.0] },
        Vertex { pos: [ 0.5, -0.5 ], color: [0.0, 1.0, 0.0]  },
        Vertex { pos: [ 0.0, 0.5 ], color: [0.0, 0.0, 1.0]  }
    ];

    let mesh = renderer.create_mesh(vertex_data);
    let program = renderer.create_program(VERTEX_SRC.clone(), FRAGMENT_SRC.clone());

    let clear = gfx::ClearData {
        color: Some(gfx::Color([0.3, 0.3, 0.3, 1.0])),
        depth: None,
        stencil: None,
    };

    while !renderer.should_finish() {
        renderer.clear(clear, frame);
        renderer.draw(&mesh, mesh.get_slice(), &frame, &program, &state)
            .unwrap();
        renderer.end_frame();
        for err in renderer.errors() {
            println!("Renderer error: {}", err);
        }
    }
}

Change monitors system

Reading the list of monitors on X11 opens a Display just for this. The API needs to be changed to prevent this from happening.

Implement lists sharing

Allow creating a window from an existing window, so that both share the same GL objects.

This is especially important for switching between fullscreen and window.

glXChooseFBConfig returns null for X11 target

Hi,

I'm using Linux (Fedora) on a virtual machine, so that might be why I get this error (checked on dual boot with another machine and it worked fine).
It seems that the errors are due to the settings of GLX_X_RENDERABLE and GLX_X_VISUAL_TYPE.
If I set them both to GLX_DONT_CARE (default values), I can run the test and open the window (i.e. ./target/test/window).
Obviously this solution is not optimal, as GLX_X_RENDERABLE should be set to true, so I didn't create a pull request for that.

Multithreading discussion

Let's sum up everything related to multithreading.

API limitations

  • In win32, you can create windows in any thread (not only in the main thread contrary to popular belief), but in order to retreive the window's events you must call GetMessage in the same thread as the one where you create the window.
  • In xlib, you must call XInitThreads before any other xlib function, or the library is not thread-safe.
  • In cocoa, apparently everything must be done in the main thread. I don't know much about cocoa, so someone should bring some more informations.

What do other libraries do?

GLFW and the SDL just assume that you do everything in the main thread. GLFW calls XInitThreads but the SDL does not.

Needs more informations here

What does glutin do?

  • In win32, a new thread is created for each window and messages are passed through channels.
  • In xlib, XInitThreads is called behind a Once (#65).
  • In cocoa, as far as I know the implementation is currently unsafe (@DavidPartouche is working on it)

X11 prints "0x0" to stdout for every function it fails to load.

Not really an issue as such, just rather spammy/verbose and Win32 and EGL don't do this.

I'm guessing it just needs suppressing? Windows uses GetProcaddress() if wglGetProcAddress() fails, so the equivalent is to use dlsym() I think, but should be unnecessary on X11. I can throw a pull request together for whichever if you want.

Mouse buttons inconsistency

On X11, the middle mouse button is Button2. On Win32, it's Button3.
Similarly, the right mouse button is Button3 on X11 and Button2 on Win32.

Detect errors on calls to *MakeCurrent

For the moment, calls to wglMakeCurrent, glXMakeCurrent, etc. can silently fail.
The return type of make_current should be a Result<(), MakeCurrentError>.

No render output on Windows 8.1 x64

I checked out the gl-init-rs project and built the test suite with cargo test. Any of the test applications such as window.exe start up and run, but do not show any output (only a black window). When the window is closed, a single frame briefly flashes on the window before it disappears.

The same applies to the gfx-rs triangle demo running with gl-init.

  • rustc 0.12.0-pre-nightly (c4a63fabe 2014-08-10 21:56:11 +0000)
  • gl-init-rs.git#87d62e5b6f38ab34586c0c9b5f41f1558e51cd1

Rename to better convey intended functionality.

As gl-init-rs provides not only an OpenGL context, but also input, it could (should IMO) become the default Piston backend.
That being the case, I find the current name lacking.
I propose glutin-rs (OpenGL, utilities and input), but I am looking forward to a proper bikeshed.

Modify events iterators behavior

wait_events and poll_events should return permanent iterators, ie. iterators that can be reused later.
wait_events should not block but instead return an iterator that blocks when next is called.

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.