Windows graphics programming Basics

Source: Internet
Author: User
Tags polyline
One of the main goals of the Graphics Device Interface (GDI) is to support devices-independent graphics on output devices (such as video monitors, printers, and plotters. By isolating applications from different output device features, GDI enables Windows applications to run on any graphics output device supported by windows without any problems.
In Windows, the graphics are basically from. the functions output by the EXE module (although some of the plot functions actually have the user. EXE entry point), GDI. the EXE module calls routines in different driver files. One of them is. the DRV driver file is used to control the display screen and may have one or more
  
Other. DRV driver files are used to control the printer or plotter.
Windows GDI uses two coordinate systems. The virtual coordinate system can enable programs to be independent from specific hardware. The device coordinate system can enable close connection between programs and hardware.
GDI contains graphical operation functions that are executed within a Windows application and are device-independent. These functions generate a variety of line, body, and bitmap functions, they can be output to many different output devices. GDI allows an application to generate pens, brushes, fonts, and bitmaps for specific output operations. The following lists several commonly used functions in GDI:
· Device context Functions
  
· Elliptic and polygon Functions
· Drawing tool Functions
· Bitmap Functions
· Plotting property Functions
· Saving text emails
· Ing function.
· Coordinate functions
· Metafile Function
· Regional Functions
· Cropping (clipping) Function ·
The procedure for the window application to output a graph is as follows:
① Get the current display device of the specified window. The display device context is actually a data structure, which includes the parameters of the window and the current setting values of various graphic and text attributes, they control the output of graphics and text in the future.
② Select the user coordinate system and ing method.
③ Set the display area in the observation window and the device coordinate system in the user coordinate system.
④ Output graphics, text, and images.
⑤ Release the display device context used.
To draw a picture on a graphic output device (such as a screen or printer), you must first obtain the device context handle. This handle is provided before Windows allows the program to use the device. In the GDI function, the handle is passed as a parameter to indicate the device to be used to Windows.
The device context contains many attributes that are used when GDI works on different devices. Using these attributes, you can make GDI focus only on the starting and ending coordinates, instead of the objects
  
Attributes, such as color and background, because these are part of the device context. To modify these attributes, you only need to call a parameter to modify the attributes of the device context. The modified attributes are used in future programs. The device context is the link connecting Windows applications, device drivers, and output devices.
You can obtain the device context handle in multiple ways. The most common method is to obtain the device context when processing a message and release it before exiting the window. The general solution is as follows:
When processing the wm_paint message
Case wm_paint:
HDC = beginpaint (hwnd, & PS)
  
Endpaint (hwnd, & PS );
The data structure is as follows:
HDC hwnd;
Paintstruct pS;
In Windows. H, the data structure of paintstruct is defined.
Type struct tagpaintstruct {
HDC;
Bool ferase;
Rect rcpaint;
Bool frestore;
Bool flncupdate;
Byte rgbreserved [16];
} Paintstruct;
Among them, HDC is used to identify the explicit context, ferase indicates whether the background is repainted, rcpaint is a colored rectangle, and other fields are retained. The HDC here is the device context handle returned by beginpaint.
  
The device context handle obtained by deginpaint can be drawn only in the rcpaint rectangle pointed out by PS. The endpaint call makes this region valid.
The second method is as follows. You can use this method to obtain and release the device context and draw images in the entire user area. The images are valid in the entire user area:
HDC = getdc (hwnd );
... Drawing operations...
Releasedc (hwnd, HDC );
The following method is used to obtain and release the device context. You can draw a picture in the entire window. The image is valid throughout the window:
HDC = getwindowdc (hwnd );
... Drawing operations...
  
Releasedc (hwnd, HDC );
You can use the fourth method below to obtain and release the device context and draw images in the entire display area, which is effective within the entire display area:
HDC = createdc (lpszdriver, lpszdevice, lpszoutput, lpdata );
... Drawing operations...
Releasedc (HDC );
Here, lpszdriver points to the DOS file name of the device driver (without the extension), lpszdevice points to the dedicated device name (for example, Epson Fx-80), and lpszoutput points to the physical output media (file or output port) the DOS file name or device name. lpdata points to
  
Devmode data structure of the initial data. For example:
HDC = createdc ("display", null );
Use Screen Drawing, while:
HDC = createdc ("ibmgrx", "IBM graphics", "LPT1", null );
Output the image on the printer. The lpdata is set to the default value. You can find the initialization value in win. ini.
If you do not need to obtain the device context, that is, you do not need to operate in the device context. You only need to know the information about the device context. You can use the following statement:
Hdcinfo = createdc (lpszdriver, lpszdevice, lpszoutput, lpdata );
  
......
Detetedc (hdcinfo );
In addition, you can use device context to control the bitmap memory, as shown below:
Hdcmem = createcompatibledc (HDC)
Oeletedc (hdcmem );
A Metafile is a set of GDI calls encoded in binary form. You can create a file by obtaining the context of a Metafile device:
Hdcmeta = createmetafile (lpszfilename );
......
Hmf = closemetafile (hdcmeta );
During the validity period of the Meta File device context, any GDI call performed by hdcmeta becomes part of the Meta File. When closemetafile is called, the change of the device context handle is invalid, and the function returns the Meta File (hmf handle.
A device generally involves physical devices, such as video monitors and printers. Therefore, you need to obtain information about the device, such as the display size and color capabilities. You can call the getdevicecaps function to obtain the following information:
Nvalue = getdevicecaps (HDC, nindex );
Here, HDC identifies the device context, and nindex determines the return value. It can be one of the 28 identifiers defined in window. H. For example, nindex = driveversion, then this function returns the version number.
  
The device context attributes that really affect the Painting Process in the user area are "ing mode". The following four device context attributes are closely related to the ing mode attributes: window origin, window origin, window range, and window range.
Windows defines eight ing methods. You can call setmapmode (HDC, mapmode) to set one of the eight ing modes. HDC is used to identify the device context. nmapmode can take one of the eight values, such as mm_text, mm_lometric, and mm_himetric. After the ing mode is set, windows always uses this ing mode until the next ing mode is set. To obtain the current ing method, you can:
  
Nmapmode = getmapmode (HDC)
After the ing mode is set, the logical unit size and increment mode are defined. In the GDI drawing function, you can directly use logical numbers without considering the content, such:
Setmapmode (HDC, mm_text );
Textout (HDC, 8, 16, szbuffer, nlength)
That is to say, the text is written at the eighth pixel from the left of the user area and 16th pixels from the top side. Regardless of the ing method, all coordinates in the Windows function must be-32768 to 32767 in a signed short integer. Note that the ing method is only a device context attribute, so the only difference in the ing method is that
  
The device context handle attribute, and the handle is used as the parameter's GDI function. Therefore, a non-GDI function like getsystemmetrics will continue to return the size value in the unit of the device (pixel value.
The setpixel function of GDI can be used to draw pixels of a specific color: rgbactualcolor = setpixel (HDC, X, Y, rgbcolor). Here, HDC identifies the context of the device, and X and Y represent the coordinate of the vertex, rgbcolor is an unsigned long integer in the structure of colorref rgbcolor. The low byte is the relative brightness of the red base color, and the second byte contains the relative brightness of the green base color, the third byte contains the Relative Brightness Value of the blue base color, and the high byte must be zero. RGB functions can be used.
  
To obtain the rgbcolor.
Rgbcolor = RGB (byred, bygreen, byblue); the value range of byred, bygreen, and byblue is 0 ~ 255, indicating the brightness of red, green, and blue respectively. Given the correct parameters, setpixel returns the color closest to the required color in the color palette. You can also use the following method to obtain the color of a specific pixel: rgbcotor = getpixel (HDC, x, y); there are three main line functions: lineto, polyline, and arc. There are also five device context attributes that will affect the appearance of the line drawn by these functions: the current position of the PEN (only affects lineto), pen,
  
Background mode (which has an influence on the non-solid pen), background color (which has an influence on the opaque background mode), and rendering method. In the context attributes of these devices, the current position of the PEN affects the starting point of the draw line, the width of the pen, and other shapes of the line. The background mode affects the Template Graphics of the line drawn by the non-solid pen, the background color affects the background color of the line template. The drawing method affects the solid line, dotted line, and other line attributes. The following are typical installation steps:
MoveTo (HDC, xstart, ystart );
Lineto (HDC, xend, yend );
The above two sentences draw a straight line from (xstart, ystart) to (xend, yend.
Statement:
  
Dwpoint = getcurrentposition (HDC );
Obtain the current position of the pen. Here, the dwpoint return value is an unsigned long integer (or double long), where the low character contains the X coordinate, and the high character contains the Y coordinate. You can use the makepoint function to convert a dwpoint to a point structure;
Point = makepoint (dwpoint );
Point Type:
Typedef struct togpoint {kk1}
Int X;
Int y;
} Point;
Polyline is used to draw a line, for example:
Polyline (HDC, & PT, 5)
Connect the five points in the PT array with line segments.
  
ARC is used to draw the perimeter of an elliptic:
ARC (HDC, xleft, ytop, xright, ybottom, xstart, ystart, xend, yend); The drawn ellipse is in the upper left corner (xleft, ytop), and in the lower right corner (xright, ybottom) the rectangle of is bounded. The Arc begins at the intersection of the elliptic and (xstart, ystart) connected to the center of the elliptic. It is drawn along the cross-clockwise direction around the elliptic and ends with the elliptic and (xend, yend) the intersection of the Small and Medium-sized connections to the elliptic.
When lineto, polyline, and Arc are called, Windows uses the pen selected in the device context to draw the line. The pen determines the color, density, and type of the line, the linear type can be solid, Dot, or short.
  
(Virtual) line. The pen in the device context is called black_pen by default. No matter how the ing method selects a pen, draw a black solid line with a pixel width, black_pen is one of the three "slave pens" provided by windows, the other two are white_pen and null_pen, and null_pen is a blank pen with nothing to draw, of course, you can also create a custom pen.
You can use a handle to reference the required pen:
Hpen;
Hpen = getstockobject (white_pen );
SelectObject (HDC, Hpen );
Call getstockobject to obtain a backup pen (white_pen) handle and call SelectObject
  
Make this pen the createpen or createpenindirect function currently selected in the device context to create a "logical pen", which is just a description of the pen.
Hpen = createpen (npenstyle, nwidth, rgbcolor );
The npenstyle parameter determines whether the pen draws a solid line or a line composed of points or short strokes. This parameter can be one of the following identifiers: ps_solid, ps_dash, ps_dot, ps_dashdot, and ps_dashdot. Nwidth indicates the pen width (logical unit), and rgbcolor indicates the pen color. If the function is successfully executed, the return value identifies a logical pen. Otherwise, the return value is null.
  
There is also a way to establish the logic pen:
Typedef struct taglogpen {kk1}
Point lopnwidth;
Colorref lopncolor;
} Logpen;
The above is the definition of the logpen structure in windows. h. Lopnstyle specifies the pen type, lopnwidth specifies the pen width, and lopncolor specifies the pen color. Then, define logpen as the logpen type:
Logpen;
Reuse
Hpen = createpenlndirect (& logpen );
You can create a custom pen.
Because the pen created in the above two methods is not related to the device context, you can create multiple pens at the same time,
  
Draw images with multiple pens.
Hpenl = createpen (ps_solid, 1, 0l );
Hpen2 = createpen (ps_solid, 3, RGB (255 )),
SelectObject (HDC, hpenl)
// Lineto call
SelectObject (HDC, hpen2)
// Polyline call
Deleteobject (hpenl );
Deleteobject (hpen2 );
The padding between the dot-line pen and the short-stroke pen is determined by the background method and background color defined in the device context. The Default background method is opaque, that is, the background color is used to fill gaps.
  
The background color of the province is white. Available:
Setbkcolor (HDC, rgbcolor );
To change the background color of the fill gap. Available:
Setbkmode (HDC, mode );
To change the background mode. The mode can be opaque or transparent.
In the device context, you can set a new draw method. The ndrawmode parameter defines the draw mode. You can use the following functions to obtain the current drawing method:
Ndrowmode = getrop2 (HDC );
This method is actually used to execute a Boolean operation between the pixel of the pen and the pixel of the target display table.
The following are the six windows functions used to draw a filled area with a border:
  
Rectangle, a rectangle with a square angle
Ellipse, elliptic
Roundrect, a rectangle with a circular Angle
A chord is an arc located around an elliptic. The vertex is connected by a string.
Pie, pie wedge around the elliptical
Polygon, Polygon
Polypolygon, multiple Polygon
The image must be filled with the current brush selected in the device context, for example:
Hbrush;
Hbrush = getstockobject (gray_brush)
SelectObject (HDC, hbrush)
For rectangular filling objects, use:
Rectangle (HDC, xleft, ytop, xright, ybottom );
  
Point (xleft, ytop) is the upper left corner of the rectangle, and (xright, ybottom) is the lower right corner (both points are given in logical coordinates ). The rationality of these two coordinates must also be considered. For example, in mm_text ing mode, xright must be greater than xleft, and ybottom must be greater than ytop.
For an elliptical filling object, use:
Ellipse (HDC, xleft, ytop, xright, ybottom );
Fill the object with the rounded rectangle, using:
Roundrect (HDC, xleft, ytop, xright, ybottom, xcornerellipse, ycornerellipse );
Rgbcolor is the foreground color of the specified brush, that is, the color of the Shadow Line.
  
③ Method 3:
Hbrush = createpatternbrush (hbitmap );
This function creates a logic brush with a pattern specified by the hbitmap parameter. This brush can be used by any device supporting the grating operation. Hbitmap identifies a bitmap. This bitmap can be created using createbitmap, createbitmapindirect, loadbitmap, or createcompatiblebitmap. The minimum size of the bitmap for filling pattern is 8 × 8.
④ Method 4:
Hbrush = createbrushindirect (& logbrush)
The variable logbrush is a logbrush ("logic brush") type structure. After the logic brush is created,
  
You can use:
SelectObject (HDC, hbrush );
Send the logic to the device context. If the use is over, you can use:
Deletobject (hbrush );
Delete an existing brush. If you need to obtain information about the brush in the program, you can call:
GetObject (hbrush, sizeof (logbrush), (lpstr) & (logbrush ));
Logbrush is a logbrush-type structure.
As mentioned above, bitmap is used as the logic brush pattern, so a bitmap handle is required. The bitmap must be at least 8 pixels high and 8 pixels wide. If the bitmap is too large, Windows uses the upper left part of the bitmap as the brush. There are also four methods to obtain the bitmap handle.
① The first method to obtain the bitmap handle is:
First, use sdkpaint provided by windows to generate a bitmap file (the extension is. BMP), and
The file name is included in a bitmap statement in the resource file (. RC file), for example:
Lpszbitmap bitmap "bitmopname. BMP"
(Assume that the bitmap generated in sdkpaint is bitmapname. BMP), and then load the bitmap:
Hbitmap = loadbitmap (hinstance, lpszbitmap );
Here, hbitmap is a bitmap handle.
② The second method to obtain the bitmap handle is:
Hbitmap = createbitmop (nwidth, nheight, nplanes, nbitspixel, lpbits );
  
This function can generate a memory bitmap with a specified width, height, and bit pattern related to the device. The nwidth parameter specifies the width (in pixels) of the bitmap, The nheight parameter specifies the height (in pixels) of the bitmap, And the nplanes parameter specifies the number of color bit planes in the bitmap, each color bit plane has a nwidthxnheight xnbitspixel bit.
Nbitspixel specifies the color digits of each pixel. Lpbits points to a short integer array containing the initial bitmap bit value. Its value is similar to the bmbits value in the bitmap structure. The content about the bitmap structure is mentioned in the previous chapter.
  
③ Method for obtaining the bitmap handle:
Hbitmap = createcompatiblebitmap (HDC, nwidth, nheight );
This function generates a bitmap compatible with the device specified by the HDC parameter. This bitmap has a color bit plane or the same number of bits per pixel format with the same value as other devices. Its color information is also determined by the device specified by HDC. HDC identifies the device context. nwidth and nheight respectively specify the width and height (in bits) of the bitmap ).
④ Method for obtaining the bitmap handle:
Hbitmop = createbitmapindirect (& Bitmap ):
This function generates a bitmap with the width, height, and bitmap pattern given by the data structure specified by the lpbitmap parameter. Here, the bitmap structure is of the bitmap type.
When you have a bitmap handle, you can also call:
GetObject (hbitmap, sizeof (Bitmap), (lpstr) & Bitmap );
Bitmap is a bitmap structure.
You can also call:
Getbitmapbits (hbitmap, dwcount, lpbits );
Copy the dwcount bytes of the bitmap hbitmap to the array with the address lpbits. You can also use setbitmopbits (hbitmap, dwcount, lpbits) to place the color bits of the lpbits identifier into the bitmap of the hbitmap identifier.
  
