rendered paste bodyrequire 'fox16'begin require 'opengl'rescue LoadError require 'fox16/missingdep' MSG = <<EOM Sorry, this example depends on the OpenGL extension. Please check the Ruby Application Archives for an appropriate download site.EOM missingDependency(MSG)endinclude Foxclass GLTestWindow < FXMainWindow # Draw the GL scene def drawScene lightPosition = [15.0, 10.0, 5.0, 1.0] lightAmbient = [ 0.1, 0.1, 0.1, 1.0] lightDiffuse = [ 0.9, 0.9, 0.9, 1.0] redMaterial = [ 1.0, 0.0, 0.0, 1.0] blueMaterial = [ 0.0, 0.0, 1.0, 1.0] width = @glcanvas.width.to_f height = @glcanvas.height.to_f aspect = width/height # Make context current @glcanvas.makeCurrent() GL.Viewport(0, 0, @glcanvas.width, @glcanvas.height) GL.ClearColor(0.0, 0.0, 0.0, 0.0) GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT) GL.Enable(GL::DEPTH_TEST) GL.Disable(GL::DITHER) #GL.MatrixMode(GL::PROJECTION) #GL.LoadIdentity() # GLU.Perspective(30.0, aspect, 1.0, 100.0) # GL.MatrixMode(GL::MODELVIEW) # GL.LoadIdentity() GLU.Ortho2D(0, 500, 0.0, 300);# GLU.LookAt(0, 0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) # GL.PushMatrix()# doModel() # GL.Begin(GL::POINTS); GL.Color(1, 0,0 ,1); (1..100).each do |x1| (1..100).each do |y1| GL.Vertex(x1, y1, 0,1);end end GL.End(); # GL.PopMatrix() #GL.Flush() # Swap if it is double-buffered if @glvisual.isDoubleBuffer @glcanvas.swapBuffers GLU.Ortho2D(0, 500, 0.0, 300); end # Make context non-current @glcanvas.makeNonCurrent end def initialize(app) # Invoke the base class initializer super(app, "OpenGL Test Application", nil, nil, DECOR_ALL, 0, 0, 800, 600) # Construct the main window elements frame = FXHorizontalFrame.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y) frame.padLeft, frame.padRight = 0, 0 frame.padTop, frame.padBottom = 0, 0 # Left pane to contain the glcanvas glcanvasFrame = FXVerticalFrame.new(frame, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT) glcanvasFrame.padLeft, glcanvasFrame.padRight = 10, 10 glcanvasFrame.padTop, glcanvasFrame.padBottom = 10, 10 # Label above the glcanvas FXLabel.new(glcanvasFrame, "OpenGL Canvas Frame", nil, JUSTIFY_CENTER_X|LAYOUT_FILL_X) # Horizontal divider line FXHorizontalSeparator.new(glcanvasFrame, SEPARATOR_GROOVE|LAYOUT_FILL_X) # Drawing glcanvas glpanel = FXVerticalFrame.new(glcanvasFrame, (FRAME_SUNKEN|FRAME_THICK| LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT)) glpanel.padLeft, glpanel.padRight = 0, 0 glpanel.padTop, glpanel.padBottom = 0, 0 # A visual to draw OpenGL @glvisual = FXGLVisual.new(getApp(), VISUAL_DOUBLEBUFFER) # Drawing glcanvas @glcanvas = FXGLCanvas.new(glpanel, @glvisual, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT) @glcanvas.connect(SEL_PAINT) { GL.Flush() #drawScene } @glcanvas.connect(SEL_CONFIGURE) { if @glcanvas.makeCurrent GL.Viewport(0, 0, @glcanvas.width, @glcanvas.height) #drawScene @glcanvas.makeNonCurrent end } # Right pane for the buttons buttonFrame = FXVerticalFrame.new(frame, LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT) buttonFrame.padLeft, buttonFrame.padRight = 10, 10 buttonFrame.padTop, buttonFrame.padBottom = 10, 10 # Label above the buttons FXLabel.new(buttonFrame, "Button Frame", nil, JUSTIFY_CENTER_X|LAYOUT_FILL_X) # Horizontal divider line FXHorizontalSeparator.new(buttonFrame, SEPARATOR_RIDGE|LAYOUT_FILL_X) # updatemodel updateModelBtn = FXButton.new(buttonFrame, "update &Timer\tSpin using interval timers\nNote the app blocks until the interal has elapsed...",nil,nil,0,FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT) updateModelBtn.padLeft, updateModelBtn.padRight = 10, 10 updateModelBtn.padTop, updateModelBtn.padBottom = 5, 5 updateModelBtn.connect(SEL_COMMAND) {drawScene() } updateModelBtn.connect(SEL_UPDATE) { } # Exit button exitBtn = FXButton.new(buttonFrame, "&Exit\tExit the application", nil, getApp(), FXApp::ID_QUIT, FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_TOP|LAYOUT_LEFT) exitBtn.padLeft, exitBtn.padRight = 10, 10 exitBtn.padTop, exitBtn.padBottom = 5, 5 # Make a tooltip FXToolTip.new(getApp()) # Initialize private variables end # Create and initialize def create super show(PLACEMENT_SCREEN) endendif __FILE__ == $0 # Construct the application application = FXApp.new("GLTest", "FoxTest") # Construct the main window GLTestWindow.new(application) # Create the app's windows application.create # Run the application application.runend