当前位置: 首页 > news >正文

C++ MFC SnowWorld

目录

效果

项目 

代码

下载


效果

SnowWorld

项目 

代码

// 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(CChildView,CWnd )
    //{{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 = NULL;
    hrc = ::wglGetCurrentContext();

    ::wglMakeCurrent( NULL, NULL );
    if ( hrc != NULL )
        ::wglDeleteContext( hrc );

    if ( m_pClientDC != NULL )
    {
        delete m_pClientDC;
        m_pClientDC = NULL;
    }
    ASSERT( m_pClientDC == NULL );

    CWnd::OnDestroy();
}

// Initialize the OpenGL context device...

VOID CChildView::InitOpenGL()
{
    m_pClientDC = new CClientDC( this );
    ASSERT( m_pClientDC != NULL );
    ASSERT_VALID( m_pClientDC );

    if ( ! SetupPixelFormat() )
        return;

    PIXELFORMATDESCRIPTOR pfd;

    int n = ::GetPixelFormat( m_pClientDC->GetSafeHdc());
    ::DescribePixelFormat( m_pClientDC->GetSafeHdc(), n, sizeof( pfd ), & pfd );

    HGLRC hrc = NULL;
    hrc = wglCreateContext( m_pClientDC->GetSafeHdc() );
    ASSERT( hrc );
    wglMakeCurrent( m_pClientDC->GetSafeHdc(), hrc );

    if ( ! LoadOpenGLTextures() )
        return;

    glEnable( GL_TEXTURE_2D );
    glShadeModel( GL_SMOOTH );                // Enable Smooth Shading
    glClearColor( 0.5f, 0.5f, 0.5f, 0.5f );    // Black Background
    glClearDepth( 1.0f );                    // Depth Buffer Setup

    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );    // Really Nice Perspective Calculations

    glLightfv( GL_LIGHT1, GL_AMBIENT,  LightAmbient  );
    glLightfv( GL_LIGHT1, GL_DIFFUSE,  LightDiffuse  );
    glLightfv( GL_LIGHT1, GL_POSITION, LightPosition );
    glEnable( GL_LIGHT1 );

    glBlendFunc( GL_SRC_ALPHA,GL_ONE );        // Set The Blending Function For Translucency
    glEnable( GL_BLEND );    
}

// Load the texture from the define file path

BOOL CChildView::LoadOpenGLTextures()
{
    glGenTextures( E_TEXTURECOUNT, & m_textureSnow[ 0 ] );
    LoadImageFromResID( IDB_SNOW_LARGE,  m_textureSnow[ 0 ] );
    LoadImageFromResID( IDB_SNOW_MIDDLE, m_textureSnow[ 1 ] );
    LoadImageFromResID( IDB_SNOW_SMALL,  m_textureSnow[ 2 ] );

    InitSnow();

    LoadImageFromResID( IDB_SNOW_MIDDLE, m_textureSnow[ 3 ] );

    return TRUE;
}