When Windows fills an area with a brush, it uses an 8x8 bitmap in both horizontal and vertical directions, and the appearance of the brush may be slightly changed, this depends on how Windows alignment the upper left corner of the bitmap with the display surface. This alignment attribute is called the "brush origin" in the device context ". In most cases, you do not have to adjust the brush origin so precisely when drawing; but in some cases, you need to do so to produce a specific visual effect. You can perform the following steps to achieve this effect:
① Call unrealizeobject for the brush (but cannot call unrealizeobject for the backup brush );
Unrealizeobject (hobject );
  
This function indicates that GDI resets the origin of the selected brush next time.
② Use setbrushorg to set the brush origin:
Brushorg = setbrushorg (HDC, x, y );.
This function is used to set the source of the brush in the context of the current selected device. HDC identifies the device context. x specifies the X coordinate of the new origin (using the device coordinate). The value range must be 0 ~ Between 7, y specifies the Y coordinate of the new origin (using the device coordinate), the value range must be 0 ~ Between 7, this function returns a double word. The previous x coordinate is placed in the low position, and the previous y coordinate is placed in the high position.
In addition to drawing points, drawing lines, and area filling, windows also includes several additional painting functions.
  
A graph function is used to process the rect (rectangle) structure and "area". A area is a part of the screen composed of a rectangle, other polygon, and an ellipse.
Fillrect (HDC, & rect, hbrush );
This function fills the given rectangle with the selected brush. The fillrect function fills the entire rectangle, including the left and top edges, but not the right and bottom edges. HDC identifies the device context. rect is the rect data structure type, which stores the logical coordinates of the rectangle to be filled. Hbrush is used to identify the brush filled with this rectangle.
Framerect (HDC, & rect );
This function draws a border around the rectangle specified by the lprect parameter. The framerect function draws the border with a given brush. the height and width of the border are always expressed in logical units. HDC identifies the device context of the window, rect indicates the logical coordinates in the upper left and lower right corner, and hbrush indicates the brush used to draw the rectangular border. Invertrect (HDC, & rect );
This function is used to display the content of a given rectangle in the video.
The preceding rect can be obtained using the following statement:
Setrect (& rect, xleft, ytop, xright, ybottom );
An area is used to describe a part on a display that is composed of a rectangle, other polygon, and an elliptical shape. It can be drawn or cropped using an area.
Available:
Hrgn = creatergn (xleft, ytop, xright, ybottom );
  
