资源简介
OpenGL实现下雪的效果,用到了纹理映射,旋转等技术,还包括背景音效的载入
代码片段和文件信息
// ChildView.cpp : implementation of the CChildView class
//
#include “stdafx.h“
#include “SnowWorld.h“
#include “ChildView.h“
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
GLfloat LightAmbient [] = { 0.5f 0.5f 0.5f 1.0f };
GLfloat LightDiffuse [] = { 1.0f 1.0f 1.0f 1.0f };
GLfloat LightPosition [] = { 0.0f 0.0f 2.0f 1.0f };
/////////////////////////////////////////////////////////////////////////////
// CChildView
CChildView::CChildView()
{
m_pClientDC = NULL;
m_lpThread = NULL;
m_nFloorIndex = 0;
}
CChildView::~CChildView()
{
if ( m_lpThread != NULL )
{
delete m_lpThread;
m_lpThread = NULL;
}
}
BEGIN_MESSAGE_MAP(CChildViewCWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if ( ! CWnd::PreCreateWindow( cs ) )
return FALSE;
cs.dwExstyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS
::LoadCursor( NULL IDC_ARROW ) HBRUSH( COLOR_WINDOW + 1 ) NULL );
return TRUE;
}
BOOL CChildView::PreTranslateMessage( MSG* pMsg )
{
if ( pMsg->message == WM_KEYDOWN && ( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_SPACE ) )
{
if ( ++m_nFloorIndex >= 3 )
m_nFloorIndex = 0;
}
return CWnd::PreTranslateMessage( pMsg );
}
int CChildView::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
if ( CWnd::OnCreate( lpCreateStruct ) == -1 )
{
TRACE0( “Failed to create the CChildView“ );
return -1;
}
m_lpThread = AfxBeginThread( Thread NULL THREAD_PRIORITY_NORMAL 0 CREATE_SUSPENDED );
ASSERT( m_lpThread );
InitOpenGL();
SetTimer( 1 50 NULL );
m_lpThread->ResumeThread();
return 0;
}
void CChildView::OnSize( UINT nType int cx int cy )
{
CWnd::OnSize( nType cx cy );
if ( cy == 0 )
cy = 1;
glViewport( 0 0 cx cy ); // Reset The Current View-port
glMatrixMode( GL_PROJECTION ); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective( 45.0f ( GLfloat ) cx / ( GLfloat ) cy 0.1f 400.0f );
glMatrixMode( GL_MODELVIEW ); // Select The Model-view Matrix
glLoadIdentity();
}
void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CBitmap bitmap;
bitmap.LoadBitmap( IDB_SNOW_FLOOR );
// TODO: Add your message handler code here
DrawOpenGLScene();
// Do not call CWnd::OnPaint() for painting messages
}
BOOL CChildView::OnEraseBkgnd( CDC* pDC )
{
UNREFERENCED_PARAMETER( pDC );
return TRUE;
}
void CChildView::OnDestroy()
{
HGLRC hrc = NU
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2006-10-10 16:45 SnowWorld
文件 10745 2006-08-31 00:04 SnowWorld\ChildView.cpp
文件 2404 2006-08-31 00:00 SnowWorld\ChildView.h
文件 2558 2006-08-22 23:15 SnowWorld\MainFrm.cpp
文件 1639 2006-08-20 00:48 SnowWorld\MainFrm.h
文件 3590 2006-08-20 00:48 SnowWorld\ReadMe.txt
目录 0 2006-09-08 14:12 SnowWorld\res
目录 0 2006-09-08 14:12 SnowWorld\res\Data
文件 196662 1999-12-21 20:20 SnowWorld\res\Data\SnowFloor.bmp
文件 12342 1999-12-21 22:25 SnowWorld\res\Data\SnowLarge.bmp
文件 12342 1999-12-21 22:26 SnowWorld\res\Data\SnowMiddle.bmp
文件 12342 1999-12-21 22:26 SnowWorld\res\Data\SnowSmall.bmp
文件 115119 1997-06-03 05:03 SnowWorld\res\Music.WAV
文件 1078 2006-08-20 00:48 SnowWorld\res\SnowWorld.ico
文件 401 2006-08-20 00:48 SnowWorld\res\SnowWorld.rc2
文件 657 2006-08-30 22:31 SnowWorld\Resource.h
文件 3910 2006-08-30 22:21 SnowWorld\SnowWorld.cpp
文件 4457 2006-08-30 22:51 SnowWorld\SnowWorld.dsp
文件 541 2006-08-20 00:48 SnowWorld\SnowWorld.dsw
文件 1400 2006-08-20 00:48 SnowWorld\SnowWorld.h
文件 148 2006-09-22 08:49 SnowWorld\SnowWorld.positions
文件 6617 2006-08-31 00:13 SnowWorld\SnowWorld.rc
文件 211 2006-08-20 00:48 SnowWorld\StdAfx.cpp
文件 1054 2006-08-20 00:48 SnowWorld\StdAfx.h
----------- --------- ---------- ----- ----
390217 24
- 上一篇:ERwin生成数据库字典
- 下一篇:OCM核心内参(OCM考试题库).pdf
评论
共有 条评论