[Translation]opengl Extension Tutorial 1

Source: Internet
Author: User

[Translation]opengl Extension Tutorial 1

Original Address https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/extensions.php

    • [Translation]opengl Extension Tutorial 1
      • Brief introduction
      • Detect Extensions
      • Using the extension
      • Glew Getting Started
        • Introduction to Getting Started
        • Initialize Glew
        • Detecting OpenGL Versions
        • Detect Extensions
        • Platform-specific extensions
        • Practice
Brief introduction

OpenGLThe extension is intended to use new features of the 3D graphics hardware. Hardware vendors define new functions to OpenGL to support new or enhanced existing features.

An extension created by a single vendor is "vendor-specific" (vendor-specific), and there are multiple Vendor Common window extensions "multivendor" (multi-vendor).

If "vendor-specific" or if the "multivendor" extension proves to be a good enhancement, then OpenGL Architecture Review Board (Arb is the short name of the OpenGL administration) may push it into an "ARB approved" extension (ABR approval).

If this extension is very good, then ABR it might be possible to integrate it into OpenGL's "core feature" (Core feature). A very good example is that "OpenGL Shading Language" (OpenGL shader language) is now part of the "core feature" version of OpenGL2.0 or later.

This concept makes OpenGL very powerful because the source code remains backwards compatible, and the OpenGL program that was written 10 years ago can now work.

Detect Extensions

In a valid OpenGL context, you can use glGetString(GL_EXTENSIONS) it to get a list of all the available extensions, which returns a long string separated by spaces.
All extension forms: GL_VENDOR_extension_name , VENDOR (vendor) from but not limited to the following table.

VENDOR Description
Arb ABR-approved Extensions
EXT Multi-Vendor expansion
APPLE The expansion of Apple Computer company
Ati The expansion of ATI (AMD) technology company
Hp Hewlett-Packard Company's expansion
NV Nvidia's extensions
SGIs Extension of the Silicon graphics

There are also some GL extensions that are not prefixes, which are specific to the platform. The most famous are the WGL prefixes, which are Windows platform-specific extensions. As well as GLX prefixes, which are X-window platform-specific extensions.

Using the extension

The use of extensions in C + + code is-unfortunately-is platform-specific. The address of a function (function pointer) must be retrieved from OpenGL execution, such as a hardware driver. This can be used wglGetProcAddress to retrieve under Windows.

our non-original translation here, some of OpenGL's new functions, often not directly using source code or static libraries linked to the program, but in the process of running the program to dynamically obtain a pointer to the function to invoke the function. non-original translation of the bank

In order to save a large amount of time for all extensions of function pointers and tokens to be processed on multiple platforms, there are some good open source solutions that can be used to simplify this process. One of them is GLEW that it can be http://glew.sourceforge.net. Another implementation is Glee that it can be in http://elf-stone.com/glee.php. are good ways to handle extensions and modifications, they are released under the BSD license. (Be sure to read the license details.)

Glew Getting Started

I want to use GLEW , no reason ———— glee is as good. The latest version of Glew is 1.3.5 and supports OpenGL 2.1 core features and some other new extensions.

Introduction to Getting Started

The Glew can be compiled into a static or dynamic library. If you compile to a static library, make sure to top a pre-processed variable GLEW_STATIC (under Windows). Another way is to glew.c glew.h copy and file the files directly into your code (if you are under Windows, you must also define them GLEW_STATIC ). This is my preferred approach because it makes cross-platform compilation and management easier.

You can download a simple example project for my glew+freeglut here:
Download: Opengl_extensions_tutorial.zip (Glew and Freeglut and included)

It is a virtual Studio 7.1 project. It can be converted to 8.0 (Express version or higher)
(If you create a project [or makefile] of a different platform [or compiler], please send to [email protected], I will put it here)

Initialize Glew

GLEWInitialization required. When you initialize, you must have a valid OpenGL render context available. (In most cases this means that an OpenGL window must be present and active).

GLenum err = glewInit();if (GLEW_OK != err){  // failed to initialize GLEW!}std::cout "Using GLEW Version: " glewGetString(GLEW_VERSION);
Detecting OpenGL Versions

GLEWAllows checking if OpenGL all core extensions are available for some versions (1.1, 1.2, 1.3, 1.5, 2.0, 2.1). If you have an installation OpenGL 1.3 , then the core extensions for OpenGL 1.2 and 1.1 will also be detected.

if (GLEW_VERSION_1_5){   std::cout "Core extensions of OpenGL 1.1 to 1.5 are available!\n";}
Detect Extensions

There are two ways to detect whether an extension supports: using GLEW宏 – a slower way – using the name string
GLEW macro Mode

if (GLEW_ARB_vertex_program) {   ... }

glewissupported function mode

if (glewIsSupported("GL_ARB_vertex_program")) {   ... }
Platform-specific extensions

You can also use GLEW macros to detect platform-specific extensions. or use number wglewIsSupported or glxglewIsSupported ). To use platform-specific extensions, you need to include "wglew.h" or "glxglew.h" after Inlcude "Glew.h".

if (WGLEW_ARB_pbuffer){   ... }
Practice
    1. Write a program that detects the core version installed on your computer OpenGL and prints the results to the console. (Use GLEW or Glee for this!)
    2. Gets the maximum length of the string returned by Glgetstring (gl_extensions)?

[Translation]opengl Extension Tutorial 1

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.