) q. b3 t2 V0 F& D* M8 l$ Y/ b&&&&glPushMatrix();: \( S; B" N6 P
1 K+ s# C m7 F1 J
&&&&&&&&glTranslatef(0.0f, 0.0f, -2.0f);* _/ W; ?8 x7 F! h g( t
glLightfv(GL_LIGHT0,GL_POSITION,light_position);; F$ ^6 B$ C- R
glEnable(GL_LIGHTING); & c! }" [ X; f, a/ c) K, HglEnable(GL_LIGHT0);7 F9 P$ U* q- G" O
glDepthFunc(GL_LESS);4 N G/ t( Y$ J* b/ l$ ^3 J
glEnable(GL_DEPTH_TEST);1 J% w' [( A: w/ m; w+ a& f
auxSolidSphere(1.0); $ |" o# E4 S" t, a- b5 d7 M- n- f1 g1 }# z; V) A |
&&&&glPopMatrix(); ! V4 F. ^, @' o7 d5 F* z : E) s9 I5 |0 b9 J&&&&glFinish(); , P$ v, l/ s+ p& d) _0 H" j # s+ T; E9 t( S# L# _1 b// Do not call CFrameWnd::OnPaint() for painting messages3 e# q: K$ O0 s- Z$ j' h' f
}$ O$ ]: M: l1 d+ ]% @6 x
应用程序类的定义(SimpleGLApp.h): 5 c J3 _& Z8 _; k1 ^) a#if !defined(AFX_SIMPLEGLAPP_H__3FB1AB29 T5 }' _6 T8 f_0E70_11D2_9ACA_48543300E17D__INCLUDED_)# ^$ E3 P2 M0 f; P$ Q
#define AFX_SIMPLEGLAPP_H__3FB1AB29_0E70 c* n3 ~: o0 R0 L
_11D2_9ACA_48543300E17D__INCLUDED_ ! B" ^3 R4 l7 p* g$ H # E/ L( n* a( p7 n2 ^6 R/ R" g#if _MSC_VER &= 1000- U! e: j, d" `/ } v5 n- J- ?6 q" E
#pragma once# d) F; H. i6 X" A5 E4 w. ~
#endif // _MSC_VER &= 1000 3 z5 X0 _' |2 w( P' ]9 w0 `, c// SimpleGLApp.h : header file ; r; n) z$ p3 E5 a//& ~, b$ {, e- f
#include & afxwin.h & C1 o0 h- z) Z" ^& R: @5 ^( ]5 Z
#include "OpenGLWnd.h" ( u7 G1 i0 W. P$ K9 |0 d* y0 b* }#include "resource.h" " U0 v' N: A5 Q9 }1 c4 \ , X) ]6 v/ I8 a! ]/////////////////////////////////////// : F$ e0 B, m7 a' e! j1 a- s////////////////////////////////////// 0 S9 s0 t. o! C. N1 R// CSimpleGLApp thread& x F) C `/ s( e8 J! T( v2 l4 E
+ T+ T2 C$ n9 l! [( _3 {$ Fclass CSimpleGLApp : public CWinApp8 `6 L9 R9 Z& F8 _9 n
{; x9 e: n$ t8 j1 S+ \
DECLARE_DYNCREATE(CSimpleGLApp) 5 ~ L- x4 i$ S: q& S) \public: ' @4 ?! P) R* H. y9 jCSimpleGLApp(); |7 Y( z% I; G0 Q8 u&&&// protected constructor used by dynamic creation( @8 X& B" `4 Z
) g) m- { |' m3 U+ `6 X( q+ e
// Attributes( p+ v8 v8 p. U% w0 a" k
public:& q. Q& N( ~/ b5 B
7 s: }6 E$ e1 h8 J# a2 ^; u2 R// Operations% A* U. x& |9 i' V" n
public:$ q4 G. k% J6 X; X/ o4 M
& ^6 }7 O1 g: W5 k, h# e// Overrides 3 N! _) [6 X* b. E( H// ClassWizard generated virtual function overrides5 G) K" B0 p) F* ~
//{{AFX_VIRTUAL(CSimpleGLApp)+ F# i D6 a: q9 L3 W/ m
public: 5 A- ?! _$ L. X" Ivirtual BOOL InitInstance(); ' G5 H& E) h J" d3 |8 Rvirtual int ExitInstance(); . w% g8 q1 f% T9 s% I3 h y% l! V# a//}}AFX_VIRTUAL/ m: r3 ?( @5 b1 m: s% H1 y* M
1 F8 R! _6 P# [/ b// Implementation/ Z5 Z9 V S% M; J
public:7 b1 A. Q& L# u Q0 f) O6 d
virtual ~CSimpleGLApp(); ; U2 l( u0 |% y+ l' X" e' Q$ E. v$ |3 ]6 B7 w# I# o9 W4 }
// Generated message map functions$ o& E- s V* B0 Z# q& Z0 F
//{{AFX_MSG(CSimpleGLApp)2 Z& U4 t& d5 s' v7 V
afx_msg void OnAppExit();. C" Y, \! R; b3 M( Z' b
//}}AFX_MSG5 T8 Q3 i! w Y- b$ M( v s
8 P- `- g- J7 w NDECLARE_MESSAGE_MAP(), x9 `8 c: y# e* @ C$ {6 M
}; 5 E8 F3 I7 w; U7 q7 U, D P2 E# g% a0 D" q" D! P& `
/////////////////////////////////////// ) e M' w0 O0 s7 S//////////////////////////////////////# \3 S' c4 z- u# ]9 g+ X
0 N8 }/ C* Z1 E) G4 `/ i2 x//{{AFX_INSERT_LOCATION}}6 ^- h/ q: c C$ K7 O+ {
// Microsoft Developer Studio will insert ; i; A$ Y- n( B+ [& l8 ?
additional declarations [) u+ Y' G# {/ O! nimmediately before the previous line.4 s- L/ A* ^" _+ V, ^; n4 K
5 l- b0 [( Y! v! E5 K9 N$ e; y l" H#endif // !defined(AFX_SIMPLEGLAPP_H__3FB1AB29_/ {' @" z" J/ ~* h6 o4 W: l
0E70_11D2_9ACA_48543300E17D__INCLUDED_)0 D" s! p; J" |6 d
应用程序类的实现(SimpleGLApp.cpp):/ ^2 ]. q5 L' B# J/ X, q: i5 X
// SimpleGLApp.cpp : implementation file " W; o2 Z ?+ F/ _ e3 J//0 ?' n# y, P ^! P2 l1 a
6 w- X; X# g2 `2 n( i8 Q) Y1 V3 l
#include "stdafx.h" # H1 {: R8 r5 V* n; L. C/ Q#include "SimpleGLApp.h" . C. P- X1 f D8 \+ H4 B#include "OpenGLWnd.h"& \2 U5 p4 y- l" s
- ~& O) P5 a+ X* _" F#ifdef _DEBUG7 W; E6 J3 }0 d
#define new DEBUG_NEW8 X. k; z* X& c3 g+ c* N0 X
#undef THIS_FILE 0 H' Y1 ]! {2 ]" b; w! @ _6 vstatic char THIS_FILE[] = __FILE__; * n+ z: ~, C$ i- y#endif 3 z* W8 R* M, a8 a O* R8 ?. t) r! r
///////////////////////////////////////! V2 f- ]3 k* |+ c: c, }( G' H
////////////////////////////////////// ' H1 J9 B4 h6 z// CSimpleGLApp 2 U% z+ I( ^ i* c( S' h2 ]; o1 y% M [" d
IMPLEMENT_DYNCREATE(CSimpleGLApp, CWinApp) 0 b; {( \& r- L h0 k! T5 N- J % u+ ^- b# {6 C0 w: }- n- J% F2 TCSimpleGLApp::CSimpleGLApp()% I: ^. Y& s* G% g6 I
{ _' _, w3 `2 U8 T
} 8 p: v' L' N2 v$ j* ~ 0 R1 ~$ M5 o3 p0 ^, }/ v; ]: F6 N+ x" H% wCSimpleGLApp::~CSimpleGLApp()! ?# Y. u* e2 ^" a- ? ]* f
{ # ^2 N0 E7 K# Y& [/ B& Z: A} + M" W' [: w( f4 z. M8 ~3 @* Y9 Y9 \7 `3 V7 o0 o
BOOL CSimpleGLApp::InitInstance() 4 j: ~9 _( C& j X, v{, d: ^) L( y& T* j% p
// TOD&&perform and per-thread initialization here ' Z! [. O6 P! E. pm_pMainWnd = new COpenGLWnd();1 T. P! m$ j) a: L5 D8 @" S
m_pMainWnd- &ShowWindow(m_nCmdShow);) N/ |* Y- H/ t
m_pMainWnd- &UpdateWindow(); 5 r0 Y. z( `) ^4 Q. Zreturn TRUE;3 R j% y) O0 d+ L3 E% }
} " |$ e9 k& E2 o3 U% U$ w! e5 w/ N/ `' F6 W6 j+ b2 b0 N
int CSimpleGLApp::ExitInstance() 0 [' F$ a' T! y/ `0 P. Y{ 9 E( B3 `6 l! r, l3 Mreturn CWinApp::ExitInstance(); ! d0 F5 {6 ^& t6 V} " S. H$ l: J& H, Y- j2 S( ?% p6 S- b4 X+ R, e
BEGIN_MESSAGE_MAP(CSimpleGLApp, CWinApp) 3 s5 m# B7 l0 P9 K+ o//{{AFX_MSG_MAP(CSimpleGLApp) 4 k9 [! s# I4 c& V/ [' SON_COMMAND(ID_APP_EXIT, OnAppExit)& {/ \: {- n- @% D
//}}AFX_MSG_MAP' w! a# s' D7 {: F; o0 \% ^
END_MESSAGE_MAP() 4 {5 d' C) |$ h8 q4 t7 |8 R" v, R) C9 e
/////////////////////////////////////// % R7 f, C0 k/ d7 H6 @# T0 e//////////////////////////////////////9 {8 N r2 Q- Z7 S/ p
// CSimpleGLApp message handlers/ x, O- I4 w/ ~
void CSimpleGLApp::OnAppExit() $ o$ E- m K8 p3 z2 a1 V. L2 |
{( [( E! y3 B. B, s3 T
// TOD Add your command handler code here6 K' b O% d% s, i
CWinApp::OnAppExit(); : T, @9 T0 c1 J- {$ g+ ]" [} - R! @; q7 K' j9 }8 w+ s5 p * t* J) f! b& NCSimpleGLApp SimpleGLApp;</P>