About the glew extension Library

Source: Internet
Author: User

Why did I find the extension libraries such as glew during initialization? Good, Mark.

Link: http://hi.baidu.com/shenzhairen/blog/item/c3632a3a1e01c5c8d56225c8.html

====================================

 

Glew is a cross-platform C ++ extension Library Based on OpenGL graphical interfaces. All those who use OpenGL know that Windows currently only supports the Han numbers of opengl1.1, but OpenGL is now more than 2.0. To use these advanced OpenGL features, you must download the latest extensions. In addition, different video card companies will also release some extension functions that are supported only by their own graphics cards. If you want to use these extensions, you have to find the latest glext. h. With the glew extension library, you no longer have to worry about finding function interfaces, because glew can automatically identify all the OpenGL advanced extensions supported by your platform. That is to say, if you include a glew. h header file, you can use the full function of GL, Glu, glext, WGL, and Glx. Glew supports various popular operating systems (including windows, Linux, Mac OS X, FreeBSD, Irix, and Solaris ).

Project home: http://glew.sourceforge.net/
Document address: http://glew.sourceforge.net/install.html
: Https://sourceforge.net/project/downloading.php? Group_id1_67586&filename=glew-1.5.1-src.zip

========================================================== ========================================================== ========================================================== ======================================

In OpenGL programming, use glmultitexcoord2f (gl_texture0 + I, x, y); you will find that this function is not defined, and gl_texture0, this constant. In the VC compiler, the version of OpenGL is 1.1, and the version is relatively backward. The next glew library is enough.

The installation steps are the same as those of GLUT. Place the DLL dynamic link library in C:/Windows:/system32;

Header file. You can search for GL. h, or gluax. h, you will find that in the installation path of the compiler (VC), put the glew in the VC:/platformsdk:/include/GL folder and it will be OK.

Put the static library lib file in the VC:/platformsdk:/lib file.

If glew is used but an error such as: XXX function is not defined, you can add the following at the beginning of the file: # pragma comment (Lib, "glew32.lib ")

There is another problem: Check the glew. h file and you will find the following:

# If defined (_ gl_h _) | defined (_ gl_h __)

# Error Gl. h encoded ded before glew. h

# Endif

The Gl. h file cannot be referenced before glew. Otherwise, the following error occurs: Gl. h encoded ded before glew. h.

 

: Http://glew.sourceforge.net/

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/jisdy/archive/2008/07/29/2730432.aspx

 

========================================================== ========================================================== ============================================

OpenGL extension wrangler Library ()

Http://glew.sourceforg.net

I really don't know what wrangler should mean here, but he has already been included in the OpenGL SDK. It is officially recommended.

What is the use of glew? You can regard it as the basic library of OpenGL on windows, which replaces the original GL. h WGL. h, so that you can easily call the latest OpenGL functions, including the extension of OpenGL.

In fact, I am confused about this OpenGL system. Apart from the core concepts and functions, I am basically confused about the extended functions. This is why I want to read the source code of glew. It seems silly to read the source code, but it is much smarter than waiting for others to publish a book.

Let's get started.

Basic features:
  • Cross-Operating System
  • Supports Dynamic Links and static libraries. You can also copy glew. C to a project for compilation.
  • Only depends on opengl32.dll and kernel32.dll
  • Because it does not depend on the CRT, and you use single-threaded, multi-threaded, or multi-threaded DLL.
File structure:

The released version includes a glew32.dll and the corresponding glew32.lib, header files glew. h and wglew. h. (Windows dll version ). The source file has only one glew. C.

Basic use of glew:

Initialization

# Include <Gl/glew. h> is referenced before all Gl-related header files.

Glenum err = glewinit (); If err is true, Initialization is completed, and it should be placed at the beginning of the program. I still don't understand why operations can be performed before initialization.

Check Extension

If (glew_arb_vertex_program)
{
/* The arb_vertex_program extension check is passed .*/
Glgenprogramsarb (...);
}

If (glew_version_1_3)
{
/* The OpenGL 1.3 is supported */
}

If (glewissupported ("gl_version_1_4 gl_arb_point_sprite "))
{
/* Both pass the check */
}

If (glewgetextension ("gl_arb_fragment_program "))
{
/* Check that arb_fragment_program is supported .*/
}

