OpenGL development tour. NET platform Configuration

Source: Internet
Author: User

  The previous article introduced the basic knowledge of OpenGL development. This article describes how to configure and develop OpenGL programs on the. NET platform.

In introduction. before configuring In the. NET platform, I want to introduce how to configure in the environment of VC6.0, because I used VC6.0 as the development environment and VC6.0 as a Windows server, you know.

The mainstream environment for developing OpenGL programs is Visual Studio, Broland C ++ Builder, and VC6.0 development environment. The following describes the configuration method in VC6.0.

 

  1. VC6.0 Configuration

  Configuration File in Windows:/Files/hanyonglu/OpenGL/OpenGL.rar

 

Download the file, decompress it, and find the address where VC6.0 is installed. My VC6.0 installation address is: d: \ Program Files \ Microsoft Visual Studio \ VC98 \ include \

(1) check whether there is a folder named "gl" under the include folder. If not, create it directly. Copy the extracted GLUT. h file to the gl folder.

(2) Put the decompressed Files glut. lib and glu32.lib in the folder where the static library is located, that is, under the d: \ Program Files \ Microsoft Visual Studio \ VC98 \ lib directory.

(3) Place the extracted glut. dll and glu32.dll In the system32 folder under the operating system directory, that is, in the C: \ Windows \ System32 directory.

 

  Then we need to open VC6.0 to create a project, and a Win32 Console Application needs to be created during the creation, and the corresponding settings are also required here:

(1) Link OpenGL libraries: click Project in Visual C ++, click Settings, find Link, and add opengl32.lib glu32.lib Glaux at the beginning of Object/library modules. lib glu32.lib.

(2) Click the C/C ++ label in Project Settings and change _ CONSOLE in Preprocessor definitions to _ WINDOWS. Click OK.

(3) introduce the header file: # include <gl/glut. h>

 

In this way, after the configuration in VC6.0 is complete, we can use VC6.0 to start our OpenGL development journey.

 

  2. Visual Studio2010 Configuration

Next let's take a look at the configuration in the. NET platform. The development of OpenGL programs in. NET has brought a lot of convenience to our. NET developers. We do not have to use the VC6.0 environment to make brilliant graphics programs.

As for. NET development of OpenGL programs, I currently know several solutions, mostly using third-party libraries. The following are some of the solutions.

Solution 1: directly call the OpenGL function library

  Using this solution, we can use C # To Call OPENGL32.DLL, GLU32.DLL, And the GLU32.DLL class library, that is, to directly call the program in the following code format:

// OpenGL constant Declaration public const uint GL_COLOR _ BUFFER _ BIT = 0x0004; public const uint GL_MODELVIEW = 0x1700; public const uint GL_PROJECTION = 0x1701; // function entry declaration [DllImport ("opengl32.dll")] public static extern void glClear (uint mask); [DllImport ("opengl32.dll")] public static extern void glBegin (uint mode); [DllImport ("opengl32.dll")] public static extern void glEnd ();

 

There are hundreds of functions in OpenGL. If we use this method to write OpenGL programs, it is really a complicated lock, so this solution is rarely used in. NET. You can understand this solution without using it.

 

  Solution 2: Use SharpGL to expand the library

  SharpGL is an extension library that allows us to easily use OpenGL in Windows Forms and WPF. It can set a powerful scenario diagram and Visual Studio template. We use it to easily develop 3D graphics programs or port code to other platforms.

It is an extension library excited by. NET developers. Let's take a brief look at some excellent graphics programs developed using it, as shown below:

  

  

The radial blur example shows how to create advanced lighting effects.

 

  

This is a WPF example of a Utah teapot. Use OpenGL to render a WPF application. SharpGL OpenGLControl provides an OpenGL rendering surface directly on your application.

  

  

This is an example of texture effect. Using this extension library, you can accelerate the development of texture functions such as OpenGL for loading and converting image data into OpenGL textures.

  

  

This is an impact test example.

 

The above are some graphical examples developed using SharpGL. What functions does SharpGL provide?

SharpGL is an extension library that allows us to use OpenGL functions in code. Namespaces include:

(1) SharpGL: contains the main OpenGL object, which encapsulates all OpenGL functions, enumerations, and extensions.

(2) SharpGL. SceneGraph: contains all the elements in the packaged OpenGL objects and scenes-lighting, materials, textures, materials, etc.

(3) SharpGL. WinForms: Contains Windows Form Controls for our applications.

(4) SharpGL. WPF: contains the WPF control for our applications.

(5) SharpGL. Serialization: Contains classes for loading ry and data from 3D Studio Max files, unnoticeable obj files, and trueSpace files.

  

In these extension libraries, SharpGL encapsulates all current OpenGL functions, all major extensions, and a set of advanced functions. We can use SharpGL to execute traditional OpenGL plotting, or use scene graphs to implement more specific tasks of applications.

 

