Download - Microsoft Foundation Classes 3
![Page 1: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/1.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 1/26
80
6.5 OpenGL ProgrammingTool to Build and Display Complex 3DScenesGL ± High-End Graphics Processing 1980s ± Silicon Graphics ± User Interface Management ± UNIX and X WindowOpen GL ± International Standard
![Page 2: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/2.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 2/26
81
Core TermsModelPolygons ± Wireframe
± Shaded ± Texture-mappingNormal
TranslationRotationScaling
![Page 3: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/3.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 3/26
82
GL_LINESvoid DrawGLSquare( ) {
glBegin( GL_LINES );glVertex3f( -5.0f, 5.0f, 0.0f );glVertex3f( -5.0f, -5.0f, 0.0f );glVertex3f( -5.0f, -5.0f, 0.0f );glVertex3f( 5.0f, -5.0f, 0.0f );glVertex3f( 5.0f, -5.0f, 0.0f );glVertex3f( 5.0f, 5.0f, 0.0f );glVertex3f( -5.0f, 5.0f, 0.0f );
glEnd( );}
![Page 4: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/4.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 4/26
83
GL_POLYGONvoid DrawSquarePatch( ) {
glBegin( GL_POLYGON )glVertex3f( 5.0f, 5.0f, 0.0f );
glVertex3f( -5.0f, 5.0f, 0.0f );glVertex3f( -5.0f, -5.0f, 0.0f );glVertex3f( 5.0f, -5.0f, 0.0f );glNormal3f( 0.0f, 0.0f, 1.0f );
glEnd( );}
![Page 5: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/5.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 5/26
84
Viewing Frustrum
x
y
z
![Page 6: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/6.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 6/26
85
LightAmbient LightDiffuse Light
Specular LightLight Intensity Equation
§ yy!!
1
0])()([m
j
n j s jd aa V R K i N K I K I
![Page 7: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/7.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 7/26
86
Examples of OpenGL Light
CommandsGLfloat fLight[4] = { 1.0f, 1.0f, 1.0f,
1.0f };glLightfv( GL_LIGHT0, GL_AMBIENT, fLight );glLightfv( GL_LIGHT0, GL_DIFFUSE, fLight );glLightfv( GL_LIGHT0, GL_SPECULAR,
fLight );glEnable( GL_DEPTH_TEST );glEnable( GL_LIGHT0 );glDisable( GL_LIGHT0 );glDisable( GL_LIGHTING );
![Page 8: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/8.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 8/26
87
Object Material PropertiesColor Properties ± How much light it reflects ± How it handles specular light
± How shiny it isExample
Glfloat fMaterial[4] = { 0.0f, 0.0f, 1.0f,1.0f };
glMaterialfv( GL_FRONT,GL_AMBIENT_AND_DIFFUSE, fMaterial );
![Page 9: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/9.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 9/26
88
Translation
¼¼¼¼
½
»
¬¬¬¬
-
«
!
¼¼¼¼
½
»
¬¬¬¬
-
«
¼¼¼¼
½
»
¬¬¬¬
-
«
h
z y
x
z y
x
t t
t
z
y
x
'
'
'
11000
100010
001
![Page 10: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/10.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 10/26
89
Scaling
¼¼¼¼
½
»
¬¬¬¬
-
«
!
¼¼¼¼
½
»
¬¬¬¬
-
«
¼¼¼¼
½
»
¬¬¬¬
-
«
h
z y
x
z y
x
s s
s
z
y
x
'
'
'
11000
000000
000
![Page 11: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/11.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 11/26
90
Matrix Stack void RenderView( ) {
glPushMatrix( );DrawGLSquare( );
glPopMatrix( );glPushMatrix( );
glScalef( 0.5f, 0.5f, 0.0f );glRotatef( 45.0f, 0.0f, 0.0f, 1.0f );DrawGLSquare( );
glPopMatrix( );}
![Page 12: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/12.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 12/26
91
OpenGL Data TypesGLbyteGLubyteGLboolean
GLshortGLintGLuintGLfloat
GLdoubleGLvoidHGLRC
![Page 13: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/13.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 13/26
92
OpenGL Rendering ContextOpenGL Command
Current OpenGLRendering Context
WindowsDevice Context
![Page 14: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/14.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 14/26
93
Three Wiggle FunctionsHGLRC wglCreateContext( HDC hDC );BOOL wglDeleteContext( HGLRC hRC );BOOL wglMakeCurrent( HDC hDC,
HGLRC hRC );
![Page 15: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/15.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 15/26
94
PIXELFORMATDESCRIPTOR PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), 1,PFD_DRAW_TO_WINDOW |PFD_SUPPORT_OPENGL |PFD_DOUBLEBUFFER, PFD_TYPE_RGBA,24,
0, 0, 0, 0, 0, 0,// Color bits and shift0, 0, 0, 0, 0, 0, 0, // Alpha and accum
32, // 32-bit depth buffer0, 0, // No stencil or aux bufferPFD_MAIN_PLANE, // Layer type
0, 0, 0, 0 };
![Page 16: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/16.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 16/26
95
Integration of OpenGL and MFCCreate your basic MFC application usingthe MFC AppWizardAdd the OpenGL libraries to your project¶s
link list:OpenGL32.lib GLAux.lib GLU32.lib
Add custom view class to your projectIntegrate the custom view class to your applicationBuild your 3D scene
![Page 17: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/17.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 17/26
96
TestOpenGLSDIAdd CGLView Class to the project
# include ³ GLView.h ´
Modify the view class to inherit fromCGLView ± Search for, and replace, every mention of the
view class¶s original base class with CGLViewOnDraw( ) Handler
![Page 18: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/18.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 18/26
97
TestOpenGLMDI
MDIAdd CGLView Class to the project
# include ³ GLView.h ´
Modify the view class to inherit fromCGLView ± Search for, and replace, every mention of
the view class¶s original base class with
CGLViewOnDraw( ) Handler Proportional Display
![Page 19: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/19.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 19/26
98
Demos of OpenGL CapabilitiesGLObjectGLSceneGLTexcube
![Page 20: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/20.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 20/26
99
6.6 Playing SoundSound Effects:
.wavMIDI Music:
.mid
: - -->
![Page 21: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/21.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 21/26
100
::PlaySound( « )Project/Setting/Link ± Object/Library Modules: winmm.lib
Example:#
include <iostream.h># include <windows.h># include "mmsystem.h"int main( )
{::PlaySound("C:\\Windows\\Media\\
ding.wav", NULL, SND_SYNC );}
![Page 22: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/22.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 22/26
101
Playing MIDI by MCI# include <iostream.h># include <windows.h># include "mmsystem.h"
void main( ){MCI_OPEN_PARMS mciOpenParms;MCI_PLAY_PARMS mciPlayParms;
mciOpenParms.lpstrDeviceType ="sequencer";
mciOpenParms.lpstrElementName ="C:\\MIDI Files\\ .mid";
![Page 23: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/23.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 23/26
102
Playing MIDI by MCI (continue)DWORD mciError = mciSendCommand(NULL,
MCI_OPEN,MCI_OPEN_TYPE |MCI_OPEN_ELEMENT | MCI_WAIT,(DWORD)&mciOpenParms);
UINT deviceID = mciOpenParms.wDeviceID;mciError = mciSendCommand(deviceID,
MCI_PLAY,MCI_WAIT,(DWORD)&mciPlayParms);
if (!mciError)mciError = mciSendCommand(deviceID,
MCI_CLOSE, 0, NULL);}
![Page 24: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/24.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 24/26
103
A Sample WAVE File FormatSize inBytes Contents Comments4 ³RIFF´ One byte contains one charcter 4 400036 file size minus 8 bytes4 ³WAVE´ fccType
4 ³fmt ³ Notice the blank 4 16 WAVE format chunk is 16
bytes2 1 1 represents PCM format2 2 number of channels4 44100 Sampling rate4 176400 nAvgBytesPerSec
![Page 25: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/25.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 25/26
104
A Sample WAVE File Format(continue)
Size inBytes Contents Comments2 2 Bytes per sample
2 16 wBitsPerSample4 ³data´4 400000 size of wave dataDepends on data digitized audio data
![Page 26: Microsoft Foundation Classes 3](https://reader030.vdocuments.us/reader030/viewer/2022021323/577d38751a28ab3a6b97d7b1/html5/thumbnails/26.jpg)
8/9/2019 Microsoft Foundation Classes 3
http://slidepdf.com/reader/full/microsoft-foundation-classes-3 26/26
105
Homework#3Revise your Homework#1 program into aWindow program. Of course, you may addor reduce capabilities.