【正文】
e//開始消息循環(huán)}光榮在于平淡,艱巨因為漫長《基于MFC的OpenGL編程》Part 2 Setting up OpenGL on Windows 源代碼下載:GLUT//Start//初始化OpenGL//Initialize//繪制回調(diào)函數(shù),當(dāng)窗口需要繪制時,GLUT會調(diào)用此函數(shù)displayasRenderScsne//Set//創(chuàng)建窗口theGLUT_RGB)。glutInitDisplayMode(GLUT_SINGLEsettingsdisplay//Choosemain(){glFlush()。pipelinetheglClear(GL_COLOR_BUFFER_BIT)。color//ClearRenderScene(){callback//設(shè)置背景色為藍(lán)色}//ThetoclearingthevoidInitialization//PerformGLUTusing//RequiredProgramincludeevery//RequiredProgramincludeFirst2 0 0 (請您對文章做出評價)光榮在于平淡,艱巨因為漫長《基于MFC的OpenGL編程》Part 1 A Primer 3D圖形學(xué)基本概念PerspectivePerspective refers to the angles between the lines that lend the illusion of three dimensions. Colors and ShadingMoving beyond line drawing, we need to add color to create a solid object. Shading refers to the way the color is applied to the polygon. Shading can be of two types in OpenGL Flat or Smooth.Lights and ShadowsPlain solid color doesn’t offer enough realism. By applying Lighting effects we can make objects appear as they would in reality depending on their material properties and the lighting parameters. Adding a shadow further increases realism.Texture MappingWith Texture Mapping we can have wood grains, cloth textures, brick like textures etc instead of plain materials. This technique of applying an image to the surface of a polygon is called Texture Mapping. The image we use is called the Texture and the individual elements of the texture are called Texels.FogFog is an atmospheric effect that adds haziness to objects in a scene depending on how far the objects are from the viewer. Blending and TransparencyBlending is the bination of colors of objects on the screen. This effect can be used for a variety of purposes. By varying the amount each object is blended with the scene we can make objects look transparent.AntiAliasingAliasing is an effect that is visible on screen due to the fact that an image consists of discrete pixels. By carefully blending the lines with the background color we can eliminate jagged edges and give them a smooth appearance. This blending technique is called antialiasing. 第一個OpenGL程序//18,《基于MFC的OpenGL編程》Part 18 Reading objects from the OBJ File Format16,《基于MFC的OpenGL編程》Part 16 Reflection14,《基于MFC的OpenGL編程》Part 14 Quadrics 12,《基于MFC的OpenGL編程》Part 12 Creating and Using Display Lists10,《基于MFC的OpenGL編程》Part 10 Texture Mapping8,《基于MFC的OpenGL編程》Part 8 Colors光榮在于平淡,艱巨因為漫長《基于MFC的OpenGL編程》系列文章 1,《基于MFC的OpenGL編程》Part 1 A Primer2,《基于MFC的OpenGL編程》Part 2 Setting up OpenGL on Windows3,《基于MFC的OpenGL編程》Part 3 Drawing Simple 2D Shapes4,《基于MFC的OpenGL編程》Part 4 Drawing Simple 3D objects5,《基于MFC的OpenGL編程》Part 5 Transformations Rotations, Translations and Scaling6,《基于MFC的OpenGL編程》Part 6 Keyboard and Mouse Control7,《基于MFC的OpenGL編程》Part 7 Animation9,《基于MFC的OpenGL編程》Part 9 Lighting11,《基于MFC的OpenGL編程》Part 11 Blending, Antialiasing and Fog13,《基于MFC的OpenGL編程》Part 13 Creating 2D and 3D Text 15,《基于MFC的OpenGL編程》Part 15 Selection17,《基于MFC的OpenGL編程》Part 17 Shadows19,《基于MFC的OpenGL編程》Part 19 Creating a Virtual Reality Walkthrough ApplicationOpenGLforWindowsgl\forthelibraryOpenGLhereSetupRC(){//SetbackgroundcolorblueglClearColor(,)。drawingfunctionvoidthebuffer//Flushrendering}voidthemode|//初始化顯示模式(單緩沖,RGB)//CreateWindowglutCreateWindow(Simple)。thefunctionthecallbackglutDisplayFunc(RenderScene)。OpenGLSetupRC()。theframeworkglutMainLoop()。WGL – Windows的 OpenGL擴(kuò)展層 The WGL extension consists of a set of functions (wglCreateContext, wglDeleteContext etc.) and structures (such as PIXELFORMATDESCRIPTOR, GLYPHMETRICSFLOAT) etc. Thus every OpenGL implementation has a platformspecific portion which has to be set up and used according to the particular platform. 設(shè)備上下文The Windows Graphical Device Interface (GDI) is capable of drawing to screen, to memory, to printers or to any other device that provides a GDI interface layer and that can process GDI calls. GDI acplishes this by a rendering handle to the currently selected device, which is called the device context, or DC. 繪制上下文A rendering context is the OpenGL equivalent of the GDI DC. All OpenGL calls are rendered to the device through a RC. The rendering context maintains OpenGL state variables such as current background color, current color etc. just as the DC maintains GDI state variables such as current pen, current brush etc. 像素格式Pixel formats are the translation layer between OpenGL calls and the rendering operation that Windows performs. 舉個例子,若像素格式只支持很少一部分顏色值,則OpenGL在用RGB值(128,120,135)繪制一個像素時,就可能使用轉(zhuǎn)換后的值(128,128,128)來繪制. The pixel format selected essentially describes such things as how colors are displayed, depth of field resolution and what additional capabilities are supported by the rendering context created. 第一個基于MFC的OpenGL應(yīng)用程開發(fā)環(huán)境:1, 首先下載需要的GLUT頭文件,DLL和Lib文件,下載鏈接: (149 kilobytes),VC98/Include/GL下,VC9/Lib