3dPageTerrainTexture.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:13k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageTerrainTexture.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
- //////////////////////////////////////////////////////////////////
- // C3dPageTerrainTexture definitions
- #define TEXTURE_SNOW 0
- #define TEXTURE_ROCK 1
- #define TEXTURE_GRASS 2
- #define TEXTURE_WATER 3
- #define MAPTEXTURETOGRID 0
- #define MAPTEXTURETOSUBGRID 1
- //////////////////////////////////////////////////////////////////
- // C3dPageTerrainTexture
- IMPLEMENT_DYNCREATE(C3dPageTerrainTexture, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrainTexture dialog construction
- C3dPageTerrainTexture::C3dPageTerrainTexture()
- : CPropertyPage(C3dPageTerrainTexture::IDD)
- {
- //{{AFX_DATA_INIT(C3dPageTerrainTexture)
- m_szTextureFileName = _T("<None>");
- m_bMapSubGridTextures = FALSE;
- m_iApplyTextureToGrid = -1;
- m_iSubTextureType = TEXTURE_SNOW;
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrainTexture Destructor
- C3dPageTerrainTexture::~C3dPageTerrainTexture()
- {
- }
- void C3dPageTerrainTexture::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageTerrainTexture)
- DDX_Text(pDX, IDC_IMAGE_NAME, m_szTextureFileName);
- DDX_Check(pDX, IDC_CHECK_SUBGRIDTEXTURES, m_bMapSubGridTextures);
- DDX_Radio(pDX, IDC_RADIO_APPLYTOGRID, m_iApplyTextureToGrid);
- DDX_Radio(pDX, IDC_RADIO_SNOW, m_iSubTextureType);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageTerrainTexture, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageTerrainTexture)
- ON_BN_CLICKED(IDC_TEXTURE_OPEN, OnTextureOpen)
- ON_BN_CLICKED(IDC_TEXTURE_EDIT, OnTextureEdit)
- ON_BN_CLICKED(IDC_TEXTURE_REMOVE, OnTextureRemove)
- ON_BN_CLICKED(IDC_CHECK_SUBGRIDTEXTURES, OnCheckSubgridtextures)
- ON_BN_CLICKED(IDC_RADIO_APPLYTOGRID, OnRadioApplytogrid)
- ON_BN_CLICKED(IDC_RADIO_APPLYTOSUBGRID, OnRadioApplytosubgrid)
- ON_BN_CLICKED(IDC_RADIO_SNOW, OnRadioSnow)
- ON_BN_CLICKED(IDC_RADIO_ROCK, OnRadioRock)
- ON_BN_CLICKED(IDC_RADIO_GRASS, OnRadioGrass)
- ON_BN_CLICKED(IDC_RADIO_WATER, OnRadioWater)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrainTexture message handlers
- BOOL C3dPageTerrainTexture::OnInitDialog()
- {
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- // Ensure that we have a vaild pointer
- if(!m_pObject)
- return TRUE;
- // Determine which texture names, if any, to show in the edit box
- if(m_pObject->m_bApplySubGridTextures && m_pObject->m_bMapTexturesToSubGrid)
- {
- if(m_iSubTextureType == TEXTURE_SNOW)
- {
- if(m_pObject->m_pTextureSnow)
- {
- if(m_pObject->m_pTextureSnow->m_szFileName.GetLength())
- m_szTextureFileName = m_pObject->m_pTextureSnow->m_szFileName;
- }
- }
- if(m_iSubTextureType == TEXTURE_ROCK)
- {
- if(m_pObject->m_pTextureRock)
- {
- if(m_pObject->m_pTextureRock->m_szFileName.GetLength())
- m_szTextureFileName = m_pObject->m_pTextureRock->m_szFileName;
- }
- }
- if(m_iSubTextureType == TEXTURE_GRASS)
- {
- if(m_pObject->m_pTextureGrass)
- {
- if(m_pObject->m_pTextureGrass->m_szFileName.GetLength())
- m_szTextureFileName = m_pObject->m_pTextureGrass->m_szFileName;
- }
- }
- if(m_iSubTextureType == TEXTURE_WATER)
- {
- if(m_pObject->m_pTextureWater)
- {
- if(m_pObject->m_pTextureWater->m_szFileName.GetLength())
- m_szTextureFileName = m_pObject->m_pTextureWater->m_szFileName;
- }
- }
- }
- else
- {
- if(m_pObject->m_pTexture)
- {
- if(m_pObject->m_pTexture->m_szFileName.GetLength())
- m_szTextureFileName = m_pObject->m_pTexture->m_szFileName;
- }
- }
- m_bMapSubGridTextures = m_pObject->m_bMapTexturesToSubGrid;
- m_iApplyTextureToGrid = m_pObject->m_bApplySubGridTextures;
- if(!m_iApplyTextureToGrid)
- {
- // Set the data window enable/disable states
- GetDlgItem(IDC_CHECK_SUBGRIDTEXTURES)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_SNOW)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_ROCK)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_GRASS)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_WATER)->EnableWindow(FALSE);
- }
- // 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 C3dPageTerrainTexture::OnTextureOpen()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- 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->m_bApplySubGridTextures && m_pObject->m_bMapTexturesToSubGrid)
- {
- if(m_iSubTextureType == TEXTURE_SNOW)
- {
- if(!m_pObject->AddSubTexture(szPath.GetBuffer(128), &m_pObject->m_pTextureSnow))
- {
- AfxMessageBox("Could not create Texture map!", MB_OK, NULL);
- return;
- }
- }
- if(m_iSubTextureType == TEXTURE_ROCK)
- {
- if(!m_pObject->AddSubTexture(szPath.GetBuffer(128), &m_pObject->m_pTextureRock))
- {
- AfxMessageBox("Could not create Texture map!", MB_OK, NULL);
- return;
- }
- }
- if(m_iSubTextureType == TEXTURE_GRASS)
- {
- if(!m_pObject->AddSubTexture(szPath.GetBuffer(128), &m_pObject->m_pTextureGrass))
- {
- AfxMessageBox("Could not create Texture map!", MB_OK, NULL);
- return;
- }
- }
- if(m_iSubTextureType == TEXTURE_WATER)
- {
- if(!m_pObject->AddSubTexture(szPath.GetBuffer(128), &m_pObject->m_pTextureWater))
- {
- AfxMessageBox("Could not create Texture map!", MB_OK, NULL);
- return;
- }
- }
- }
- else
- {
- if(!m_pObject->AddTexture(szPath.GetBuffer(128)))
- {
- AfxMessageBox("Could not create Texture map!", MB_OK, NULL);
- return;
- }
- }
- // Force a rebuild of the objects display lists
- m_pObject->m_bBuildLists = TRUE;
- m_szTextureFileName = szPath;
- }
- else
- AfxMessageBox("Unsupported File Extension! Select files with either 'bmp', 'dib' or 'avi' extensions.", MB_OK, NULL);
- }
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageTerrainTexture::OnTextureEdit()
- {
- CTexture* pTexture = NULL;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- if(m_pObject->m_bApplySubGridTextures && m_pObject->m_bMapTexturesToSubGrid)
- {
- if(m_iSubTextureType == TEXTURE_SNOW)
- {
- if(m_pObject->m_pTextureSnow)
- pTexture = m_pObject->m_pTextureSnow;
- }
- if(m_iSubTextureType == TEXTURE_ROCK)
- {
- if(m_pObject->m_pTextureRock)
- pTexture = m_pObject->m_pTextureRock;
- }
- if(m_iSubTextureType == TEXTURE_GRASS)
- {
- if(m_pObject->m_pTextureGrass)
- pTexture = m_pObject->m_pTextureGrass;
- }
- if(m_iSubTextureType == TEXTURE_WATER)
- {
- if(m_pObject->m_pTextureWater)
- pTexture = m_pObject->m_pTextureWater;
- }
- }
- else
- {
- if(m_pObject->m_pTexture)
- pTexture = m_pObject->m_pTexture;
- }
- if(pTexture)
- {
- ASSERT(pTexture);
- CEditTextureDlg textureDlg(pTexture, CWnd::GetActiveWindow());
- textureDlg.DoModal();
- // Force a reload of the texture map
- pTexture->m_bApplyImage = TRUE;
- }
- else
- AfxMessageBox("There are no textures to edit!", MB_OK, 0);
- }
- void C3dPageTerrainTexture::OnTextureRemove()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- if(m_pObject)
- {
- // Delete the objects texture map
- if(m_pObject->m_bApplySubGridTextures && m_pObject->m_bMapTexturesToSubGrid)
- {
- if(m_iSubTextureType == TEXTURE_SNOW)
- {
- if(m_pObject->m_pTextureSnow)
- {
- m_pObject->DeleteSubTexture(m_pObject->m_pTextureSnow);
- m_pObject->m_pTextureSnow = NULL;
- }
- }
- if(m_iSubTextureType == TEXTURE_ROCK)
- {
- if(m_pObject->m_pTextureRock)
- {
- m_pObject->DeleteSubTexture(m_pObject->m_pTextureRock);
- m_pObject->m_pTextureRock = NULL;
- }
- }
- if(m_iSubTextureType == TEXTURE_GRASS)
- {
- if(m_pObject->m_pTextureGrass)
- {
- m_pObject->DeleteSubTexture(m_pObject->m_pTextureGrass);
- m_pObject->m_pTextureGrass = NULL;
- }
- }
- if(m_iSubTextureType == TEXTURE_WATER)
- {
- if(m_pObject->m_pTextureWater)
- {
- m_pObject->DeleteSubTexture(m_pObject->m_pTextureWater);
- m_pObject->m_pTextureWater = NULL;
- }
- }
- }
- else
- {
- if(m_pObject->m_pTexture)
- {
- m_pObject->DeleteTexture();
- m_pObject->m_pTexture = NULL;
- }
- }
- m_szTextureFileName = _T("<None>");
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- }
- void C3dPageTerrainTexture::OnCheckSubgridtextures()
- {
- m_pObject->m_bMapTexturesToSubGrid = !m_pObject->m_bMapTexturesToSubGrid;
- if(m_pObject->m_bMapTexturesToSubGrid)
- {
- GetDlgItem(IDC_RADIO_SNOW)->EnableWindow(TRUE);
- GetDlgItem(IDC_RADIO_ROCK)->EnableWindow(TRUE);
- GetDlgItem(IDC_RADIO_GRASS)->EnableWindow(TRUE);
- GetDlgItem(IDC_RADIO_WATER)->EnableWindow(TRUE);
- }
- else
- {
- GetDlgItem(IDC_RADIO_SNOW)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_ROCK)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_GRASS)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIO_WATER)->EnableWindow(FALSE);
- }
- }
- void C3dPageTerrainTexture::OnRadioApplytogrid()
- {
- m_pObject->m_bApplySubGridTextures = FALSE;
- // Set the data window enable/disable states
- GetDlgItem(IDC_CHECK_SUBGRIDTEXTURES)->EnableWindow(FALSE);
- m_pObject->m_bMapTexturesToSubGrid = FALSE;
- }
- void C3dPageTerrainTexture::OnRadioApplytosubgrid()
- {
- m_pObject->m_bApplySubGridTextures = TRUE;
- // Set the data window enable/disable states
- // Disabled for now..
- // GetDlgItem(IDC_CHECK_SUBGRIDTEXTURES)->EnableWindow(TRUE);
- }
- void C3dPageTerrainTexture::OnOK()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- // Force the object to rebuild its' display list
- m_pObject->m_bBuildLists = TRUE;
- CPropertyPage::OnOK();
- }
- void C3dPageTerrainTexture::OnRadioSnow()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- if(m_pObject->m_pTextureSnow)
- m_szTextureFileName = m_pObject->m_pTextureSnow->m_szFileName;
- else
- m_szTextureFileName = _T("<None>");
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageTerrainTexture::OnRadioRock()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- if(m_pObject->m_pTextureRock)
- m_szTextureFileName = m_pObject->m_pTextureRock->m_szFileName;
- else
- m_szTextureFileName = _T("<None>");
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageTerrainTexture::OnRadioGrass()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- if(m_pObject->m_pTextureGrass)
- m_szTextureFileName = m_pObject->m_pTextureGrass->m_szFileName;
- else
- m_szTextureFileName = _T("<None>");
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageTerrainTexture::OnRadioWater()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- if(m_pObject->m_pTextureWater)
- m_szTextureFileName = m_pObject->m_pTextureWater->m_szFileName;
- else
- m_szTextureFileName = _T("<None>");
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }