Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
MODEL.CPP
Package: openglsystem.rar [view]
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 5k
Category:
OpenCV
Development Platform:
Visual C++
- // Model.cpp: implementation of the Model class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Terrain3DTest.h"
- #include "Model.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- Model::Model()
- {
- m_numMeshes = 0;
- m_pMeshes = NULL;
- m_numMaterials = 0;
- m_pMaterials = NULL;
- m_numTriangles = 0;
- m_pTriangles = NULL;
- m_numVertices = 0;
- m_pVertices = NULL;
- }
- Model::~Model()
- {
- int i;
- for ( i = 0; i < m_numMeshes; i++ )
- delete[] m_pMeshes[i].m_pTriangleIndices;
- for ( i = 0; i < m_numMaterials; i++ )
- delete[] m_pMaterials[i].m_pTextureFilename;
- m_numMeshes = 0;
- if ( m_pMeshes != NULL )
- {
- delete[] m_pMeshes;
- m_pMeshes = NULL;
- }
- m_numMaterials = 0;
- if ( m_pMaterials != NULL )
- {
- delete[] m_pMaterials;
- m_pMaterials = NULL;
- }
- m_numTriangles = 0;
- if ( m_pTriangles != NULL )
- {
- delete[] m_pTriangles;
- m_pTriangles = NULL;
- }
- m_numVertices = 0;
- if ( m_pVertices != NULL )
- {
- delete[] m_pVertices;
- m_pVertices = NULL;
- }
- }
- void Model::draw()
- {
- GLboolean texEnabled = glIsEnabled( GL_TEXTURE_2D );
- // Draw by group
- for ( int i = 0; i < m_numMeshes; i++ )
- {
- int materialIndex = m_pMeshes[i].m_materialIndex;
- if ( materialIndex >= 0 )
- {
- glMaterialfv( GL_FRONT, GL_AMBIENT, m_pMaterials[materialIndex].m_ambient );
- glMaterialfv( GL_FRONT, GL_DIFFUSE, m_pMaterials[materialIndex].m_diffuse );
- glMaterialfv( GL_FRONT, GL_SPECULAR, m_pMaterials[materialIndex].m_specular );
- glMaterialfv( GL_FRONT, GL_EMISSION, m_pMaterials[materialIndex].m_emissive );
- glMaterialf( GL_FRONT, GL_SHININESS, m_pMaterials[materialIndex].m_shininess );
- if ( m_pMaterials[materialIndex].m_texture > 0 )
- {
- glBindTexture( GL_TEXTURE_2D, m_pMaterials[materialIndex].m_texture );
- glEnable( GL_TEXTURE_2D );
- }
- else
- glDisable( GL_TEXTURE_2D );
- }
- else
- {
- // Material properties?
- glDisable( GL_TEXTURE_2D );
- }
- glBegin( GL_TRIANGLES );
- {
- for ( int j = 0; j < m_pMeshes[i].m_numTriangles; j++ )
- {
- int triangleIndex = m_pMeshes[i].m_pTriangleIndices[j];
- const Triangle* pTri = &m_pTriangles[triangleIndex];
- for ( int k = 0; k < 3; k++ )
- {
- int index = pTri->m_vertexIndices[k];
- glNormal3fv( pTri->m_vertexNormals[k] );
- glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );
- glVertex3fv( m_pVertices[index].m_location );
- }
- }
- }
- glEnd();
- }
- if ( texEnabled )
- glEnable( GL_TEXTURE_2D );
- else
- glDisable( GL_TEXTURE_2D );
- }
- GLuint Model::makeDisplayList()
- {
- GLuint List = glGenLists(1);
- glNewList(List,GL_COMPILE); // Start With The Box List
- GLboolean texEnabled = glIsEnabled( GL_TEXTURE_2D );
- // Draw by group
- for ( int i = 0; i < m_numMeshes; i++ )
- {
- int materialIndex = m_pMeshes[i].m_materialIndex;
- if ( materialIndex >= 0 )
- {
- glMaterialfv( GL_FRONT, GL_AMBIENT, m_pMaterials[materialIndex].m_ambient );
- glMaterialfv( GL_FRONT, GL_DIFFUSE, m_pMaterials[materialIndex].m_diffuse );
- glMaterialfv( GL_FRONT, GL_SPECULAR, m_pMaterials[materialIndex].m_specular );
- glMaterialfv( GL_FRONT, GL_EMISSION, m_pMaterials[materialIndex].m_emissive );
- glMaterialf( GL_FRONT, GL_SHININESS, m_pMaterials[materialIndex].m_shininess );
- if ( m_pMaterials[materialIndex].m_texture > 0 )
- {
- glBindTexture( GL_TEXTURE_2D, m_pMaterials[materialIndex].m_texture );
- glEnable( GL_TEXTURE_2D );
- }
- else
- glDisable( GL_TEXTURE_2D );
- }
- else
- {
- // Material properties?
- glDisable( GL_TEXTURE_2D );
- }
- glBegin( GL_TRIANGLES );
- {
- for ( int j = 0; j < m_pMeshes[i].m_numTriangles; j++ )
- {
- int triangleIndex = m_pMeshes[i].m_pTriangleIndices[j];
- const Triangle* pTri = &m_pTriangles[triangleIndex];
- for ( int k = 0; k < 3; k++ )
- {
- int index = pTri->m_vertexIndices[k];
- glNormal3fv( pTri->m_vertexNormals[k] );
- glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );
- glVertex3fv( m_pVertices[index].m_location );
- }
- }
- }
- glEnd();
- }
- if ( texEnabled )
- glEnable( GL_TEXTURE_2D );
- else
- glDisable( GL_TEXTURE_2D );
- glEndList();
- return List;
- }
- void Model::reloadTextures()
- {
- for ( int i = 0; i < m_numMaterials; i++ )
- if ( strlen( m_pMaterials[i].m_pTextureFilename ) > 0 )
- m_pMaterials[i].m_texture = m_texture.LoadGLTexture( m_pMaterials[i].m_pTextureFilename );
- else
- m_pMaterials[i].m_texture = 0;
- }