Help translating from GLUT to FXRuby??

T

Tom Nakamura

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, (e-mail address removed), 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top