VOID CChildView::SetDefaultTextureParams()
{
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

BOOL CChildView::SetupPixelFormat()
{
    static PIXELFORMATDESCRIPTOR pfd = {
        sizeof( PIXELFORMATDESCRIPTOR ),// size of this pfd
        1,                              // version number
        PFD_DRAW_TO_WINDOW |            // support window
        PFD_SUPPORT_OPENGL |        // support OpenGL
        PFD_DOUBLEBUFFER,           // double buffered
        PFD_TYPE_RGBA,                  // RGBA type
        24,                             // 24-bit color depth
        0, 0, 0, 0, 0, 0,               // color bits ignored
        0,                              // no alpha buffer
        0,                              // shift bit ignored
        0,                              // no accumulation buffer
        0, 0, 0, 0,                     // accum bits ignored
        32,                             // 32-bit z-buffer
        0,                              // no stencil buffer
        0,                              // no auxiliary buffer
        PFD_MAIN_PLANE,                 // main layer
        0,                              // reserved
        0, 0, 0                         // layer masks ignored
    };

    int pixelformat = 0;

    ASSERT( m_pClientDC != NULL );
    if ( ( pixelformat = ChoosePixelFormat( m_pClientDC->GetSafeHdc(), & pfd ) ) == 0 )
    {
        AfxMessageBox( _T( "ChoosePixelFormat failed" ) );
        return FALSE;
    }

    if ( SetPixelFormat( m_pClientDC->GetSafeHdc(), pixelformat, & pfd ) == FALSE )
    {
        AfxMessageBox( _T( "SetPixelFormat failed" ) );
        return FALSE;
    }

    return TRUE;
}

VOID CChildView::DrawOpenGLScene()
{
    static GLfloat wAngleY = 10.0f;

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glLoadIdentity();
    glTranslatef( 0.0f, -30.0f, -150.0f );
    glRotatef( wAngleY, 0.0f, 1.0f, 0.0f );

    glBindTexture( GL_TEXTURE_2D, m_textureSnow[ m_nFloorIndex ] );

    glColor4f( 1.0f, 1.0f, 1.0f, 0.5 );

    glBegin( GL_QUADS );
    glNormal3f( 0.0f, 1.0f, 0.0f );
    glTexCoord2f( 0.0f, 0.0f ); glVertex3f(  100.0f, 0.0f, -100.0f );
    glTexCoord2f( 1.0f, 0.0f ); glVertex3f(  100.0f, 0.0f,  100.0f );
    glTexCoord2f( 1.0f, 1.0f ); glVertex3f( -100.0f, 0.0f,  100.0f );
    glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -100.0f, 0.0f, -100.0f );
    glEnd();

    for ( int nIndex = 0; nIndex < E_SNOWCOUNT; nIndex++ )
    {
        glLoadIdentity();
        glTranslatef( 0.0f, -30.0f, -150.0f ); 
        glRotatef( wAngleY, 0.0f, 1.0f, 0.0f );

        glBindTexture( GL_TEXTURE_2D, m_textureSnow[ m_snow[ nIndex ].nIndexTexture ] );
        glTranslatef( m_snow[ nIndex ].x, m_snow[ nIndex ].y, m_snow[ nIndex ].z );

        glRotatef( m_snow[ nIndex ].xrot, 1.0f, 0.0f, 0.0f );
        glRotatef( m_snow[ nIndex ].yrot, 0.0f, 1.0f, 0.0f );
        glRotatef( m_snow[ nIndex ].zrot, 0.0f, 0.0f, 1.0f );

        glBegin( GL_QUADS );
        glNormal3f( 0.0f, 1.0f, 0.0f );
        glTexCoord2f( 0.0f, 0.0f ); glVertex3f(  1.0f, 0.0f, -1.0f );
        glTexCoord2f( 1.0f, 0.0f ); glVertex3f(  1.0f, 0.0f,  1.0f );
        glTexCoord2f( 1.0f, 1.0f ); glVertex3f( -1.0f, 0.0f,  1.0f );
        glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 0.0f, -1.0f );
        glEnd();

        m_snow[ nIndex ].y -= m_snow[ nIndex ].dropSpeed;
        if( m_snow[ nIndex ].y < -33 )
            m_snow[ nIndex ].y = 125.0f;

        m_snow[ nIndex ].xrot += m_snow[ nIndex ].rotSpeed;
        m_snow[ nIndex ].yrot += m_snow[ nIndex ].rotSpeed;
        m_snow[ nIndex ].zrot += m_snow[ nIndex ].rotSpeed;
    }

    wAngleY += 0.2f;

    glFinish();
    SwapBuffers( wglGetCurrentDC() );
}