Or
Hrgn = createrectrgnindirect (& rect );
To create a rectangular area, you can also use:
Hrgn = createllipsergn (xleft, ytop, xright, ybottom );
Or:
Hrgn = createellipsergnindirect (& rect );
To create an elliptical area. You can also use:
Hrgn = createpolygonrgn (upoint, ncount, npolyfillmode );
To create a polygon area. Use:
Hrgn = createroundrectrgn (XL, YL, X2, Y2, X3, Y3 );
(XL, Y1) indicates the upper left corner of the area, (X2, Y2) indicates the lower right corner of the area, x3 and Y3 are used to specify the width and height of the elliptical corner.
After the handles in specific regions are generated, you can also use:
Nrgntype = combinergn (hdestrgn, hsrcrgnl, hsrcrgn2, ncombine );
Create a new region by combining two existing regions. The ncombine parameters describe the method of combining regions:
Here, hsrcrgnl and hsrcrgn2 identify two existing regions, and the hdestrgn mark will be replaced by the new region as the existing region of the target.
After a region is used up, you can use deleteobject (hrgn) to delete it.
Floodfill (HDC, xstart, ystart, rgbcolor );
  
This function fills an area in the display table with the current brush. This area is assumed to be determined by the color boundary specified by most rgbcolor. The floodfill function is specified by the xstart and ystart parameters, the vertex begins to fill in all directions until the color boundary ends.
Extfloodfill (HDC, xstart, ystart, rgbcolor, wfill );
This function fills a certain area on the surface with the current brush. If wfill is set to floodfillborder,
This area uses the color set by rgbcolor as the border, and extfloodfill fills in each direction from (xstart, ystart point until the border of the color. If wfill is set to floodfillsurface,
  
The extfloodfill function fills all adjacent areas with the colors set by the rgbcolor parameter in each direction starting from the (xstart, ystart) Point.
Drowicon (HDC, xstort, ystart, hicon );
This function draws an icon on the specified device. (Xstart, ystart) is the upper left corner of the icon. hicon identifies the icon to be drawn. Like hbitmap, it can be drawn by sdkpaint. It is defined in the. RC file and obtained by loadicon.
Scrollwindow (hwnd, xscroll, yscroll, & rectscroll, & rectclip );
This function scrolls the window by moving the content of the user area of a window and moving the xscroll units along the X axis,
  
Move the yscroll units along the Y axis. rectscroll indicates the part of the content to be rolled in the user area,
Rectclip indicates the cropped rectangle to scroll.
Scrolldc (HDC, dx, Dy, lprcscroll, lprcclip, hrgnupdate, lprcupdate );
This function horizontally and vertically scrolls the rectangle composed of digits. Lprcscroll points to the rectangle to be rolled, DX indicates the horizontal scroll unit, Dy indicates the vertical scroll unit, lprcclip points to the cropped rectangle, and hrgnupdate returns the area not covered during the rolling process, lprcupdate returns the largest rectangular area to be repainted.
OpenGL is a high-performance 3D graphics standard developed in recent years. It is under the initiative of many world-renowned computer companies such as SGI, A general shared OPEN 3D graphics standard based on the GL 3D graphics library of SGI. Currently, large companies such as Microsoft, SGI, IBM, Dec, sun, and HP all adopt OpenGL as three-dimensional graphics standards, many software vendors have developed their own products based on OpenGL, among them, the famous products include soft image and 3D Studio MAX, simulation software Open Inventor, VR software World Tool Kit, CAM software proengineer, and GIS soft ARC/INFO. It is worth mentioning that, with Microsoft's introduction of OpenGL standard and OpenGL 3D Graphics Accelerator card (such as AGC-3D series 3D Graphics Accelerator card of Beijing Dawn electronic technology company) in Windows NT and the latest Windows 95, openGL will be widely used in microcomputer, and it also provides users with the opportunity to use various software that can only run on high-performance graphics workstations in the past.
OpenGL is actually an open 3D graphics software package. It is independent of the window system and operating system. applications developed based on OpenGL can be easily transplanted between various platforms; openGL can work closely with Visual C ++ to implement computation and graphics algorithms on the manipulator, ensuring the correctness and reliability of the algorithms.
OpenGL is easy to use and efficient. It has seven functions:
  
1) In addition to providing basic points, lines, and polygon drawing functions, the OpenGL Graphic Library provides complex 3D objects (such as balls, cones, polygons, and teapot) as well as complex curves and curves (such as betilles, curves, or surfaces such as OpenGL) to draw functions.
2) transform OpenGL graphics library transformations include basic transformations and projection transformations. Basic transformations include four types of transformations: translation, rotation, and ratio of variation image. projection transformations include two types: Parallel projection (also called normal projection) and Perspective Projection. The transformation method is exactly the same as the Coordinate Transformation Method in robot kinematics, which helps reduce the running time of the algorithm and increase the display speed of 3D images.
3) The color mode sets two OpenGL color modes: rgba mode and color index ).
4) OpenGL light includes emitted light, ambient light, diffuse light, and specular light ). The material is represented by light reflectivity. In scene (scene), the object eventually reflects the human eye color, which is formed after the red, green, and blue components of light are multiplied by the reflectivity of the red, green, and blue components of the material.
5) Texture Mapping (texture mapping) uses OpenGL texture ing to vividly express the surface details of objects.
6) in addition to basic copying and pixel reading and writing, the bitmap display and image enhancement functions also provide blending, antialiasing, and fog functions) special image processing. The above three items can make the simulated objects more realistic and enhance the graphic display effect.
7) Double Cache (double buffering): the front-end cache and the back-end cache. In short, the back-end cache is used for computing scenarios and screen generation. The front-end cache displays the pictures that have been cached in the back-end. In addition, OpenGL can be used to implement special effects such as depth cue and motion blur. Thus, the Blanking algorithm is implemented. There are more than 100 functions in the OpenGL graphics library. There are 115 core functions, which are the most basic functions,
  
