EgtGraphics 1.5d5 :

- Gestione materiali
- Facce con front e back diversificati per materiale
- HiddenLine.
This commit is contained in:
Dario Sassi
2014-04-23 13:03:45 +00:00
parent 401b66cc0e
commit f7a63375df
9 changed files with 260 additions and 123 deletions
+44 -10
View File
@@ -1,13 +1,13 @@
//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : ObjNewGraphics.cpp Data : 10.02.14 Versione : 1.5b1
// File : ObjNewGraphics.cpp Data : 23.04.14 Versione : 1.5d5
// Contenuto : Implementazione della classe grafica di un oggetto geometrico.
//
//
//
// Modifiche : 10.02.14 DS Creazione modulo.
//
// 23.04.14 DS Agg. gestione materiali.
//
//----------------------------------------------------------------------------
@@ -57,6 +57,27 @@ ObjNewGraphics::AddColor( const Color& colC)
return AddColor( colC.GetRed(), colC.GetGreen(), colC.GetBlue(), colC.GetAlpha()) ;
}
//----------------------------------------------------------------------------
bool
ObjNewGraphics::AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec)
{
return AddMaterial( NgAtom::MAT_A, colAmb.GetRed(), colAmb.GetGreen(),
colAmb.GetBlue(), colDiff.GetAlpha()) &&
AddMaterial( NgAtom::MAT_D, colDiff.GetRed(), colDiff.GetGreen(),
colDiff.GetBlue(), colDiff.GetAlpha()) &&
AddMaterial( NgAtom::MAT_S, colSpec.GetRed(), colSpec.GetGreen(),
colSpec.GetBlue(), colDiff.GetAlpha()) &&
AddMaterial( NgAtom::MAT_SH, 128 * colSpec.GetAlpha(), 0, 0, 0) ;
}
//----------------------------------------------------------------------------
bool
ObjNewGraphics::AddBackMaterial( const Color& colAmbDiff)
{
return AddMaterial( NgAtom::MAT_B, colAmbDiff.GetRed(), colAmbDiff.GetGreen(),
colAmbDiff.GetBlue(), colAmbDiff.GetAlpha()) ;
}
//----------------------------------------------------------------------------
bool
ObjNewGraphics::AddPoint( const Point3d& ptP)
@@ -234,15 +255,30 @@ ObjNewGraphics::Draw( int nStat, int nMark)
NGALIST::iterator iIter ;
for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) {
switch ( iIter->m_nType) {
case NewGrAtom::VERTS :
case NgAtom::VERTS :
if ( iIter->m_nCount > 0 && iIter->m_nVaoId != 0) {
glBindVertexArray( iIter->m_nVaoId) ;
glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ;
glBindVertexArray( 0) ;
}
break ;
case NewGrAtom::COLOR :
glColor4f( iIter->m_fRed, iIter->m_fGreen, iIter->m_fBlue, iIter->m_fAlpha) ;
case NgAtom::COLOR :
glColor4fv( iIter->m_fCol) ;
break ;
case NgAtom::MAT_A :
glMaterialfv( GL_FRONT, GL_AMBIENT, iIter->m_fCol) ;
break ;
case NgAtom::MAT_D :
glMaterialfv( GL_FRONT, GL_DIFFUSE, iIter->m_fCol) ;
break ;
case NgAtom::MAT_S :
glMaterialfv( GL_FRONT, GL_SPECULAR, iIter->m_fCol) ;
break ;
case NgAtom::MAT_SH :
glMaterialf( GL_FRONT, GL_SHININESS, iIter->m_fCol[0]) ;
break ;
case NgAtom::MAT_B :
glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, iIter->m_fCol) ;
break ;
}
}
@@ -261,16 +297,14 @@ ObjNewGraphics::Draw( int nStat, int nMark)
NGALIST::iterator iIter ;
for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) {
switch ( iIter->m_nType) {
case NewGrAtom::VERTS :
case NgAtom::VERTS :
if ( iIter->m_nCount > 0 && iIter->m_nVaoId != 0) {
glBindVertexArray( iIter->m_nVaoId) ;
glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ;
glBindVertexArray( 0) ;
}
break ;
case NewGrAtom::COLOR :
// si usa il colore di marcatura
break ;
// non si impostano i colori, si usa quello di marcatura
}
}
}
@@ -294,7 +328,7 @@ ObjNewGraphics::DeleteVaoVbo( void)
// ciclo di cancellazione VAO/VBO
NGALIST::iterator iIter ;
for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) {
if ( iIter->m_nType == NewGrAtom::VERTS && iIter->m_nCount > 0) {
if ( iIter->m_nType == NgAtom::VERTS && iIter->m_nCount > 0) {
glBindBuffer( GL_ARRAY_BUFFER, 0) ;
glDeleteBuffers( 1, &iIter->m_nVboId) ;
glBindVertexArray( 0) ;