Help translating from GLUT to FXRuby??

Discussion in 'Ruby' started by Tom Nakamura, Jun 16, 2005.

  1. Tom Nakamura

    Tom Nakamura Guest

    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, , 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
     
    Tom Nakamura, Jun 16, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Magnusson

    GLUT callback registration (not quite OT)

    Martin Magnusson, Sep 5, 2003, in forum: C++
    Replies:
    1
    Views:
    526
    Ivan Vecerina
    Sep 6, 2003
  2. Bushido Hacks
    Replies:
    0
    Views:
    2,417
    Bushido Hacks
    Feb 20, 2005
  3. Adam Hartshorne

    GLUT & QT Together

    Adam Hartshorne, Apr 24, 2005, in forum: C++
    Replies:
    7
    Views:
    6,406
    Alvin Beach
    Apr 24, 2005
  4. Fulko van Westrenen

    GLUT/Tk problem

    Fulko van Westrenen, Nov 13, 2003, in forum: Python
    Replies:
    1
    Views:
    391
    Fulko van Westrenen
    Nov 13, 2003
  5. Lyle Johnson
    Replies:
    0
    Views:
    153
    Lyle Johnson
    May 20, 2008
Loading...

Share This Page