Its prefix is Gl. the OpenGL utility Library (Glu) has more functions, such as drawing Complex Curve and surface, advanced coordinate transformation, and polygon division. There are 43 functions in total, the prefix is Glu. OpenGL auxiliary Library (Glaux) functions are some special functions, including simple window management, input event processing, and some complex 3D object rendering functions, A total of 31, prefixed with aux.
In addition, there are also six WGL functions that are very important for OpenGL and Windows 95 Window System connections. The prefix is WGL, which is mainly used to create and select a graphic operation description table (rendering contexts) and display the character bitmap at any position in the window. These functions are Windows 95's only supplement to OpenGL. In addition, there are five Win32 functions used to process the pixel format (pixel formats) and double cache. Since they are extended to Win32 systems, they cannot be applied to other OpenGL platforms.
The Design of OpenGL for Windows 95 is slightly different from that of OpenGL for Unix. The key is how to associate OpenGL with window systems under different operating systems. If you call the OpenGL helper library window management function, you do not need to consider these issues. The following briefly introduces the key of OpenGL program design in Windows 95.
  
1. Graphic operation description
In Windows 95, the window program must first process the device description table (device contexts, DC). DC includes many ways to display graphical information in the window, both specifying the color of the paint brush and brush, set drawing mode, color palette, ing mode, and other graphic attributes. Similarly, OpenGL for Windows 95 must use DC, which is similar to other Windows 95 programs. However, OpenGL forwindows 95 must process a special DC graphic operation description table, which is used by OpenGL in DC. An OpenGL graphical operation description table contains various information related to OpenGL and Windows 95 window systems. An OpenGL application must first create a graphical operation description table, then start it, and then call the OpenGL function to draw a graph in the defined window as usual. A graphical operation description table is different from other DC. Each of them requires a handle to call each GDI function, while a graphical operation description table can call OpenGL functions with only one handle. That is to say, as long as a graphical operation description table is enabled, any OpenGL function can be called to perform various operations before the graphic operation description table is deleted.
2. pixel format
Before creating a graphic operation table, you must set the pixel format. The pixel format contains the properties of the drawing interface of the device. These properties include: whether the drawing interface uses the rgba mode or the color table mode, whether the pixel cache uses a single cache or a dual cache, as well as the number of digits of color, the number of digits used by the deep cache and template cache, as well as other attributes.
3. pixel Format Structure
Each OpenGL display device supports a specified pixel format. Generally, a structure named pixelformatdescriptor is used to represent a special pixel format. This structure contains 26 attribute information. Win32 defines pixelformatdescriptor as follows:
Typedef struct tagpixelformatdescriptor
{Kk1}
// PFD
Word nsize;
Word nversion;
DWORD dwflags;
Byte ipixeltype;
  
