一个用 opengl 开发的雪花动画


应用VS2010及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

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件       10745  2006-08-31 00:04  ChildView.cpp
     文件        2404  2012-02-27 14:37  ChildView.h
     目录           0  2012-04-02 08:29  ipch
     目录           0  2012-04-02 08:29  ipchsnowworld-8858a476
     文件    69861376  2012-04-02 08:29  ipchsnowworld-8858a476snowworld-45f7a5.ipch
     文件        2558  2006-08-22 23:15  MainFrm.cpp
     文件        1639  2006-08-20 00:48  MainFrm.h
     文件        3590  2006-08-20 00:48  ReadMe.txt
     目录           0  2012-02-27 14:24  res
     文件         657  2006-08-30 22:31  Resource.h
     目录           0  2012-02-27 14:24  resData
     文件      196662  1999-12-21 20:20  resDataSnowFloor.bmp
     文件       12342  1999-12-21 22:25  resDataSnowLarge.bmp
     文件       12342  1999-12-21 22:26  resDataSnowMiddle.bmp
     文件       12342  1999-12-21 22:26  resDataSnowSmall.bmp
     文件      115119  1997-06-03 05:03  resMusic.WAV
     文件        1078  2006-08-20 00:48  resSnowWorld.ico
     文件         401  2006-08-20 00:48  resSnowWorld.rc2
     文件      372756  2012-04-02 08:45  SnowWorld.aps
     文件        3910  2006-08-30 22:21  SnowWorld.cpp
     文件        4461  2006-11-27 12:59  SnowWorld.dsp
     文件         541  2006-08-20 00:48  SnowWorld.dsw
     文件        1400  2006-08-20 00:48  SnowWorld.h
     文件       58368  2012-02-27 13:55  SnowWorld.ncb
     文件      162304  2012-02-27 13:55  SnowWorld.opt
     文件        3602  2006-11-27 12:55  SnowWorld.plg
     文件         148  2006-09-22 08:49  SnowWorld.positions
     文件        6617  2006-08-31 00:13  SnowWorld.rc
     文件    56971264  2012-04-02 10:29  SnowWorld.sdf
     文件         884  2012-02-27 14:36  SnowWorld.sln
     文件       12800  2012-04-02 10:29  SnowWorld.suo
............此处省略6个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)