From: Lyle Johnson Date: 2003-03-26T01:43:38+09:00 Subject: Re: [FXRuby] FXGLViewer and textures Rasmus wrote: > I want to use textures in a FXGLViewer. But there seems to be some > initialization for the OpenGL system missing. When calling > GL.GenTextures a huge number is returned. The OpenGL samples from the > samples/opengl folder return 1 or 2 always. The difference is that > these examples are using GLUT for the GUI -- not FXRuby. > > I have attached an example for my problem. The program prints > >>rubyw gltexture.rbw > Generated texture number 44171928 > Generate mipmap > gltexture.rbw:40: [BUG] Segmentation fault >>Exit code: 3 > > when executed. The segmentation fault seems to be a consequence of the > invalid texture number. > > Does anybody know, what initialization I'm missing? Yes, you need to make the GL viewer's context the "current" context before calling stuff like GL.GenTextures. The least intrusive changes to your example program would be to first add an accessor to the TestWindow class to return a reference to the FXGLViewer window, i.e. class TestWindow < FXMainWindow attr_reader :viewer # ... remaining code as before ... end and then add calls to FXGLViewer#makeCurrent and FXGLViewer#makeNonCurrent before and after the call to TestViewer#scene, i.e. if __FILE__ == $0 application = FXApp.new("Test", "Test") window = TestWindow.new(application) application.create viewer = TestViewer.new # Make the GL viewer's context current window.viewer.makeCurrent # Generate textures, etc. window.scene viewer.scene(1) # Make the GL viewer's context non-current window.viewer.makeNonCurrent application.run end I see some other problems, e.g. you're trying to pass FXGLPoint objects in as arguments to GL.Vertex, which expects an Array. But I'll let you debug those yourself first ;) If you run into additional problems, let me know. Hope this helps, Lyle