Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Showcase / Ruby OpenGl Tutorials
- - By tjbladez Date 2011-03-25 20:03 Edited 2011-05-11 03:01
Hey guys,

Figured I will share my progress. I am writing/porting a set of tutorials to work with Ruby, Gosu and OpenGl. If you need more examples of these guys working together or just willing to learn about it you may find it here:

Implemented so far:
lesson01 - texture loading
lesson02 - polygons
lesson03 - adding colors
lesson04 - rotation animation
lesson05 - 3D shapes
lesson06 - texture mapping
lesson07 - texture filters, lighting and keyboard control
lesson08 - texture blending, transparency
lesson09 - moving bitmaps in 3D space
lesson10 - loading and moving through 3D World (update May, 10)
Attachment: lesson_8.tiff - blending (543k)
Attachment: lesson_8_1.tiff - Lights, Filters etc (384k)
Attachment: lesson_8_3.tiff - Lighting and source of light (479k)
Attachment: lesson_9_2.tiff - Bitmaps (310k)
Parent - By tjbladez Date 2011-03-25 20:34
throwing a couple of quick screenshots. Of course it doesn't reflect keyboard interaction, change of light, texture mapping etc etc etc
Parent - - By jlnr (dev) Date 2011-03-27 09:12
Mhm, the ruby-opengl gem fails me as usual. I get the dreaded "Invalid value" error for all interesting examples. I think it has to do with how the gem casts function pointers around, but I'm not sure. Should I go and offer a few PayPal €€ to the Ruby mailing list?

It would be convenient if the rubygems require was there in all files for us who use 1.8 by default, and if the scripts would maybe automatically chdir into the enclosing folder. That way us lazy TextMate users can just hit cmd+R to run stuff :)
Parent - - By tjbladez Date 2011-03-28 04:01
Thanks for the suggestion on making it easier for textmate users (vim user myself).
If that will be helpful I can through a rvmrc file to suggest a particular gemset (with frozen version) with particular ruby version. I was successful in working with ruby-opengl in ree-1.8.7-2011.03, ree-1.8.7-2010.02, ruby-1.9.1-p378, ruby-1.9.2-p180. Let me know what are your gem versions (ruby-opengl 0.60.1, linecache 0.5, etc)
Parent - - By jlnr (dev) Date 2011-03-28 11:19
I am using 10.6 system Ruby: ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0], the ruby-opengl gem is the same version. Does it work for you with system Ruby?
Parent - - By tjbladez Date 2011-03-30 18:17
I have updated the repo to work with both 1.8 and 1.9 (mri and rubinius).

* bundle install  to install it
* bundle exec ruby <pathtofile> to run each lesson.

jlnr, I have tested it with system ruby as well as install on the clean box. Did you find gist that I have sent you helpful? If you are till experiencing problems can you send me what are you seeing in a gist? Running it from textmate will not work purposely due to the fact that you need to run it via bundler
Parent - By jlnr (dev) Date 2011-03-31 09:19
It's on my desktop and I will try it out tomorrow, thanks!
Parent - - By jlnr (dev) Date 2011-04-01 17:58 Edited 2011-04-01 18:06
Same problem as with system Ruby. Example 3 works, but in example 4 I get this after the window briefly appears:

using_nehe_lessons/lesson04.rb:18:in glClear': invalid operation (Gl::Error)
  from using_nehe_lessons/lesson04.rb:18:in
  from using_nehe_lessons/lesson04.rb:17:in gl'
  from using_nehe_lessons/lesson04.rb:17:in
  from using_nehe_lessons/lesson04.rb:51:in `show'
  from using_nehe_lessons/lesson04.rb:51

That looks like the usual problems I run into with ruby-opengl. On which architecture are you? Is it a 64/32 bit thing (I am on 32-bit)?

Example 8 works with and without bundle BTW (since that is what you tried in the gist). Curious since you seem to use glClear the same way in every file.

And what is linecache? Okay, I have looked it up, but it didn't seem to appear in the code :)
Parent - - By tjbladez Date 2011-04-01 20:07
1) i have 64bit architecture. Also when you try to run example 4 again will it start?
2) If example works without bundler it means that the gems that you need to run it are globally available (probably your case)
3) I have corrected the repo and killed linecache, thanks
Parent - By jlnr (dev) Date 2011-04-01 23:44
1. You are right. It is not deterministic. I just tried more samples and sometimes I get the error on all of them. I contrasted with the "native" ruby-opengl examples and they seem to work more reliably. How could Gosu cause an error in glClear out of all functions? :<
Parent - - By jlnr (dev) Date 2011-04-06 12:33
Hah, got it. So apparently Gosu somewhere triggers a GL error internally, does not clear the error bit, and the first ruby-opengl call will throw a totally unrelated exception. My bad.

Yay, so gosu + ruby-opengl works perfectly fine on OS X! Need to push this out & finally link the tutorial series from the new docs wiki entry page.
Parent - By jsb Date 2011-04-06 19:56
This is great news! This error has been bugging me for ages.
Parent - By tjbladez Date 2011-04-07 03:52
Awesome news! Thank you for finding that.
Parent - - By tjbladez Date 2011-05-27 15:55
:( I am still nondeterministically getting errors except now it is using_nehe_lessons/lesson08.rb:34:in `glBindTexture': invalid operation (Gl::Error), will look to see if i can figure out why
Parent - By jlnr (dev) Date 2011-05-27 22:28
I just realized that I only clear the GL error bit before jumping into gl{} blocks. It now dawns on me that you may also do non-visual GL calls everywhere else. Is my guess right and your call fails outside of a gl{} block?

