天天看點

《基于MFC的OpenGL程式設計》Part 1 A Primer

3D圖形學基本概念

Perspective

Perspective refers to the angles between the lines that lend the illusion of three dimensions.

Colors and Shading

Moving 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 Shadows

Plain 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 Mapping

With 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.

Fog

Fog is an atmospheric effect that adds haziness to objects in a scene depending on how far the objects are from the viewer.

Blending and Transparency

Blending is the combination 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.

Anti-Aliasing

Aliasing 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 anti-aliasing.

第一個OpenGL程式

複制代碼

//Simple.cpp - First OpenGL Program

#include <windows.h> //Required for every Windows Program

#include <gl\glut.h> //Required for using the GLUT library     

//Perform OpenGL Initialization here 

void SetupRC()

{

    //Set the background clearing color to blue

    glClearColor(0.0f,0.0f,1.0f,1.0f);//設定背景色為藍色

}

//The drawing callback function

void RenderScene()

    //Clear the color buffer 

    glClear(GL_COLOR_BUFFER_BIT);

    //Flush the rendering pipeline

    glFlush();

void main()

    //Choose the display mode settings

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//初始化顯示模式(單緩沖,RGB)

    //Create the Window

    glutCreateWindow("Simple");//建立視窗

    //Set the RenderScsne function as the display callback

    glutDisplayFunc(RenderScene);//繪制回調函數,當視窗需要繪制時,GLUT會調用此函數

    //Initialize OpenGL

    SetupRC();//初始化OpenGL

    //Start the GLUT framework

    glutMainLoop();//開始消息循環

本文轉自Phinecos(洞庭散人)部落格園部落格,原文連結:http://www.cnblogs.com/phinecos/archive/2008/11/04/1326648.html,如需轉載請自行聯系原作者

繼續閱讀