3dFog.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:4k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dFog.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"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dFog
- IMPLEMENT_DYNAMIC(C3dFog, CObject)
- /////////////////////////////////////////////////////////////////////////////
- // C3dFog construction
- C3dFog::C3dFog()
- {
- // Default Fog attribute settings
- m_enumMode = GL_EXP; // GL_LINEAR, GL_EXP, and GL_EXP2
- m_enumHint = GL_FASTEST; // GL_FASTEST, GL_NICEST
- m_fDensity = 0.05f;
- m_fStart = 1.0f; // Map fog start to 'Near' clipping plane default
- m_fEnd = 500.0f; // Map fog end to 'Far' clipping plane default
- m_Color.SetColor4f(0.0f, 0.0f, 0.0f, 0.0f);
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dFog Destructor
- C3dFog::~C3dFog()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dLight serialization
- void C3dFog::Serialize(CArchive& ar, int iVersion)
- {
- CString szBuffer;
- if (ar.IsStoring())
- {
- // Save the Fog member variables
- szBuffer.Format("%stC3dFog {n", szIndent);
- ar.WriteString(szBuffer);
- szBuffer.Format("%sttColor < %f %f %f %f > // RGBAn", szIndent, m_Color.m_fColor[0], m_Color.m_fColor[1], m_Color.m_fColor[2], m_Color.m_fColor[3]);
- ar.WriteString(szBuffer);
- szBuffer.Format("%sttFog Hint < %d >n", szIndent, m_enumHint);
- ar.WriteString(szBuffer);
- szBuffer.Format("%sttFog Mode < %d >n", szIndent, m_enumMode);
- ar.WriteString(szBuffer);
- szBuffer.Format("%sttDensity < %f >n", szIndent, m_fDensity);
- ar.WriteString(szBuffer);
- szBuffer.Format("%sttStart < %f >n", szIndent, m_fStart);
- ar.WriteString(szBuffer);
- szBuffer.Format("%sttEnd Location < %f >n", szIndent, m_fEnd);
- ar.WriteString(szBuffer);
- szBuffer.Format("%st}nn", szIndent); // end of fog def
- ar.WriteString(szBuffer);
- }
- else
- {
- // Read the Fog member variables
- do {
- // Look for the Fog header...
- szBuffer.TrimLeft();
- if(szBuffer.Compare("C3dFog {") == 0)
- break;
- } while(ar.ReadString(szBuffer));
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "Color < %f %f %f %f >n", &m_Color.m_fColor[0], &m_Color.m_fColor[1], &m_Color.m_fColor[2], &m_Color.m_fColor[3]);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "Fog Hint < %d >n", &m_enumHint);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "Fog Mode < %d >n", &m_enumMode);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "Density < %f >n", &m_fDensity);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "Start < %f >n", &m_fStart);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "End Location < %f >n", &m_fEnd);
- ar.ReadString(szBuffer);
- sscanf(szBuffer, "}nn");
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dFog Implimentation
- void C3dFog::SetAttributes()
- {
- glEnable(GL_FOG);
- glHint(GL_FOG_HINT, m_enumHint);
- glFogi(GL_FOG_MODE, m_enumMode);
- glFogf(GL_FOG_DENSITY, m_fDensity);
- glFogf(GL_FOG_START, m_fStart);
- glFogf(GL_FOG_END, m_fEnd);
- if(m_Color.m_fColor[3] < 1)
- glEnable(GL_ALPHA);
- else
- glDisable(GL_ALPHA);
- glFogfv(GL_FOG_COLOR, m_Color.m_fColor);
- }