Byte ccolorbits;
Byte credbits;
Byte credshift;
Byte cgreenbits;
Byte cgreenshift;
Byte cbluebits;
Byte cblueshift;
Byte calphabits;
Byte calphashift;
Byte caccumbits;
Byte caccumredbits;
Byte caccumgreenbits;
Byte caccumbluebits;
Byte caccumalphabits;
Byte cdepthbits;
Byte cstencilbits;
Byte cauxbuffers;
Byte ilayertype;
  
Byte breserved;
DWORD dwlayermask;
DWORD dwvisiblemask;
DWORD dwdamagemask;
} Pixelformatdescriptor;
4. initialize the pixelformatdescriptor Structure
For more information about the meanings and settings of each variable value in pixelformatdescriptor, see the following example to briefly describe the significance of related variables.
The PFD that defines the pixelformatdescriptor structure is as follows:
Pixelformatdescriptor PFD = {kk1}
Sizeof (pixelformatdescriptor),. // size of this PFD 1
  
Pfd_draw_to_window | // support window
Pfd_support_opengl | // support OpenGL
Pfd_doublebuffer, // double buffered
Pfd_type_rgba, // rgba type
24, // 24-bit color depth
0, 0, 0, 0, // color bits ignored
0, // No Alpha Buffer
0, // shift bit ignored
0, // no accumulation buff
0, 0, 0, // accum bits ignored
32, // 32-bit Z-Buffer
0, // No stencel Buffer
0, // No auxiliary Buffer
Pfd_main_plane, // main layer
0, // Reserved
0, 0 // layer masks ignored
  
};
In this structure, the meaning of the first two variables is very obvious. The value of the third variable dwflags is pfd_draw_to_window | pfd_support_opengl, indicating that the application uses the OpenGL function to draw a window.

 

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.