3dColor.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:4k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dColor.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 <windows.h>
- #include "stdafx.h"
- #include "glOOP.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dColor
- IMPLEMENT_DYNAMIC(C3dColor, CObject)
- //IMPLEMENT_SERIAL(C3dColor, CObject, 0)
- /////////////////////////////////////////////////////////////////////////////
- // C3dColor construction
- C3dColor::C3dColor()
- {
- // Assign default values to member attributes..
- m_szName.GetBuffer(128); // allocate 128 bytes min.
- m_szName = _T("");
- SetColor4f(1.0f, 1.0f, 1.0f, 1.0f); // White
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dColor Destructor
- C3dColor::~C3dColor()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dColor Implimentation
- C3dColor* C3dColor::Create()
- {
- C3dColor* pColor = new C3dColor;
- ASSERT(pColor);
- return pColor;
- }
- C3dColor* C3dColor::Create(CString szName,
- GLfloat r,
- GLfloat g,
- GLfloat b,
- GLfloat a)
- {
- C3dColor* pColor = new C3dColor;
- ASSERT(pColor);
- pColor->m_szName = szName;
- pColor->SetColor4f(r, g, b, a);
- return pColor;
- }
- void C3dColor::Delete(C3dColor* pColor)
- {
- if(pColor) {
- delete pColor;
- }
- }
- void C3dColor::GetColor4f(GLfloat *r, GLfloat *g, GLfloat *b, GLfloat *a)
- {
- // Get the Color RGBA component values
- *r = m_fColor[0];
- *g = m_fColor[1];
- *b = m_fColor[2];
- *a = m_fColor[3];
- }
- void C3dColor::SetColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
- {
- // Set the Color RGBA component values
- m_fColor[0] = r;
- m_fColor[1] = g;
- m_fColor[2] = b;
- m_fColor[3] = a;
- }
- void C3dColor::SetColor3fv(C3dColor* pColor)
- {
- // Set the Color RGB components only (No alpha)
- if(pColor)
- {
- // Set the Color RGBA component values
- m_fColor[0] = pColor->m_fColor[0];
- m_fColor[1] = pColor->m_fColor[1];
- m_fColor[2] = pColor->m_fColor[2];
- }
- }
- void C3dColor::SetColor4fv(C3dColor* pColor)
- {
- if(pColor)
- {
- // Set the Color RGBA component values
- m_fColor[0] = pColor->m_fColor[0];
- m_fColor[1] = pColor->m_fColor[1];
- m_fColor[2] = pColor->m_fColor[2];
- m_fColor[3] = pColor->m_fColor[3];
- }
- }
- BOOL C3dColor::Compare(C3dColor* pColor)
- {
- // Compare the color components
- if(pColor->m_fColor[0] != m_fColor[0])
- return FALSE;
- if(pColor->m_fColor[1] != m_fColor[1])
- return FALSE;
- if(pColor->m_fColor[2] != m_fColor[2])
- return FALSE;
- if(pColor->m_fColor[3] != m_fColor[3])
- return FALSE;
- return TRUE;
- }
- void C3dColor::Serialize(CArchive& ar, int iVersion)
- {
- CString szBuffer;
- if (ar.IsStoring())
- {
- // Save the Color header
- szBuffer.Format("%sC3dColor {n", szIndent);
- ar.WriteString(szBuffer);
- // Save the Color Data...
- szBuffer.Format("%stName < %s >n", szIndent, m_szName);
- ar.WriteString(szBuffer);
- szBuffer.Format("%stColor < %f %f %f %f > // RGBAn", szIndent, m_fColor[0], m_fColor[1], m_fColor[2], m_fColor[3]);
- ar.WriteString(szBuffer);
- szBuffer.Format("%s}n", szIndent); // end of Color def
- ar.WriteString(szBuffer);
- }
- else
- {
- // Read the Color data...
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft(); // Remove leading white spaces
- sscanf(szBuffer, "Name < %s >n", m_szName);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "Color < %f %f %f %f >n", &m_fColor[0], &m_fColor[1], &m_fColor[2], &m_fColor[3]);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- }
- }