An optimized framework for using OpenGL programming in C + + Builder

Source: Internet
Author: User
Tags win32

Let's not talk about the valuable background of OpenGL and the bright future, the practicality and effectiveness alone is enough to make it the first choice for our graphics output programming. But in practical engineering applications, programmers do not need to carefully delve into the operating mechanism of OpenGL, also often do not need to master a variety of advanced effect production, the real need is the most simple use of this powerful tool to achieve the output data visualization, such as waveform, spectrum, stereo statistics, such as the display of graphs. In view of this, this paper summarizes the practical framework of OpenGL programming in C++builder. After practice, this framework is sufficient for the application of general graphics output. More complex procedures can be augmented on the basis of this framework.

In Windows environment with OpenGL programming to at least understand the following preliminary knowledge:

OpenGL itself: For general applications, we can think of OpenGL as a set of three-dimensional graphics functions that are independent of the window system and the operating system.

DC and RC: Each WIN32 application has a Device description table (Device context) referred to as DC, which includes how graphics are displayed in the window's settings (GDI) information in this device description table. Calling the OpenGL function must use the device description table to correctly output the window. The Graphical Operation description Table (Rendering context), referred to as RC, is the form of a device description table that holds some information about OpenGL and the operating system in the graphical Operation description table. A graphical Operation description table is a port that passes all OpenGL commands.

Pixel format: Pixel format defines the properties of OpenGL drawing, creating a graphical Operation description table to define the pixel format first. It is implemented by such a data structure

typedef struct TAGPIXELFORMATDESCRIPTOR
{
Word nsize//structure size
Word nversion;//version
DWORD dwflags; /pixel-Buffered bit flags
Byte Ipixeltype;//rgba mode or color index mode
byte ccolorbits;//color number
byte credbits;//rgba mode R placeholder
Byte cRe Dshift; R-bit offset
byte cgreenbits in Rgba mode g in//rgba mode
Byte cgreenshift//rgba mode G-digits offset
byte cbluebits;// Rgba mode B is occupied by
Byte Cblueshift;//rgba mode B-digit offset
byte calphabits//rgba mode the number of alpha digits
BYTE calphashift;// Alpha-bit offset
byte caccumbits//cumulative buffer Rgba Total
byte caccumredbits//cumulative buffer R-Face total
byte caccumgreenbits; Cumulative buffer G-bit total
byte caccumbluebits;//Cumulative buffer B-face total
byte caccumalphabits//cumulative buffer Alpaha Total number of bytes
byte cdepthbits; Depth buffer number
byte cstencilbits;//template buffer digits
Byte cauxbuffers//win32 does not support
byte Ilayertype;//no longer used
byte breserved; 0
DWORD Dwlayermask;//no longer used
DWORD Dwvisiblemask;//0
DWORD Dwdamagemask;//no longer used
} pixelformatdescriptor ;  

Dual buffering technology: OpenGL supports a display buffer and a non display buffer. The default scenario is that all OpenGL drawing commands are drawn in an swapbuffers buffer, and then copied to the display buffer (using the function) when the drawing is finished. Double buffering makes the image transformation smoother, which is the secret of no screen flicker in fast animations such as waveforms and so on in real time output.

Anti-aliasing technology: The actual need to draw the curve is often, because the computer to generate graphics at discrete points, the curve will be jagged, which is a phenomenon of aliasing. This phenomenon is unavoidable when drawing in a general language. Using the hybrid technique in OpenGL, the sawtooth part of the original boundary is filled with the point of low saturation to achieve anti-aliasing and smooth boundary effect.

OK, we can now enable the following program framework.

To add a private member to the class declaration of the *.h file:

Private

HGLRC HRC;

HDC HDC;

The following are the corresponding *.cpp files

First, add two included files:

#include <gl\gl.h>//programs use the core functions of OpenGL

#include <gl\glu.h>//programs use functions in the utility library

Related Article

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.