BOOL CChildView::LoadImageFromResID( UINT nResID, GLuint& texture )
{
    ASSERT( nResID > 0 );

    HBITMAP hBitmap = ( HBITMAP ) LoadImage( \
        AfxGetInstanceHandle(), \
        MAKEINTRESOURCE( nResID ), \
        IMAGE_BITMAP, \
        0, 0, \
        LR_CREATEDIBSECTION );
    ASSERT( hBitmap != NULL );

    DIBSECTION ds;
    GetObject( hBitmap, sizeof( DIBSECTION ), ( LPVOID ) & ds );

    glBindTexture( GL_TEXTURE_2D, texture );
    SetDefaultTextureParams();

    glTexImage2D( GL_TEXTURE_2D, 0, 3, ds.dsBm.bmWidth, ds.dsBm.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, ds.dsBm.bmBits );
    DeleteObject( hBitmap );

    return TRUE;
}

void CChildView::OnTimer(UINT_PTR nIDEvent )
{
    DrawOpenGLScene();

    CWnd::OnTimer( nIDEvent );

    // Eat spurious WM_TIMER message
    MSG msg;
    while( ::PeekMessage( & msg, m_hWnd, WM_TIMER, WM_TIMER, PM_REMOVE ) )
        ;
}

VOID CChildView::InitSnow()
{
    srand( GetTickCount() );

    for ( int nIndex = 0; nIndex < E_SNOWCOUNT; nIndex++ )
    {
        m_snow[ nIndex ].nIndexTexture = rand() % 3;

        m_snow[ nIndex ].x = GLfloat( rand() % 200 - 100 );
        m_snow[ nIndex ].y = GLfloat( rand() % 200 - 100 );
        m_snow[ nIndex ].z = 100.0f + GLfloat( rand() % 25 );
    }

    for ( int i = 0; i < E_SNOWCOUNT; i++ )
    {
        m_snow[ i ].nIndexTexture = rand() % 3;
        m_snow[ i ].x             = GLfloat( rand() % 200 - 100 );
        m_snow[ i ].z             = GLfloat( rand() % 200 - 100 );
        m_snow[ i ].y             = 100.0f + GLfloat( rand() % 25 );

        m_snow[ i ].xrot          = 0;
        m_snow[ i ].yrot          = 0;
        m_snow[ i ].zrot          = 0;

        m_snow[ i ].dropSpeed     = 0.01f * ( rand() % 50 + 2 );
        m_snow[ i ].rotSpeed      =  0.1f * ( rand() % 10 + 2 );
    }
}

// The thread which will play the music
//  for the scene...

UINT CChildView::Thread( LPVOID lParam )
{
    UNREFERENCED_PARAMETER( lParam );

    for ( ; ; )
    {
        HRSRC hResInfo = FindResource( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDR_MUSIC_SNOW ), "WAVE" );
        ASSERT( hResInfo );
        HRSRC hRes = ( HRSRC ) LoadResource( AfxGetInstanceHandle(), hResInfo );
        ASSERT( hRes );
        LPSTR lpRes = ( LPSTR ) LockResource(hRes);
        sndPlaySound(lpRes, SND_MEMORY | SND_SYNC | SND_NODEFAULT ); 
        FreeResource( hRes ); 
    }

    return 0;
}

