60 likes | 168 Views
In this guide, you will learn how to set up OpenGL in C# using the Tao Framework. Follow these simple steps: install the setup file or download the ZIP file, copy `freeglut.dll` to the `WINDOWSSystem` directory, and add the necessary references to your .NET solution. We will provide sample code for initializing a Tic Tac Toe window, handling mouse inputs, and applying basic OpenGL settings. While C# offers object-oriented programming benefits and ease of setup, be aware of the need for certain dynamic link libraries to run your application smoothly.
E N D
Using OpenGL in C# by Joshua Shelfer
Setting It Up • www.taoframework.com • Install the Setup file • Or • Download the Zip file • Open lib\win32deps and copy freeglut.dll • Paste freeglut.dll into WINDOWS\System
Getting Started • Open your .NET solution • Click Project > Add Reference • If you installed, find the three Tao GL and GLUT files under .NET tab • If not, find these dlls under the browse tab (located in the bin folder of the Zip file). Keep in mind, the dlls will have to be in the same directory as the Exe file in order for it to run. • Tao.Freeglut.dll • Tao.OpenGL.dll • Tao.OpenGL.Glu.dll
Required Code • Add these lines of code • using Tao.FreeGlut; • using Tao.OpenGl;
Example Code Main function Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB); Glut.glutInitWindowSize(INITIAL_WIDTH, INITIAL_HEIGHT); Glut.glutInitWindowPosition(0, 0); Glut.glutCreateWindow("Tic Tac Toe"); Glut.glutDisplayFunc(tictactoe.display); Glut.glutMouseFunc(tictactoe.mouseHandler); Glut.glutMotionFunc(tictactoe.motionHandler); Glut.glutReshapeFunc(tictactoe.reshapeHandler); Init function Gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); Gl.glColor3f(0.0f, 0.0f, 0.0f); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Glu.gluOrtho2D(0.0, 50.0, 0.0, 50.0); Gl.glMatrixMode(Gl.GL_MODELVIEW);
Pros and Cons • Pros: • Inherent benefits of C# • OOP • Easy to set up • Cons: • Gl., Glut., And Glu. can be cumbersome to type • User must have freeglut.dll in WINDOWS\System folder