3dPageTexture.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:5k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageTexture.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 "3dObjectDialog.h"
- #include "EditTextureDlg.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dPageTexture
- IMPLEMENT_DYNCREATE(C3dPageTexture, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTexture dialog construction
- C3dPageTexture::C3dPageTexture()
- : CPropertyPage(C3dPageTexture::IDD)
- {
- //{{AFX_DATA_INIT(C3dPageTexture)
- m_szTextureFileName = _T("<None>");
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTexture Destructor
- C3dPageTexture::~C3dPageTexture()
- {
- }
- void C3dPageTexture::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageTexture)
- DDX_Text(pDX, IDC_IMAGE_NAME, m_szTextureFileName);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageTexture, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageTexture)
- ON_BN_CLICKED(IDC_TEXTURE_OPEN, OnTextureOpen)
- ON_BN_CLICKED(IDC_TEXTURE_EDIT, OnTextureEdit)
- ON_BN_CLICKED(IDC_TEXTURE_REMOVE, OnTextureRemove)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTexture message handlers
- BOOL C3dPageTexture::OnInitDialog()
- {
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- // If our Object has a background Texture map, copy its name to
- // the CEdit box.
- if(m_pObject)
- {
- if(m_pObject->m_pTexture)
- {
- if(m_pObject->m_pTexture->m_szFileName.GetLength())
- m_szTextureFileName = m_pObject->m_pTexture->m_szFileName;
- }
- }
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void C3dPageTexture::OnTextureOpen()
- {
- CFileDialog fileDlg(TRUE, NULL, NULL);
- fileDlg.m_ofn.lpstrFilter = "Texture Files (*.bmp) *.bmp DIB Files (*.dib) *.dib AVI Files (*.avi) *.avi All Files (*.*) *.* ";
- fileDlg.m_ofn.lpstrTitle = "Open Texture Map";
- if(!m_pObject)
- return;
- int retn = fileDlg.DoModal();
- if(retn == IDOK) {
- CString szFile = fileDlg.GetFileName();
- CString szPath = fileDlg.GetPathName();
- CString szFileExt = fileDlg.GetFileExt();
- if(szFileExt.Compare("bmp") == 0 ||
- szFileExt.Compare("dib") == 0 ||
- szFileExt.Compare("avi") == 0)
- {
- if(m_pObject->AddTexture(szPath.GetBuffer(128)))
- {
- // Force a rebuild of the objects display lists
- m_pObject->m_bBuildLists = TRUE;
- m_szTextureFileName = szPath;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- else
- AfxMessageBox("Could not create Texture map!", MB_OK, NULL);
- }
- else
- AfxMessageBox("Unsupported File Extension! Select files with either 'bmp', 'dib' or 'avi' extensions.", MB_OK, NULL);
- }
- }
- void C3dPageTexture::OnTextureEdit()
- {
- // Get a pointer to our objects texture
- if(m_pObject)
- {
- if(m_pObject->m_pTexture)
- {
- CTexture* pTexture = m_pObject->m_pTexture;
- ASSERT(pTexture);
- CEditTextureDlg textureDlg(pTexture, CWnd::GetActiveWindow());
- textureDlg.DoModal();
- // Force a repaint of the window
- pTexture->m_bApplyImage = TRUE;
- }
- else
- AfxMessageBox("There are no background textures to edit!", MB_OK, 0);
- }
- }
- void C3dPageTexture::OnTextureRemove()
- {
- if(m_pObject)
- {
- // Delete the objects texture map
- if(m_pObject->m_pTexture)
- {
- m_pObject->DeleteTexture();
- m_szTextureFileName = _T("<None>");
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- }
- }