require 'opengl' require 'glut' require 'mathn' require 'bizzielibrary' $rotAngle = 0.0; 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(1.5); GL.ClearColor(0.0, 0.0, 0.0, 0.0); end def drawLine(x1, y1, x2, y2) GL.Begin(GL::LINES) GL.Vertex(x1, y1) GL.Vertex(x2, y2) GL.End end display = Proc.new { GL.Clear(GL::COLOR_BUFFER_BIT); GL.Rotate(-$rotAngle, 0.0, 0.0, 0.1); GL.Color(0.0, 1.0, 0.0); drawLine(0.1, 0.2, -0.5, -0.9) GL.Color(0.0, 0.0, 1.0); drawLine(0.5, 0.5, -0.5, -0.5) GL.Flush(); } 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(); } # /* ARGSUSED1 */ keyboard = Proc.new {|key, x, y| case (key) when 'r'[0],'R'[0] $rotAngle = $rotAngle + 20.0; $rotAngle = 0.0 if ($rotAngle >= 360.0) GLUT.PostRedisplay(); when 27 #/* Escape Key */ exit(0); end } GLUT.Init GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB); GLUT.InitWindowSize(300, 300); GLUT.CreateWindow($0); init(); GLUT.ReshapeFunc(reshape); GLUT.KeyboardFunc(keyboard); GLUT.DisplayFunc(display); GLUT.MainLoop();