I'll make it a priority to actually *fix* the GL error instead of suppressing the error number in Gosu 0.7.32. Sorry for the trouble. If ruby-opengl bridges the GL error functions, maybe you can call them to clear the error before the glBindTexture call.
Parent - - By jlnr (dev) Date 2011-06-01 17:45
Super ugly workaround: Call glGetError, which will clear the error flag. I used it to trace down the error and apparently it happens where there is no GL code anyway; if you want you can do the same. I sometimes get an error before the first line of Texture#initialize, but not right after Window#initialize. The weird thing is that there is no GL or Gosu code inbetween those two places that could trigger an error.

I now clear the error flag right after Window#initialize (you can do so too to compare). In a quick test, it seems the flag is sometimes set at program startup… I added a check to every GL call in Gosu to verify that, of course the error is not deterministic :)

If the error flag gets set to some value from out of nowhere and my patch was not enough, then we could only patch ruby-opengl to clear the error bit before every call, and then only check for new errors AFTER the call it's supposed to do.
Parent - By tjbladez Date 2011-06-02 13:41
Thanking for finding it. Workaround of calling glGetError works.
Parent - - By RunnerPack Date 2011-03-31 05:40
So... does this work "out of the box" on OSX? I'm on Win32 and I wasn't sure where to get "/config/boot.rb" so I made one. Other than that and a trivial change to the location of "earth.png" in "lesson01.rb", it seems to be working well. Thanks!
Attachment: boot.rb.txt - Just rename and put in in a "config" folder alongside the others from the repo. (34B)
Parent - By tjbladez Date 2011-03-31 15:28
Great catch, thank you. I have added boot.rb as well as modified bundler to respect mingw_18 and mingw_19 and mswin platforms. Now it should work well out of the box for win32.
Parent - - By Dahrkael Date 2011-04-07 19:44
the cubes of lesson08 and lesson07 after few seconds lose the textures and turn into a white cube, gosus fault?
Parent - - By tjbladez Date 2011-04-08 15:51
can you provide a little more about the environment you are running it in? I am not seeing lose of the textures
Parent - By jlnr (dev) Date 2011-04-08 16:59
It doesn't do this here, but another note about lesson08.rb (and others) - gl shouldn't be used outside of Window#draw. The texture loading should also work fine without the gl block. If it doesn't, let me know :)
Parent - - By Dahrkael Date 2011-04-08 21:19
Microsoft Windows XP SP3 [Versión 5.1.2600]
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

it loses the texture after a few seconds, i think its always at the same moment.
Parent - - By jlnr (dev) Date 2011-04-09 02:53
Can you call GC.disable as a first step and see if it is some kind of weird garbage collection issue?
Parent - - By Dahrkael Date 2011-04-09 09:16
yes it is
Parent - - By jlnr (dev) Date 2011-04-09 11:16
Ah, and I see why. Texture correctly keeps its @image alive, but the Window does not keep the Textures alive.

I could make Gosu a bit safer by making GLTexInfo keeping its attached Image alive, but because tex_name is just a Fixnum, there is no way that "tex_name =" will work with the GC anytime soon. So the example is subtly broken.

I think this is worthy of a comment in the tutorials :)
Parent - By tjbladez Date 2011-04-09 15:15
Thank you Dahrkael and jlnr for worhty comments :). I will fix the example shortly
Parent - - By tjbladez Date 2011-04-11 14:30
Dahrkael, Can you please give it a shot with the newer code?
Parent - By Dahrkael Date 2011-04-11 17:41
it works now \o/
Up Topic Gosu / Gosu Showcase / Ruby OpenGl Tutorials

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill