PDA

View Full Version : Drawing Board on FXGLCanvas



03-20-2003, 08:24 PM
I'm using a Fox/OpenGL interface to Ruby and have not been able to get shapes to show up correctly in the FXGLCanvas. The code to generate three squares in the canvas area is shown below. The Square class performs a translation on the x and y coordinates. I can't seem to get all three squares to show up, or if they do it is in weird places or off-scale. Also, the program always gives me a different scenario each time I run it. It's all probably something very obvious that I'm overlooking but I can't figure it out.

def drawBoard()
w=@glcanvas.width.to_f
h=@glcanvas.height.to_f
aspect = width/height

@glcanvas.makeCurrent()
GL.Viewport(0, 0, @glcanvas.width, @glcanvas.height)

GL.ClearColor(1.0, 1.0, 1.0, 1.0)
GL.Clear(GL::COLOR_BUFFER_BIT|GL: http://www.opengl.org/discussion_boards/ubb/biggrin.gifEPTH_BUFFER_BIT)
GL.Enable(GL: http://www.opengl.org/discussion_boards/ubb/biggrin.gifEPTH_TEST)

GL.MatrixMode(GL::PROJECTION);
GL.LoadIdentity();
GLU.Perspective(45.0, aspect, 1.0, 100.0)

GL.MatrixMode(GL::MODELVIEW);
GL.LoadIdentity();
GLU.LookAt(5.0, 10.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
GL.ShadeModel(GL::SMOOTH);

@boardArray[1] = Square.new(1.5, 0.5, 0.4)
@boardArray[2] = Square.new(0.0, 2.0, 0.2)
@boardArray[3] = Square.new(0.0, -2.0, 0.4)

GL.Flush();

if @glvisual.isDoubleBuffer
@glcanvas.swapBuffers
end
end