Since SharpGL is an excellent extension library, how can we use SharpGL to develop our OpenGL program?

If we see the OpenGL program code implemented in C language, for example, the following code:

// Set the line width and point size glLineWidth (3.0f); glPointSize (2.0f );

 

Then we can use SharpGL in. NET as follows:

// Obtain an OpenGL object reference OpenGL gl = openGLCtrl1.OpenGL; // set the width and point size of the line and gl. LineWidth (3.0f); gl. PointSize (2.0f );

 

The functions in SharpGL remove gl and glu. The functions starting with gl and glu are the same.

The general rule is like this, but there are some exceptions, such as code like this:

// Set the color glColor3f (0.5f, 0.5f, 0.5f); glVertex3f (2.0f, 3.0f 4.0f); glVertex4f (2.0f, 1.0f, 10.0f, 1.0f );

 

SharpGL must be written in the following format:

// Set the gl color. color3 (0.5f, 0.5f, 0.5f); // Output some vertices. gl. vertex3 (2.0f, 3.0f 4.0f); gl. vertex4 (2.0f, 1.0f, 10.0f, 1.0f );

 

The code with parameters is as follows:

// Set the polygon mode. glPolygonMode (GL_FRONT, GL_FILL );

 

SharpGL must be written in the following format:

// Set the polygon mode gl. PolygonMode (OpenGL. GL_FRONT, OpenGL. GL_FILL );

 

Or the format is as follows:

// Set the polygon mode gl. PolygonMode (PolygonFace. Front, PolygonMode. Fill );

 

Constants in OpenGL are defined as members in the SharpGL. OpenGL class and have the same name as the original constants.

This is intended to be compatible with the OpenGL code written in the Standard C language.

  

Through some simple descriptions, we all probably know how to write code in. NET, but how to create such a project in Visual Studio? How to build such a framework?

First, download the extension library and double-click it to install it. The extension library is as follows:

 

Extension Library: Click to download

After downloading, decompress the package and double-click SharpGL. vsix. The following installation page is displayed:

  

  

  

After the installation is complete, open Visual Studio (for example, I used Visual Studio2010) and create a new project. We will see two new project templates, as shown in:

 

  

 

Select the Sharp Windows Forms Application project and click OK to create a default program. The running effect is a rotating pyramid, as shown in:

  

  

 

Similarly, if you select the SharpGL WPF Application Project, a default WPF program will be created, and the running effect is the same as above.

This extended library feels good, because it may be easy to port the graphics program in the VC6.0 environment, and can be used by interested friends.

  

Solution 3: Use the CsGL Library

  CsGL library is also a very good library, detailed information about this library Interested friends can view: http://csgl.sourceforge.net/index.html

 

CsGL provides two key dll: csgl. dll and csgl. native. dll. Copy the two dll files to the C: \ Windows \ System32 directory and reference them in the program.

Add the namespace using CsGL. OpenGL to the program code;

 

Download the CsGL Library:/Files/hanyonglu/OpenGL/csgl.1.4.1.dll.zip

Download the CsGL document:/Files/hanyonglu/OpenGL/csgl.1.4.1.doc.zip

 

The use of CsGL is still quite large. I will not detail details about the CsGL library. If you are interested, please check the official documentation directly.

 

  Solution 4: Use the OpenTK framework

OpenTK is a cross-platform encapsulation of OpenGL, OpanAL, and OpenCL. It can run on Windows, Linux, and MacOSX platforms. net language can be used to develop our graphics programs, it is easy to integrate into our Windows Forms, WPF or other programs.

Address for OpenTK project: http://sourceforge.net/projects/opentk/files/opentk/nightly/

The above provides some source code examples. If you have experience developing OpenGL, you can easily read the source code. If you are interested, you can study it.

 

  Solution 5: Use the Tao framework

The Tao framework is also a way for C # To use OpenGL libraries. The Tao framework encapsulates many C libraries, making it easier for us to use these library functions in C. The Tao framework is also bound to Mono, so it can be used in Linux and MacOSX.

In addition to encapsulating OpenGL libraries, the Tao framework also encapsulates other libraries, as shown in:

  

  

 

The Tao framework provides many useful libraries. These libraries have very good application examples in practice. They can not only write excellent graphics programs, but also write other programs.

:/Files/hanyonglu/OpenGL/Executable.rar

 

  Solution 6: Use the CSopenGL Library

If you are interested in this database, you can search for it online. I will not detail it here. This database is not used much.

Library:/Files/hanyonglu/OpenGL/dll.rar

 

The above is the solution and configuration method for developing OpenGL programs on the. NET platform, which facilitates our. NET developers to develop graphics programs.

 

Finally, we hope that our reposted friends can respect the author's Labor achievements and add the reposted address: http://www.cnblogs.com/hanyonglu/archive/2012/06/12/2537981.html,thank you.

  

Complete. Pai_^

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.