MyCloudWnd.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:5k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // MyCloudWnd.cpp : implementation file
- //
- // glOOP (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1998
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- // This program is -not- in the public domain.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "glOOP.h"
- #include "MyColorPaletteWnd.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMyCloudWnd
- IMPLEMENT_DYNAMIC(CMyCloudWnd, CMyglWnd)
- CMyCloudWnd::CMyCloudWnd()
- {
- // Set our camera to Orthographic view and
- // initialize our camera variables
- m_Camera.m_bPerspective = TRUE;
- m_Camera.m_fOrigin[X] = 0.0f;
- m_Camera.m_fOrigin[Y] = 0.0f;
- m_Camera.m_fOrigin[Z] = 25.0f;
- m_Camera.m_fRotation[X] = 0.0f;
- m_Camera.m_fRotation[Y] = 0.0f;
- m_Camera.m_fRotation[Z] = 0.0f;
- m_Camera.m_fNear = 0.0f;
- m_Camera.m_fFar = 300.0f;
- m_pCloudObject = new C3dObjectCloud;
- }
- CMyCloudWnd::~CMyCloudWnd()
- {
- if(m_pCloudObject)
- delete m_pCloudObject;
- }
- BEGIN_MESSAGE_MAP(CMyCloudWnd, CWnd)
- //{{AFX_MSG_MAP(CMyCloudWnd)
- ON_WM_PAINT()
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_WM_SIZE()
- ON_WM_PALETTECHANGED()
- ON_WM_QUERYNEWPALETTE()
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BOOL CMyCloudWnd::Create(DWORD dwExStyle, LPCTSTR lpszClassName,
- LPCTSTR lpszWindowName, DWORD dwStyle,
- const RECT& rect, CWnd* pParentWnd, UINT nID,
- CCreateContext* pContext)
- {
- // if(lpszClassName == NULL)
- // // Register a class with its own device context and the 'cross' cursor
- // lpszClassName = AfxRegisterWndClass(CS_OWNDC | CS_HREDRAW | CS_VREDRAW,
- // ::LoadCursor(NULL, IDC_CROSS));
- return CMyglWnd::Create(dwExStyle, lpszClassName, lpszWindowName,
- dwStyle, rect, pParentWnd, nID, pContext);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyCloudWnd messages forwarded to CMyglWnd base class
- void CMyCloudWnd::OnDestroy()
- {
- // Forward the message to the base class
- CMyglWnd::OnDestroy();
- }
- void CMyCloudWnd::OnSize(UINT nType, int cx, int cy)
- {
- // Forward the message to the base class
- CMyglWnd::OnSize(nType, cx, cy);
- }
- void CMyCloudWnd::OnPaletteChanged(CWnd* pFocusWnd)
- {
- // Forward the message to the base class
- CMyglWnd::OnPaletteChanged(pFocusWnd);
- }
- BOOL CMyCloudWnd::OnQueryNewPalette()
- {
- // Forward the message to the base class
- return CMyglWnd::OnQueryNewPalette();
- }
- BOOL CMyCloudWnd::OnEraseBkgnd(CDC* pDC)
- {
- // Forward the message to the base class
- return CMyglWnd::OnEraseBkgnd(pDC);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyCloudWnd message handlers
- int CMyCloudWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMyglWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- return 0;
- }
- void CMyCloudWnd::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // Make this view the current OpenGL rendering context...
- if(!the3dEngine.EnableRC(dc, m_hRC, TRUE))
- return;
- // Call OpenGL drawing code
- RenderPreviewWnd();
- // Exchange the front and back buffers
- SwapBuffers(dc);
- // Releases the device context that is used by the rendering context
- // to allow other rendering contexts to co-exist.
- the3dEngine.EnableRC(NULL, NULL, FALSE);
- // Do not call CWnd::OnPaint() for painting messages
- }
- void CMyCloudWnd::RenderPreviewWnd()
- {
- GLfloat fOrigin [4] = {5.0f, 5.0f, 5.0f, 1.0f};
- GLfloat fColorAmbient [4] = {0.2f, 0.2f, 0.2f, 1.0f};
- GLfloat fColorDiffuse [4] = {0.7f, 0.7f, 0.7f, 1.0f};
- GLfloat fColorSpecular [4] = {0.9f, 0.9f, 0.9f, 1.0f};
- // Enable color material
- glEnable(GL_COLOR_MATERIAL);
- // Enable lighting
- glEnable(GL_LIGHTING);
- // If we have a palette, enable dithering of color before
- // writing to the color buffer
- if(the3dEngine.GetPalette())
- glEnable(GL_DITHER);
- // We want specular reflections to take the direction of our
- // cameras' position
- glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0f);
- glEnable(GL_DEPTH_TEST);
- glShadeModel(GL_SMOOTH);
- // Set the background color to light blue
- glClearColor(0.0f, 0.6f, 1.0f, 1.0f);
- // Clear the window with current clearing color
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // Save the current Modelview matrix
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- // Position our camera
- m_Camera.PositionCamera();
- // Set the Lights Parameters and Enable...
- glLightfv(GL_LIGHT0, GL_AMBIENT, fColorAmbient);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, fColorDiffuse);
- glLightfv(GL_LIGHT0, GL_SPECULAR, fColorSpecular);
- glLightfv(GL_LIGHT0, GL_POSITION, fOrigin);
- glEnable(GL_LIGHT0);
- m_pCloudObject->SetAttributes(NULL, NULL);
- m_pCloudObject->Build(NULL, NULL);
- // Restore the Modelview matrix
- glPopMatrix();
- // Flush drawing commands
- glFlush();
- }