[Z] How to use OpenGL extension

Source: Internet
Author: User
If you develop OpenGL on windows Program The self-contained OpenGL library in the system is 1.1. If you want to use an OpenGL library of version 1.2 or later, you can only use OpenGL extension. Article Many, but most of them are simple, copied, and copied, and few are practical. Code I also encountered the same problem at the time. After several twists and turns, I finally found a solution and did not dare to share it with you. If anything is inappropriate, I would be grateful to you!

I. Concepts clarification

I often see people in the forum asking:

Where to downloadOpengl2.0?

in fact, for a newbie who is new to OpenGL , if it is developed on the Windows platform, this problem will certainly occur. Why? Because opengl2.0 , however, Microsoft only supports OpenGL 1.1 , 1.1 after that, Microsoft no longer supports it. Why, because Microsoft wants to develop its own DirectX . Therefore, if you want to use opengl1.1 or more functions, only OpenGL extensions can be used, these extensions are OpenGL functions developed by groups or individuals Windows opengl1.1 . So, there is no header file or library in Windows opengl2.0 file, opengl1.1 future things already exist in the form of extensions, and there is no unified standard, you can use glex , glew , Glee . Below are two common methods:

Most people encounter this problem when running the programs in hongbao, such as this function.Glblendequation, It isGl_arb_imagingA function in the extension. Therefore, before using an extension, you must first determine whether your video card supports the extension.

II. How to determine the extensions supported by the video card:

Use FunctionsGlgetstringLet's take a look at its prototype:

 
Const glubyte *Glgetstring(GlenumName)

We useGl_extensionsCall this function as a parameter to obtain all the extensions supported by the current video card, as shown below:

Const glubyte * STR = glgetstring (gl_extensions );

Cout <STR <Endl;

The extensions of the output are separated by spaces.If these extensions containGl_arb_imagingThen you can useGlblendequationThis function is now available.

Of course, onlyGLExtension. You can also useGlugetstringObtainGLUExtension.

III. Use extended functions

After judging the extensions supported by the video card, you can use the functions included in the extension. The following describes the specific methods for using the extension functions:

UseGlext

Download here:Http://graphics.ethz.ch/pointshop3d/sourcedoc/html/glext_8h-source.html)

A)Header file inclusion This file is notWindowsThe original system must be downloaded from the Internet. When using it, note that if the program still usesGLUT. hFile, you mustGlext. hPut inGLUT. hBecauseGlext. hTo useGl. h, AndGLUT. hContainsGl. hIf the order is wrong, there will be a lot of errors during compilation. The correct order is as follows:

# Include <iostream>

# Include <windows. h>

# Include <Gl/glut. h>

# Include <Gl/glext. h>

B)Get function pointer

First define the function pointer,Pfnglblendequationproc glblendequation = NULL;

Obtain the function address.,UseWglgetprocaddressFunction, note that this sentence should be addedGlblendequationThe function is valid only before the statement is used.GlblendequationDo not add them to all subprograms. Otherwise, the obtained pointer is invalid.

Glblendequation = (pfnglblendequationproc) wglgetprocaddress ("glblendequation ");

For example, you can add:

Pfnglblendequationproc glblendequation = (pfnglblendequationproc) wglgetprocaddress ("glblendequation ");

Switch (key)

{

Case 'A ':

Case 'A ':

// Note: glblendequation is a subset of gl_arb_imaging, please call glgetstring

// First to confirm whether your video card support this extension.

Glblendequation (gl_func_add );

Break;

Case's ':

Case's ':

Glblendequation (gl_func_subtract );

Break;

If the above method is troublesome, you can use the following method: I recommend this method:

1.UseGlew

GlewIt is also an extension library, includingOpenGLIn many core and extended functions, the current version is1.3.5, SupportedOpengl2.1, Which can be downloaded here:

Http://glew.sourceforge.net/

The above method may be a bit difficult. If you have downloadedGlewLibrary, you can directly use this extension, but before using it, you must first determine whether your graphics card supports this extension. The method is as follows: first, determine whether the video card supports the extension. We assume that the extension is supported,

1. Contains header filesGlew. h, Note that this is different from the above, this timeGLUT. hTo be placed inGlew. hAfter

As shown below

# Include <Gl/Glew. h>

# Include <Gl/glut. h>

Then you can directly useGlblendequationOther extensions are used in a similar way.

Finally, remember! That is to callGlewinit ();You can use the extension only after initialization, as shown below:

Glenum err = glewinit ();

If (glew_ OK! = ERR)

{

Messageboxa (null, "error", "my window", 1 );

}

In Project-> setting, open the link tab and add glew. Lib
Or add # progmma comment (Lib, "glew. lib") to the file ")

Now you can use the extension with confidence. Please continue with yourOpenGLA journey!

 

Note: The above links are links from official sites outside China. If you do not go to the Internet, I can send you a copy.

A few better onesOpenGLSite:

First: Of courseHttp://www.opengl.org/

Second: entry site:Http://www.opengl.org/wiki/index.php/Main_Page

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.