《基于MFC的OpenGL编程》Part 17 Shadows


Shadows

Conceptually drawing a shadow is quite simple. A shadow is produced when an object keeps light from a source from striking some object or surface behind the object, casting the shadow. The area on the shadowed object's surface outlined by the object casting the shadow appears dark. We can produce a shadow programatically by flattening the original object into the plane of the surface in which the object lies. The object is then drawn in black or some other color. This is a very simple method which works when casting shadows on a flat surface.

从这一篇开始将用到一个第三方库PixieLib,本文先对这个库的使用做简单介绍,后续文章中将不再赘述。

Paul DiLascia是兼职软件顾问和资深的 Web/UI 设计师。他是《Windows++: Writing Reusable Windows Code in C++》(Windows++:在 C++ 中编写可重用 Windows 代码)一书(Addison-Wesley,1992)的作者。Paul 在其业余时间里开发出了 PixieLib,可通过他的网站 www.dilascia.com 来获取该 MFC 类库。

将下载下来的源代码编译后会生成Lib目录,我们需要用到的就是Include和Lib这两个目录,当然你也可以看看它自带的Samples。由于使用的是最新PixieLib7.1版,因此接下来几篇文章都在VS2005下进行开发。

1,将Lib和Include目录拷贝到新建的MFC 项目目录下,配置如下:

1)c/c++à附加包含目录,这里加入”."include”。

2)链接器à附加库目录,这里加入”."lib”

3)输入à附加依赖项,这里加入PixieLib71.lib

2,在stdafx.h中包含进PixieLib库文件:

#include <PixieLib.h>     //Pixel Library

3,在CCY457OpenGLView类中加入下述变量:

int m_PixelFormat;    //Pixel Format
//Position and Direction
GLfloat m_PosX;
GLfloat m_PosY;
GLfloat m_PosZ;
GLfloat m_DirX;
GLfloat m_DirY;
GLfloat m_DirZ;
//Rotation
GLfloat m_xRot, m_yRot;//绕x,y轴旋转的角度,随时间不断变化
//Increment for Keyboard Control
GLfloat m_PosIncr;  //Positional Increment
GLfloat m_AngIncr;  //Angular Increment
//Angle of Camera With X Axis
GLfloat m_AngleX;
GLdouble m_texWrap, m_texFilter, m_texMode;
GLfloat m_ShadowMat[4][4];
//All Texture Names
GLuint m_Texture[4];

时间: 2024-11-08 17:28:24

《基于MFC的OpenGL编程》Part 17 Shadows的相关文章

《基于MFC的OpenGL编程》Part 19 Creating a Virtual Reality Walkthrough…

<基于MFC的OpenGL编程>Part 19 Creating a Virtual Reality Walkthrough Application 本文是整个系列文章的最后一篇,将创建一个完整的虚拟office应用程序(如图所示)来做为ending. 1,在CCY457OpenGLView类中加入下述变量,用来保存office内各个物体的显示列表 //Display List Names GLuint m_SceneList; GLuint m_ComputerList; GLuint m_

《基于MFC的OpenGL编程》Part 5 Transformations

<基于MFC的OpenGL编程>Part 5 Transformations - Rotations,Translations and Scaling Transformations - Translation, Rotation and Scaling Translation is nothing but moving along an arbitrary axis. Rotation is spinning about an arbitrary axis. Scaling is incre

《基于MFC的OpenGL编程》Part 2 Setting up OpenGL on Windows

WGL – Windows的 OpenGL扩展层 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 platform-specific portio

《基于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

《基于MFC的OpenGL编程》Part 18 Reading objects from the OBJ File Format

本文将介绍如何从Obj文件格式中创建3D对象,我们使用的是Nate Miller的obj格式加载类. This would be very useful to create large Virtual Reality applications as we could make use of the readily available 3D model files or make use of modeling tools to create these models and load them

《基于MFC的OpenGL编程》Part 15 Selection

Selection Selection is a powerful feature of OpenGL that allows you click at some position of the OpenGL window using the mouse and determine which of your objects lie beneath it. The act of selecting a specific object is called Picking. With OpenGL'

《基于MFC的OpenGL编程》Part 14 Quadrics

本文在第11篇文章的基础上,为其加入显示各种二次曲面的代码: Quadrics Every quadric has a few settings associated with it. We have to create a quadric first and then customize its settings to render the shape we want. The gluNewQuadric function creates a state variable that descr

《基于MFC的OpenGL编程》Part 13 Creating 2D and 3D Text

wglUseFontBitmaps函数 The wglUseFontBitmaps() function creates a set of bitmap display lists based on the glyphs in the currently selected font in the current DC for use in the current OpenGL RC. It basically creates a series of sequential display list

《基于MFC的OpenGL编程》Part 12 Creating and Using Display Lists

本文对第11篇文章进行修改,使用显示列表来存储渲染命令. 显示列表 OpenGL provides a facility to create a preprocessed set of OpenGL commands called a display list. Creating a display list is a straight forward process. We just have to delimit the display list code with glNewList an