Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created June 18, 2013 06:55
Show Gist options
  • Select an option

  • Save ashwin/5803190 to your computer and use it in GitHub Desktop.

Select an option

Save ashwin/5803190 to your computer and use it in GitHub Desktop.
C# program that uses Tao framework to call OpenGL, GLU and FreeGLUT functions.
// C# program that uses Tao framework to call
// OpenGL, GLU and FreeGLUT functions.
//
// Steps:
// 1. Install Tao framework. Its .Net assemblies will be added to GAC.
// 2. Create an empty C# console application project in Visual Studio
// 3. Add references to Tao.OpenGL.dll and Tao.FreeGLUT.dll to the project.
// These files are in C:\Program Files (x86)\TaoFramework\bin
// 4. Paste this source code into the C# source file
// 5. Copy FreeGLUT.dll from C:\Program Files (x86)\TaoFramework\lib to
// directory of the generated EXE file
// 6. Run. You should see a grey teapot.
//
// Copyright (c) 2013 Ashwin Nanjappa
// Released under the MIT License
using System;
using Tao.OpenGl;
using Tao.FreeGlut;
namespace TaoExample
{
class Program
{
static void init_graphics()
{
Gl.glEnable(Gl.GL_LIGHTING);
Gl.glEnable(Gl.GL_LIGHT0);
float[] light_pos = new float[3] {1, 0.5F, 1};
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, light_pos);
Gl.glEnable(Gl.GL_DEPTH_TEST);
Gl.glClearColor(1, 1, 1, 1);
}
static void on_display()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glLoadIdentity();
Glu.gluLookAt(0, 0, 5, 0, 0, 1, 0, 1, 0);
Glut.glutSolidTeapot(1);
Glut.glutSwapBuffers();
}
static void on_reshape(int w, int h)
{
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Gl.glViewport(0, 0, w, h);
Glu.gluPerspective(40, w / h, 1, 100);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
}
static void Main()
{
Glut.glutInit();
Glut.glutInitWindowSize(500, 500);
Glut.glutCreateWindow("Tao Example");
init_graphics();
Glut.glutDisplayFunc(on_display);
Glut.glutReshapeFunc(on_reshape);
Glut.glutMainLoop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment