Opengl 3D Samples

OpenGL 3D samples

These samples use the Tao Framework for OpenGL on .NET and Mono.
Tao is constantly changing (and moving), so these samples may be out of date.

Redbook.Cube example in boo

//cube.boo
//when compiling with booc, add references to
//Tao.OpenGl.dll and Tao.FreeGlut.dll
//You may need to find a build of the freeglut.dll.  I don't
//know where such a build is now.

import Tao.FreeGlut
import Tao.OpenGl

def Init():
	Gl.glClearColor(0.0, 0.0, 0.0, 0.0) //floats
	Gl.glShadeModel(Gl.GL_FLAT)

def Display():
	Gl.glClear(Gl.GL_COLOR_BUFFER_BIT)
	Gl.glColor3f(1.0, 1.0, 1.0) //floats

	// Clear the matrix
	Gl.glLoadIdentity()

	// Viewing transformation
	Glu.gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

	// Modeling transformation
	Gl.glScalef(1.0, 2.0, 1.0) //floats

	Glut.glutWireCube(1.0)
	Gl.glFlush()

def Keyboard(key as byte, x as int, y as int):
	if key == 27:  //escape key
		System.Environment.Exit(0)

def Reshape(w as int, h as int):
	Gl.glViewport(0, 0, w, h)
	Gl.glMatrixMode(Gl.GL_PROJECTION)
	Gl.glLoadIdentity()
	Gl.glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
	Gl.glMatrixMode(Gl.GL_MODELVIEW)


Glut.glutInit()
Glut.glutInitDisplayMode(Glut.GLUT_SINGLE | Glut.GLUT_RGB)
Glut.glutInitWindowSize(500, 500)
Glut.glutInitWindowPosition(100, 100)
Glut.glutCreateWindow("Cube")
Init()
Glut.glutDisplayFunc(Display)
Glut.glutKeyboardFunc(Keyboard)
Glut.glutReshapeFunc(Reshape)
Glut.glutMainLoop()

NeHe Example

This is a port of the base code sample from the NeHe OpenGL tutorials site. It uses the Tao Framework's SimpleOpenGlControl.

/*
nehe.boo

Requires boo: http://boo.codehaus.org/
and the Tao OpenGl Framework: http://www.mono-project.com/Tao

Compile using the booc compile line tool:
booc.exe -r:Tao.OpenGl.dll -r:Tao.OpenGl.Glu.dll -r:Tao.Platform.Windows.dll -out:nehe.exe NeHe.boo
*/

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 components as Container = null
	private glControl = SimpleOpenGlControl()

	def constructor():
		InitializeComponent()

	def InitializeComponent():
		SuspendLayout()
		glControl.Location = Point(0, 0)
		glControl.Dock = DockStyle.Fill
		glControl.Visible = true
		glControl.KeyDown += HandleKeyDown

		Controls.Add(glControl)

		//the "self" is always optional:
		self.AutoScaleBaseSize = System.Drawing.Size(5, 13)
		self.ClientSize = System.Drawing.Size(292, 273)
		self.Name = 'MainForm'
		self.Text = 'NeHe Boo Example'
		ResumeLayout(false)

	protected override def OnLoad(e as EventArgs):
		super(e)
		InitGL()

	protected override def OnResize(e as EventArgs):
		super(e)
		ResizeGL(glControl.Width, glControl.Height)

	def Run(): //main loop
		while Created:
			Invalidate(true)
			DrawGL()
			Application.DoEvents()

	protected override def Dispose(disposing as bool):
		if disposing:
			if components != null:
				components.Dispose()
		super(disposing)

	private def HandleKeyDown(sender, e as KeyEventArgs):
		if e.KeyCode == Keys.Escape: //char type will be in boo soon
			Close()

	private def InitGL():
		glControl.InitializeContexts()
		OnResize(null)

	private def ResizeGL(w as int, h as int):
		Gl.glViewport( 0, 0, w, h)
		Gl.glMatrixMode ( Gl.GL_PROJECTION )
		Gl.glLoadIdentity()
		Glu.gluPerspective( 60.0, cast(double,w) / h, 1.0,1000.0)
		Gl.glMatrixMode ( Gl.GL_MODELVIEW )
		Gl.glLoadIdentity()

	///////////////////// Drawing code ///////////////////////////
	private _lastMs = 0
	private _angle = 0.0

	private def DrawGL():
		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

form.Show()
form.Run()

Labels

 
(None)
  1. Sep 06, 2005

    Alexander Rødseth says:

    How to get started with OpenGL and Boo in Debian First of all, install the "mon...

    — How to get started with OpenGL and Boo in Debian —

    First of all, install the "monodevelop-boo" and "subversion" packages.

    Then, fire off the following commands:

    svn co svn://mono.myrealbox.com/source/trunk/tao tao
    (Download Tao into a directory named tao).

    cd tao
    (Enter the Tao-directory).

    make mono-1.1 || sensible-pager BUILDING.txt
    (Make the config or read documentation if it didn't work).

    make
    (Build Tao. There will be lots of error-messages, which is fine).

    cd .. && mkdir myboo && cd myboo
    (Create a nice directory for playing around with).

    cp ../tao/dist/bin/* .
    (Copy all the Tao-libraries here. This is all we need).

    Save the cube.boo program (on this page: http://boo.codehaus.org/Opengl+3D+Samples) as cube.boo in your myboo-directory:

    Okay. Now you've got the dll-files you need to use OpenGl with Boo and a sample application.
    Compile the appplication like this:

    booc cube.boo -r:Tao.FreeGlut.dll -r:Tao.OpenGl.dll -r:Tao.OpenGl.Glu.dll

    The -r options are for making the dll-files available for your program.

    Now, you can run your very first OpenGl program in Boo with Mono:

    mono cube.exe

    Or even just:

    ./cube.exe

    If you get a black window with some white lines then you're all set. Congratulations!
    You can even resize the window, just to see that the white lines are resized too.

    Now, get hold of some OpenGL-tutorials, and it's all downhill from here.

    If you should get errors that look like the following, on some other OpenGL-application:
    nehe.boo(14,8): BCE0021: Namespace 'System.Windows.Forms' not found, maybe you forgot to add an assembly reference?
    nehe.boo(15,8): BCE0021: Namespace 'System.Drawing' not found, maybe you forgot to add an assembly reference?

    You can try to add -r:System.Windows.Forms or -r:System.Drawing, but at the time of writing, these parts are still unfinished in Mono.
    Here's the status of System.Windows.Forms: http://www.go-mono.com/winforms.html

    I can't wait to see your first complete game or application that uses OpenGL and Boo. Good luck!