Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Issue with Opengl
- - By bestguigui Date 2018-02-14 18:07
Hi guys,

I don't know why, but I got some issues with Ruby OpenGL lately. I have some weird errors within a glBegin...glEnd block, like the one below :

`glEnd': invalid operation for glEnd (Gl::Error)

I found something that seems related, but kinda old, on this board :
https://www.libgosu.org/cgi-bin/mwf/topic_show.pl?tid=570

I went with the minimal code I can get to test it out :
require 'gosu'
require 'gl'
require 'glu'

include Gl, Glu

class Window < Gosu::Window
  def initialize
    super(640, 480, false)
  end

  def button_down(id)
    super
    exit if id == Gosu::KbEscape
  end

  def draw
    gl do
      begin
        glBegin(GL_QUADS)
          glVertex3f(10, 10, 0)
          glVertex3f(110, 10, 0)
          glVertex3f(110, 110, 0)
          glVertex3f(10, 110, 0)
        glEnd
      rescue; end

    end
  end
end

Window.new.show

In this case, because of the exception handling, the program doesn't crash and the quad is displayed on the screen. If I comment the begin...rescue, I get the error I mentionned.

I only get this error on lauching the program, doesn't seem to occur later. Would someone have an idea ?

Thanks a lot !
Parent - - By bestguigui Date 2018-02-18 09:11
Actually, don't mind. I have exactly the same issue with GLUT, so Gosu has just nothing to do with it :)
Parent - - By jlnr (dev) Date 2018-02-19 00:32
Oh wow, this issue again :) Does the workaround from the linked thread still work (calling glGetError before any other gl method)? Although it would probably be cleaner to find the OpenGL maintainer and figure out the source of this error instead of working around it. I'm not even sure that OpenGL errors are severe enough that they should throw an exception in Ruby.
Parent - By bestguigui Date 2018-02-19 17:48
I tried first, and no : it doesn't work.

Anytime you'll try to glBegin...glEnd something, it will crash at first. At least once... And a Ruby exception is actually thrown. But we have to handle it if we want to be able to use immediate mode...

I even saw someone modifying the opengl.rb file to include the exception block inside it :(
Parent - - By kjarrigan Date 2018-02-20 14:31
Well "finding" the opengl maintainer isn't that hard - it's my coworker lars: https://github.com/larskanis/opengl but he doesn't do anything other than "keep it running"

Quote - *Attention*: This project is in maintenance mode. It might receive bug fixes or adjustments for new Ruby versions, but no new features (like support for newer OpenGL versions).

But just some days ago he stumbled across a "new" opengl gem: https://github.com/vaiorabbit/ruby-opengl. He alreadys switch some of our company internal gui's to the new binding and mentioned that it worked quite well. There are less comfort ruby-like functions but the transition was really easy and due to its usage of the Khronos XML API it supports even newer opengl versions. Haven't really looked into the code yet (just came back from a month long holiday), but he was quite satisfied with this gem so you might give it a try.

Greetings,
Kjarrigan
Parent - By bestguigui Date 2018-02-20 17:35 Edited 2018-02-20 18:34
Works like a charm !!! Thank you so much ! In case some would like to see the differences :

Link : https://github.com/vaiorabbit/ruby-opengl (just removed the accidental "." at the end ;))

gem install opengl-bindings

and then the minimal code :

require 'gosu'
require 'opengl'
require 'glu'

OpenGL.load_lib
GLU.load_lib

include OpenGL, GLU

class Window < Gosu::Window
  def initialize
    super(640, 480, false)
  end

  def button_down(id)
    super
    exit if id == Gosu::KbEscape
  end

  def draw
    gl do
        glBegin(GL_QUADS)
          glVertex3f(10, 10, 0)
          glVertex3f(110, 10, 0)
          glVertex3f(110, 110, 0)
          glVertex3f(10, 110, 0)
        glEnd
    end
  end
end

Window.new.show

We have to add those load_lib methods at the very begining. But then, it just works !

JLNR : it's supposed to support new versions, but for now I can't get a sample code to display something using modern opengl and Gosu. Maybe I'm wrong somewhere, but would there be some incompatibility around it ?
Parent - By jlnr (dev) Date 2018-02-21 10:36
Your coworker?! Nice coincidence - say thanks to him for maintaining it :)

I wasn't aware of the ruby-opengl project. I think an older gem was called ruby-opengl before? I'll keep an eye on the new version and maybe update the wiki and example. They have a Gosu-focused example, based on tjbladez' example series, which is nice:

https://github.com/vaiorabbit/ruby-opengl/blob/master/sample/Gosu/lesson01.rb

It's reassuring that it uses libffi. Maybe FFI really is the way to go, after all? The C extension situation on Windows just doesn't seem to get any better with time.
Up Topic Gosu / Gosu Exchange / Issue with Opengl

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill