Microsoft offers less standard support, for things that compete, such as Corba (Competition for COM) and OpenGL (competitors of DirectX). However, it is not possible in c # to achieve OpenGL, there are many very good third-party libraries, and 2 are listed here. (1) csglhttp: //csgl.sourceForge.Net/index.html is a large OpenGL library with a large name, there is a stable version. The project address on the sf http://sourceforge.net/project/showfiles.php?group_id=33241. There are currently many 3D engine projects used in this library.
(2) csopenglhttp: //www.ia.hiof.no/gb/ptools/csharp/p-csharp.html has more detailed documents and examples. The project address on the sf http://sourceforge.net/project/showfiles.php?group_id=54966&package_id=49782. An example of csopengl (I compiled on VS2005) ------- form1.cs ------- # Region Using Directives
using System; using System.Collections.Generic; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using CSOpenGL; #endregion
Namespace OpenTest {Partial Class Form1: System.Windows.Forms.form {// private system.componentmodel.container component = null; private glview view;
Public form1 () {initializecomponent ();
View = new glview (); view.parent = this; view.createControl (); view.dock = dockstyle.Fill; view._onpaint = new painter ();
}
/ * Protected Override void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();} view.dispose ();} base.dispose (Disposing);} * /
Private Void Form1_Load (Object Sender, Eventargs E) {}
}
public class Painter: GLViewPainter {public Painter () {} public override void Paint (GLView view) {glViewport (0, 0, view.Width, view.Height); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (45.0f, 1.0F, 0.1F, 100.0F); Glshademodel (GL_SMOOTH);
GlclearColor (0.0F, 0.0F, 0.0F, 0.0F); GLCLEARDEPTH (1.0F); GLENABLE (GL_Depth_test); GLDEPTHFUNC (GL_LEQUN); GLHINT (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
Glclear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLmatrixMode (GL_ModelView); // DrawPheRAMID (); // DrawSphere (); DrawCube (); GLFLUSH ();}
Private void drawpyramid () {GLLoadIdentity (); gltranslatef (-0.2f, 0.3f, -4.0F); Glrotatef (45.0F, 1.0F, 1.0F, 1.0F);
Glbegin (GL_TRIANGLES);
// Front Face Triangle: Glcolor3f (1.0F, 0.0F, 0.0F); GlvertEX3F (0.0F, 1.0F, 0.0F); Glcolor3f (0.0F, 1.0F, 0.0F); GlvertEX3F (-1.0F, -1.0 F, 1.0F); Glcolor3f (0.0F, 0.0F, 1.0F); GlvertEX3F (1.0F, -1.0F, 1.0F);
// Right Face Triangle: Glcolor3f (1.0F, 0.0F, 0.0F); GlvertEX3F (0.0F, 1.0F, 0.0F); Glcolor3f (0.0F, 0.0F, 1.0F); GlvertEx3f (1.0F, -1.0F 1.0F); Glcolor3f (0.0F, 1.0F, 0.0F); GlvertEX3F (1.0F, -1.0F, -1.0F);
// back face triangle: Glcolor3f (1.0F, 0.0F, 0.0F); GlvertEX3F (0.0F, 1.0F, 0.0F); Glcolor3f (0.0F, 1.0F, 0.0F); GlvertEX3F (1.0F, -1.0F , -1.0F); Glcolor3f (0.0F, 0.0F, 1.0F); GlvertEX3F (-1.0F, -1.0F, -1.0F);
// Left face triangle: Glcolor3f (1.0F, 0.0F, 0.0F); GlvertEX3F (0.0F, 1.0F, 0.0F); Glcolor3f (0.0F, 0.0F, 1.0F); GlvertEX3F (-1.0F, -1.0 F, -1.0F); Glcolor3f (0.0F, 1.0F, 0.0F); GlvertEX3F (-1.0F, -1.0F, 1.0F); glend ();
Private void drawcube () {// enable color beding: glenable (gl_blend); glblendfunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GLLOADITITITY ();
GLTranslateF (0.0F, 0.2F, -6.0F); Glrotatef (45.0F, 1.0F, 1.0F, 1.0F);
Glbegin (GL_QUADS); // Tegner Først de Sidene Som Ikke Skal være gjennomsiktige: // The Back: Glcolor4f (1.0F, 1.0F, 0.0F, 1.0F); // Yellow GlvertEX3F (1.0F, -1.0F, - 1.0F); GlvertEX3F (-1.0F, -1.0F, -1.0F); GlvertEX3F (-1.0F, 1.0F, -1.0F); GlvertEX3F (1.0F, 1.0F, -1.0F);
// The Bottom: Glcolor4f (1.0F, 0.5F, 0.0F, 1.0F); // Orange Glvertex3f (1.0F, -1.0F, 1.0F); GlvertEX3F (-1.0F, -1.0F, 1.0F); GlvertEX3F (-1.0F, -1.0F, -1.0F); GlvertEX3F (1.0F, -1.0F, -1.0F);
// The right face: Glcolor4f (1.0F, 0.0F, 1.0F, 0.75F); // cyan glvertex3f (1.0F, 1.0F, -1.0F); GLVERTEX3F (1.0F, 1.0F, 1.0F); GlvertEx3f (1.0F, -1.0F, 1.0F); GlvertEX3F (1.0F, -1.0F, -1.0F);
// de Sidene Som Skal være gjennomsiktige: // setter depthbuffer read-only: gldepthmask (0); // The Front: Glcolor4f (1.0F, 0.0F, 0.0F, 0.75F); // red glvertex3f (1.0f, 1.0F, 1.0F); GlvertEX3F (-1.0F, 1.0F, 1.0F); GlvertEX3F (-1.0F, -1.0F, 1.0F); GlvertEX3F (1.0F, -1.0F, 1.0F);
// The top: Glcolor4f (0.0F, 1.0F, 0.0F, 0.75F); // Green GlvertEX3F (1.0F, 1.0F, -1.0F); GlvertEX3F (-1.0F, 1.0F, -1.0F); GlvertEX3F (-1.0F, 1.0F, 1.0F); GlvertEX3F (1.0F, 1.0F, 1.0F);
// The Left Face: Glcolor4f (0.0F, 0.0F, 1.0F, 0.75F); // Blue GlvertEX3F (-1.0F, 1.0F, 1.0F); GlvertEX3F (-1.0F, 1.0F, -1.0F) GlvertEX3F (-1.0F, -1.0F, -1.0F); GlvertEX3F (-1.0F, -1.0F, 1.0F); glend ();
GLDepthmask (1); GLDISABLE (GL_BLEND);
Private void DrawSphere () {float [] Ambient = {1.0F, 1.0F, 0.0F, 1.0F}; float [] Diffuse = {1.0F, 1.0F, 0.0F, 1.0F}; float [] specular = { 1.0F, 1.0F, 1.0F, 1.0F}; float [] position = {4.0F, 0.0F, 6.0F, 0.0F};
glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv (GL_LIGHT0, GL_SPECULAR, specular); glLightfv (GL_LIGHT0, GL_POSITION, position); glEnable (GL_LIGHT0); glEnable (GL_LIGHTING);
Glulookat (-4.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
INTPTR HDC = glunewquadric (); Glusphere (HDC, 2.0, 40, 40); Gludeletequadric (HDC);}}
} ------------- Program.cs -------------- # Region Using Directives
Using system.collections.gener; using system.windows.forms;
#ndregion