// 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__;
#endifGLfloat 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 };/
// CChildViewCChildView::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(CChildView,CWnd )//{{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 handlersBOOL 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-portglMatrixMode( GL_PROJECTION );	// Select The Projection MatrixglLoadIdentity();				// Reset The Projection Matrix		// Calculate The Aspect Ratio Of The WindowgluPerspective( 45.0f, ( GLfloat ) cx / ( GLfloat ) cy, 0.1f, 400.0f );glMatrixMode( GL_MODELVIEW );	// Select The Model-view MatrixglLoadIdentity();		
}void CChildView::OnPaint() 
{CPaintDC dc(this); // device context for paintingCBitmap bitmap;bitmap.LoadBitmap( IDB_SNOW_FLOOR );// TODO: Add your message handler code hereDrawOpenGLScene();// Do not call CWnd::OnPaint() for painting messages
}BOOL CChildView::OnEraseBkgnd( CDC* pDC )
{UNREFERENCED_PARAMETER( pDC );return TRUE;
}void CChildView::OnDestroy()
{HGLRC hrc = NULL;hrc = ::wglGetCurrentContext();::wglMakeCurrent( NULL, NULL );if ( hrc != NULL )::wglDeleteContext( hrc );if ( m_pClientDC != NULL ){delete m_pClientDC;m_pClientDC = NULL;}ASSERT( m_pClientDC == NULL );CWnd::OnDestroy();
}// Initialize the OpenGL context device...VOID CChildView::InitOpenGL()
{m_pClientDC = new CClientDC( this );ASSERT( m_pClientDC != NULL );ASSERT_VALID( m_pClientDC );if ( ! SetupPixelFormat() )return;PIXELFORMATDESCRIPTOR pfd;int n = ::GetPixelFormat( m_pClientDC->GetSafeHdc());::DescribePixelFormat( m_pClientDC->GetSafeHdc(), n, sizeof( pfd ), & pfd );HGLRC hrc = NULL;hrc = wglCreateContext( m_pClientDC->GetSafeHdc() );ASSERT( hrc );wglMakeCurrent( m_pClientDC->GetSafeHdc(), hrc );if ( ! LoadOpenGLTextures() )return;glEnable( GL_TEXTURE_2D );glShadeModel( GL_SMOOTH );				// Enable Smooth ShadingglClearColor( 0.5f, 0.5f, 0.5f, 0.5f );	// Black BackgroundglClearDepth( 1.0f );					// Depth Buffer SetupglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );	// Really Nice Perspective CalculationsglLightfv( GL_LIGHT1, GL_AMBIENT,  LightAmbient  );glLightfv( GL_LIGHT1, GL_DIFFUSE,  LightDiffuse  );glLightfv( GL_LIGHT1, GL_POSITION, LightPosition );glEnable( GL_LIGHT1 );glBlendFunc( GL_SRC_ALPHA,GL_ONE );		// Set The Blending Function For TranslucencyglEnable( GL_BLEND );	
}// Load the texture from the define file pathBOOL CChildView::LoadOpenGLTextures()
{glGenTextures( E_TEXTURECOUNT, & m_textureSnow[ 0 ] );LoadImageFromResID( IDB_SNOW_LARGE,  m_textureSnow[ 0 ] );LoadImageFromResID( IDB_SNOW_MIDDLE, m_textureSnow[ 1 ] );LoadImageFromResID( IDB_SNOW_SMALL,  m_textureSnow[ 2 ] );InitSnow();LoadImageFromResID( IDB_SNOW_MIDDLE, m_textureSnow[ 3 ] );return TRUE;
}VOID CChildView::SetDefaultTextureParams()
{glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
} BOOL CChildView::SetupPixelFormat()
{static PIXELFORMATDESCRIPTOR pfd = {sizeof( PIXELFORMATDESCRIPTOR ),// size of this pfd1,                              // version numberPFD_DRAW_TO_WINDOW |            // support windowPFD_SUPPORT_OPENGL |        // support OpenGLPFD_DOUBLEBUFFER,           // double bufferedPFD_TYPE_RGBA,                  // RGBA type24,                             // 24-bit color depth0, 0, 0, 0, 0, 0,               // color bits ignored0,                              // no alpha buffer0,                              // shift bit ignored0,                              // no accumulation buffer0, 0, 0, 0,                     // accum bits ignored32,                             // 32-bit z-buffer0,                              // no stencil buffer0,                              // no auxiliary bufferPFD_MAIN_PLANE,                 // main layer0,                              // reserved0, 0, 0                         // layer masks ignored};int pixelformat = 0;ASSERT( m_pClientDC != NULL );if ( ( pixelformat = ChoosePixelFormat( m_pClientDC->GetSafeHdc(), & pfd ) ) == 0 ){AfxMessageBox( _T( "ChoosePixelFormat failed" ) );return FALSE;}if ( SetPixelFormat( m_pClientDC->GetSafeHdc(), pixelformat, & pfd ) == FALSE ){AfxMessageBox( _T( "SetPixelFormat failed" ) );return FALSE;}return TRUE;
}VOID CChildView::DrawOpenGLScene()
{static GLfloat wAngleY = 10.0f;glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );glLoadIdentity();glTranslatef( 0.0f, -30.0f, -150.0f );glRotatef( wAngleY, 0.0f, 1.0f, 0.0f );glBindTexture( GL_TEXTURE_2D, m_textureSnow[ m_nFloorIndex ] );glColor4f( 1.0f, 1.0f, 1.0f, 0.5 );glBegin( GL_QUADS );glNormal3f( 0.0f, 1.0f, 0.0f );glTexCoord2f( 0.0f, 0.0f ); glVertex3f(  100.0f, 0.0f, -100.0f );glTexCoord2f( 1.0f, 0.0f ); glVertex3f(  100.0f, 0.0f,  100.0f );glTexCoord2f( 1.0f, 1.0f ); glVertex3f( -100.0f, 0.0f,  100.0f );glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -100.0f, 0.0f, -100.0f );glEnd();for ( int nIndex = 0; nIndex < E_SNOWCOUNT; nIndex++ ){glLoadIdentity();glTranslatef( 0.0f, -30.0f, -150.0f ); glRotatef( wAngleY, 0.0f, 1.0f, 0.0f );glBindTexture( GL_TEXTURE_2D, m_textureSnow[ m_snow[ nIndex ].nIndexTexture ] );glTranslatef( m_snow[ nIndex ].x, m_snow[ nIndex ].y, m_snow[ nIndex ].z );glRotatef( m_snow[ nIndex ].xrot, 1.0f, 0.0f, 0.0f );glRotatef( m_snow[ nIndex ].yrot, 0.0f, 1.0f, 0.0f );glRotatef( m_snow[ nIndex ].zrot, 0.0f, 0.0f, 1.0f );glBegin( GL_QUADS );glNormal3f( 0.0f, 1.0f, 0.0f );glTexCoord2f( 0.0f, 0.0f ); glVertex3f(  1.0f, 0.0f, -1.0f );glTexCoord2f( 1.0f, 0.0f ); glVertex3f(  1.0f, 0.0f,  1.0f );glTexCoord2f( 1.0f, 1.0f ); glVertex3f( -1.0f, 0.0f,  1.0f );glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 0.0f, -1.0f );glEnd();m_snow[ nIndex ].y -= m_snow[ nIndex ].dropSpeed;if( m_snow[ nIndex ].y < -33 )m_snow[ nIndex ].y = 125.0f;m_snow[ nIndex ].xrot += m_snow[ nIndex ].rotSpeed;m_snow[ nIndex ].yrot += m_snow[ nIndex ].rotSpeed;m_snow[ nIndex ].zrot += m_snow[ nIndex ].rotSpeed;}wAngleY += 0.2f;glFinish();SwapBuffers( wglGetCurrentDC() );
}BOOL CChildView::LoadImageFromResID( UINT nResID, GLuint& texture )
{ASSERT( nResID > 0 );HBITMAP hBitmap = ( HBITMAP ) LoadImage( \AfxGetInstanceHandle(), \MAKEINTRESOURCE( nResID ), \IMAGE_BITMAP, \0, 0, \LR_CREATEDIBSECTION );ASSERT( hBitmap != NULL );DIBSECTION ds;GetObject( hBitmap, sizeof( DIBSECTION ), ( LPVOID ) & ds );glBindTexture( GL_TEXTURE_2D, texture );SetDefaultTextureParams();glTexImage2D( GL_TEXTURE_2D, 0, 3, ds.dsBm.bmWidth, ds.dsBm.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, ds.dsBm.bmBits );DeleteObject( hBitmap );return TRUE;
}void CChildView::OnTimer(UINT_PTR nIDEvent )
{DrawOpenGLScene();CWnd::OnTimer( nIDEvent );// Eat spurious WM_TIMER messageMSG msg;while( ::PeekMessage( & msg, m_hWnd, WM_TIMER, WM_TIMER, PM_REMOVE ) );
}VOID CChildView::InitSnow()
{srand( GetTickCount() );for ( int nIndex = 0; nIndex < E_SNOWCOUNT; nIndex++ ){m_snow[ nIndex ].nIndexTexture = rand() % 3;m_snow[ nIndex ].x = GLfloat( rand() % 200 - 100 );m_snow[ nIndex ].y = GLfloat( rand() % 200 - 100 );m_snow[ nIndex ].z = 100.0f + GLfloat( rand() % 25 );}for ( int i = 0; i < E_SNOWCOUNT; i++ ){m_snow[ i ].nIndexTexture = rand() % 3;m_snow[ i ].x             = GLfloat( rand() % 200 - 100 );m_snow[ i ].z             = GLfloat( rand() % 200 - 100 );m_snow[ i ].y             = 100.0f + GLfloat( rand() % 25 );m_snow[ i ].xrot          = 0;m_snow[ i ].yrot          = 0;m_snow[ i ].zrot          = 0;m_snow[ i ].dropSpeed     = 0.01f * ( rand() % 50 + 2 );m_snow[ i ].rotSpeed      =  0.1f * ( rand() % 10 + 2 );}
}// The thread which will play the music
//  for the scene...UINT CChildView::Thread( LPVOID lParam )
{UNREFERENCED_PARAMETER( lParam );for ( ; ; ){HRSRC hResInfo = FindResource( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDR_MUSIC_SNOW ), "WAVE" );ASSERT( hResInfo );HRSRC hRes = ( HRSRC ) LoadResource( AfxGetInstanceHandle(), hResInfo );ASSERT( hRes );LPSTR lpRes = ( LPSTR ) LockResource(hRes);sndPlaySound(lpRes, SND_MEMORY | SND_SYNC | SND_NODEFAULT ); FreeResource( hRes ); }return 0;
}