Glew compiled a lot of code to implement the extended check function. In a simple view, macro tags and string queries are supported.

Source code structure of glew. h:

Check whether there are any libraries that conflict with glew at the beginning.

# If defined (_ gl_h _) | defined (_ gl_h __)
# Error Gl. h encoded ded before glew. h
# Endif
# If defined (_ glext_h _) | defined (_ glext_h _)
# Error glext. h encoded ded before glew. h
# Endif
# If defined (_ gl_ati_h _)
# Error glati. h encoded ded before glew. h
# Endif

The functions of these files are the same as those of glew, and all files are blocked at the beginning.

The next bunch of macros are just to correctly define glewapi glapientry callback and so on. These definitions have already been defined in other header files. For example, wingdiapi is defined in winnt. h. This is just to ensure the purity of glew, in order not to rely on any unnecessary libraries and header files.

The following is the definition of opengl1.1. Here it is simple to define the type and Macro. The API uses the external function method, which is why Gl. H is not required.

# Define glew_version_1_1 glew_get_var (_ glew_version_1_1)

The only thing that is confusing is that after parsing all macros, glew_version_1_1 is defined as a glboolean variable. Then it is annoying to initialize _ glew_version_1_1 to gl_false. Then, the author assigned a value of glew_version_1_1 to true after detecting that glew_version_1_1 is supported. It's depressing to go with Macro. However, it makes sense to think about it. glew_version_1_1 must be a macro as the detection mark, and the macro cannot modify the value. Since it may be true or false, there is only one way, find a variable as its storage space, and then this macro can be used as a variable.

Next, # include <Gl/Glu. h>

The following is the definition of opengl1.2, which is similar to that of 1.1, but the function definition method is different.

Typedef void (glapientry * cursor) (glenum target, glint level, glint xoffset, glint yoffset, glint zoffset, glint X, glint y, glsizei width, glsizei height );
Typedef void (glapientry * pfngldrawrangeelementsproc) (glenum mode, gluint start, gluint end, glsizei count, glenum type, const glvoid * indices );
Typedef void (glapientry * pfnglteximage3dproc) (glenum target, glint level, glint internalformat, glsizei width, glsizei height, glsizei depth, glint border, glenum format, glenum type, const glvoid * pixels );
Typedef void (glapientry * cursor) (glenum target, glint level, glint xoffset, glint yoffset, glint zoffset, glsizei width, glsizei height, glsizei depth, glenum format, glenum type, const glvoid * pixels );

# Define glcopytexsubimage3d glew_get_fun (_ glewcopytexsubimage3d)
# Define gldrawrangeelements glew_get_fun (_ glewdrawrangeelements)
# Define glteximage3d glew_get_fun (_ glewteximage3d)
# Define gltexsubimage3d glew_get_fun (_ glewtexsubimage3d)

The four function pointer definitions correspond to four define statements, and the names are exactly the same, but they are not the same. However, this code can be found at the end of the file.

Glew_fun_export pfnglcopytexsubimage3dproc _ glewcopytexsubimage3d;
Glew_fun_export pfngldrawrangeelementsproc _ glewdrawrangeelements;
Glew_fun_export pfnglteximage3dproc _ glewteximage3d;
Glew_fun_export pfngltexsubimage3dproc _ glewtexsubimage3d;

Four, too. Now it's the correct number. Pfnglcopytexsubimage3dproc is a function pointer type definition _ glewcopytexsubimage3d is a actually defined pointer function. # define glcopytexsubimage3d glew_get_fun (_ glewcopytexsubimage3d) points to glcopytexsubimage3d. Finally, glcopytexsubimage3d is the real API interface. Really hard.

Next we went down to 1.3, 1.4, 1.5, 2.0, and 2.1. the structure was exactly the same as that of 3.0.

Then there are various extensions, which are in the same form as those defined in 1.2.

The next step is glew_fun_export pfnglcopytexsubimage3dproc _ glewcopytexsubimage3d.

Go down to glew_var_export glboolean _ glew_version_1_1; and so on.

Finally, it is the main function interface of glew. Here a glew_mx definition is supported, that is, the support for glew MX.

Source code structure of glew. C:

Relatively simple, except for some functions, they are all initialization functions.

All started from glewinit and initialized each version and all extensions along the way.

Wglew

You don't need to talk about the above. It's better than watching the gourd.

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.