《基于MFC的OpenGL编程》Part 1 A Primer

本文介绍了3D图形学的基本概念,包括透视原理、颜色和阴影、光照和阴影效果、纹理映射、雾效、混合与透明度、抗锯齿等技术。并通过一个简单的OpenGL程序示例展示了如何在屏幕上绘制基本的3D图形。

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程序

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->//Simple.cpp-FirstOpenGLProgram
#include<windows.h>//RequiredforeveryWindowsProgram
#include<gl/glut.h>//RequiredforusingtheGLUTlibrary
//PerformOpenGLInitializationhere
voidSetupRC()
{
//Setthebackgroundclearingcolortoblue
glClearColor(0.0f,0.0f,1.0f,1.0f);//设置背景色为蓝色
}
//Thedrawingcallbackfunction
voidRenderScene()
{
//Clearthecolorbuffer
glClear(GL_COLOR_BUFFER_BIT);
//Flushtherenderingpipeline
glFlush();
}
voidmain()
{
//Choosethedisplaymodesettings
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);//初始化显示模式(单缓冲,RGB)
//CreatetheWindow
glutCreateWindow("Simple");//创建窗口
//SettheRenderScsnefunctionasthedisplaycallback
glutDisplayFunc(RenderScene);//绘制回调函数,当窗口需要绘制时,GLUT会调用此函数
//InitializeOpenGL
SetupRC();//初始化OpenGL
//StarttheGLUTframework
glutMainLoop();//开始消息循环
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值