下载

源码下载


http://www.mrgr.cn/news/29159.html

相关文章:

  • AR眼镜方案_AR智能眼镜阵列/衍射光波导显示方案
  • 【多线程】伪共享的概念
  • Openshift 如何更新访问控制机
  • ⚡️如何在 React 和 Next.js 项目里优雅的使用 Zustand
  • 半导体制造技术导论(第二版)萧宏 第二章集成电路工艺介绍答案
  • 丹摩征文活动|Faster-Rcnn-训练与测试详细教程
  • 华为OD机试 - 阿里巴巴找黄金宝箱(V) - 滑动窗口(Python/JS/C/C++ 2024 E卷 100分)
  • 【编译原理】看书笔记
  • C++和OpenGL实现3D游戏编程【目录】
  • WebMagic:强大的Java网络爬虫框架
  • Python绘制基频曲线——实例解析与应用探讨
  • 最新腾讯高精度动作模仿模型MimicMotion分享
  • golang学习笔记27——golang 实现 RPC 模块
  • Golang | Leetcode Golang题解之第414题第三大的数
  • JavaScript:驱动现代Web应用的关键引擎及其与HTML/CSS的集成
  • 一天认识一个硬件之显示器
  • 如何在Java服务中实现数据一致性:事务与锁机制的综合应用
  • 【技术分享】走进Docker的世界:从基础到实战全面解析(Docker全流程)
  • golang学习笔记26——golang 实现节点筛选与负载均衡
  • Windows目录监控部署
  • Qt容器类控件——QGroupBox和QTabWidget
  • pythonnet python图像 C# .NET图像 互转
  • C++ 类的默认成员函数-构造函数
  • 操作系统----操作系统引导
  • 71、Python之函数式编程:不能定义常量,Python如何支持不可变性?
  • 每日学习一个数据结构-FST数据结构与算法