From: Tom Nakamura Date: 2005-06-16T13:35:20+09:00 Subject: Help translating from GLUT to FXRuby?? Can some please help me translate smooth.rb (below) from yoshi's opengl extension to FXRuby? I've never used opengl before, and am having trouble translating from GLUT to FXRuby. My poor attempt is also below... Tom Nakamura ## ##smooth.rb sample from yoshi's opengl ##shows a pretty little triangle ## require "opengl" require "glut" STDOUT.sync=TRUE disp = Proc.new { GL.Clear(GL::COLOR_BUFFER_BIT) GL.Begin(GL::TRIANGLES) GL.Color(0.0, 0.0, 1.0) GL.Vertex(0, 0) GL.Color(0.0, 1.0, 0.0) GL.Vertex(200, 200) GL.Color(1.0, 0.0, 0.0) GL.Vertex(20, 200) GL.End GL.Flush } reshape = Proc.new {|w, h| GL.Viewport(0, 0, w, h) GL.MatrixMode(GL::PROJECTION) GL.LoadIdentity GL.Ortho(0, w, 0, h, -1, 1) GL.Scale(1, -1, 1) GL.Translate(0, -h, 0) } GLUT.Init a = GLUT.CreateWindow("single triangle"); GLUT.DisplayFunc(disp); GLUT.ReshapeFunc(reshape); GLUT.MainLoop; ## ##My rather pathetic attempt to translate above to FXRuby... ## require 'fox' require 'opengl' include Fox class GLWindow < FXMainWindow def initialize(app) super(app, "GLWindow") @visual = FXGLVisual.new(app, VISUAL_DOUBLEBUFFER) @canvas = FXGLCanvas.new(self,@visual) @canvas.connect(SEL_PAINT) do display end FXButton.new(self,"display").connect(SEL_COMMAND) do |sender, selector, data| display end end def display @canvas.makeCurrent() GL.Viewport(0, 0, @canvas.width, @canvas.height) GL.ClearColor(1.0,1.0,1.0,1.0) GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT) GL.Disable(GL::DITHER) GL.MatrixMode(GL::PROJECTION) GL.LoadIdentity GL.Ortho(0, @canvas.width, 0, @canvas.height, -1, 1) GL.Scale(1, -1, 1) GL.Translate(0, -@canvas.height, 0) GL.Begin(GL::TRIANGLES) GL.Color(0.0, 0.0, 1.0) GL.Vertex(0, 0) GL.Color(0.0, 1.0, 0.0) GL.Vertex(200, 200) GL.Color(1.0, 0.0, 0.0) GL.Vertex(20, 200) GL.End GL.Flush @canvas.makeCurrent() end def create super show(PLACEMENT_SCREEN) end end app = FXApp.new GLWindow.new(app) app.create app.run