/*
nehe.boo
Requires boo: http://boo.codehaus.org/
and the Tao OpenGl Framework: http://www.taoframework.com/
Compile using the booc compile line tool:
booc.exe -r:Tao.OpenGl.dll -r:Tao.Platform.Windows.dll -out:nehe.exe NeHe.boo
then run nehe.exe
There are better ways to do OpenGL animation, like using Application.DoEvents instead of a timer, and subclassing SimpleOpenGlControl. Unfortunately the Tao Framework not well documented.
*/
namespace NeheTest
import System
import System.Windows.Forms
import System.Drawing
import System.ComponentModel
import Tao.OpenGl
import Tao.Platform.Windows
private class MainForm(Form):
private _glControl = SimpleOpenGlControl()
private _updateTimer = Timer()
def constructor():
InitializeComponent()
_glControl.Location = Point(0, 0)
_glControl.Dock = DockStyle.Fill
_glControl.Visible = true
_glControl.Paint += GlDraw
_glControl.SizeChanged += OnGlResize
GlInit()
self.Load += OnFormLoad //the "self." is optional
self.Closing += OnFormClosing
_glControl.KeyDown += OnKey
self.Controls.Add(_glControl)
def InitializeComponent():
self.AutoScaleBaseSize = System.Drawing.Size(5, 13)
self.ClientSize = System.Drawing.Size(292, 273)
self.Name = 'MainForm'
self.Text = 'NeHe Boo Framework'
override def Dispose(disposing as bool):
if disposing:
if _updateTimer != null:
_updateTimer.Stop()
_updateTimer.Dispose()
_updateTimer = null
super(disposing)
def OnFormLoad(sender, e as EventArgs):
_updateTimer.Interval = 10
_updateTimer.Tick += OnTick
_updateTimer.Start()
def OnTick(sender, e as EventArgs):
_glControl.Invalidate()
def OnFormClosing(sender, e as CancelEventArgs):
if _updateTimer != null:
_updateTimer.Stop()
_updateTimer.Dispose()
_updateTimer = null
def OnKey(sender, e as KeyEventArgs):
if e.KeyCode == Keys.Escape: //char type will be in boo soon
Close()
def GlInit():
_glControl.InitializeContexts()
def OnGlResize():
_glControl.MakeCurrent()
Gl.glViewport( 0, 0, _glControl.Width, _glControl.Height )
Gl.glMatrixMode ( Gl.GL_PROJECTION )
Gl.glLoadIdentity()
Glu.gluPerspective( 60.0, cast(double,_glControl.Width) / _glControl.Height, 1.0,1000.0)
Gl.glMatrixMode ( Gl.GL_MODELVIEW )
Gl.glLoadIdentity()
//Drawing code:
private _lastMs = 0
private _angle = 0.0
def GlDraw():
if _lastMs == 0:
_lastMs = DateTime.Now.Ticks
currentMs = DateTime.Now.Ticks
//int division will change from / to \ in future:
milliseconds as long = (currentMs - _lastMs) / 10000
_lastMs = currentMs
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT)
Gl.glLoadIdentity()
Gl.glTranslatef(0, 0, -6)
Gl.glRotatef(_angle, 0, 1, 0)
rot1 = 0
while rot1 < 2.0:
Gl.glRotatef(90, 0, 1, 0)
Gl.glRotatef(180, 1, 0, 0)
rot2 = 0
while rot2 < 2:
Gl.glRotatef(180, 0, 1, 0)
Gl.glBegin(Gl.GL_TRIANGLES)
Gl.glColor3f(1, 0, 0)
Gl.glVertex3f(0, 1, 0)
Gl.glColor3f(0, 1, 0)
Gl.glVertex3f(-1, -1, 1)
Gl.glColor3f(0, 0, 1)
Gl.glVertex3f(1, -1, 1)
Gl.glEnd()
rot2 += 1
rot1 += 1
Gl.glFlush()
_angle += milliseconds / 5.0
//main part of script
res = MessageBox.Show(null, 'Would You Like To Run In Fullscreen Mode?',
'Start Fullscreen?',
MessageBoxButtons.YesNo,
MessageBoxIcon.Information )
form = MainForm()
if res == DialogResult.Yes:
form.FormBorderStyle = FormBorderStyle.None
form.Location = Point(0, 0)
form.Size = Screen.PrimaryScreen.Bounds.Size
Application.Run(form)
base code using boo (simple python-like language for .NET) and Tao framework
Here is the Nehe base code converted to boo, a python-like language for .NET: http://boo.codehaus.org/ It runs as fast as C# code.
The sample also requires the Tao OpenGl wrapper for .NET & Mono: http://www.taoframework.com/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement