require 'opengl' require 'glut' require 'mathn' def transformPoint(screenX, screenY) x = (screenX - ($screenWidth / 2.0)) / ($screenWidth / 2.0) y = -1 * (screenY - ($screenHeight / 2.0)) / ($screenHeight / 2.0) return Point2d.new(x, y) end def init GL.Enable(GL::LINE_SMOOTH); GL.Enable(GL::BLEND); GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA); GL.Hint(GL::LINE_SMOOTH_HINT, GL::DONT_CARE); GL.LineWidth(0.1); GL.ClearColor(0.0, 0.0, 0.0, 0.0); end reshape = Proc.new {|w, h| GL.Viewport(0, 0, w, h); GL.MatrixMode(GL::PROJECTION); GL.LoadIdentity(); if (w <= h) GLU.Ortho2D(-1.0, 1.0, -1.0*h/w, 1.0*h/w); else GLU.Ortho2D(-1.0*w/h, 1.0*w/h, -1.0, 1.0); end GL.MatrixMode(GL::MODELVIEW); GL.LoadIdentity(); } GLUT.Init GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB) GLUT.InitWindowSize($screenWidth, $screenHeight) GLUT.CreateWindow($0) init GLUT.ReshapeFunc($reshape)