cae2cf6ab0
- aggiunta gestione dello sfondo anche sfumato - adattamenti per modifiche a ICMdParser.
109 lines
3.1 KiB
C++
109 lines
3.1 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : ObjNewGraphics.cpp Data : 10.02.14 Versione : 1.5b1
|
|
// Contenuto : Implementazione della classe grafica di un oggetto geometrico.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 10.02.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "ObjNewGraphics.h"
|
|
#include "Scene.h"
|
|
|
|
#define glewGetContext() (( m_pScene != nullptr) ? m_pScene->glewGetContext() : nullptr)
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
ObjNewGraphics::~ObjNewGraphics( void)
|
|
{
|
|
// cancello eventuali vecchi vertici
|
|
DeleteVaoVbo() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
ObjNewGraphics::Reset( void)
|
|
{
|
|
m_bValid = false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjNewGraphics::AddPolyLine( const PolyLine& PL)
|
|
{
|
|
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
|
return false ;
|
|
|
|
// cancello eventuali vecchi vertici
|
|
DeleteVaoVbo() ;
|
|
// imposto il nuovo stato
|
|
m_bValid = true ;
|
|
m_nMode = GL_LINE_STRIP ;
|
|
// inserisco i nuovi vertici
|
|
glGenVertexArrays( 1, &m_nVaoId) ;
|
|
if ( m_nVaoId == 0)
|
|
return false ;
|
|
glBindVertexArray( m_nVaoId) ;
|
|
glGenBuffers( 1, &m_nVboId) ;
|
|
glBindBuffer( GL_ARRAY_BUFFER, m_nVboId) ;
|
|
glBufferData( GL_ARRAY_BUFFER, PL.GetPointNbr() * SIZEV3F, NULL, GL_STATIC_DRAW) ;
|
|
Point3d ptP ;
|
|
Vert3f v3V ;
|
|
m_nCount = 0 ;
|
|
for ( bool bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP)) {
|
|
v3V.Set( ptP.x, ptP.y, ptP.z) ;
|
|
glBufferSubData( GL_ARRAY_BUFFER, m_nCount * SIZEV3F, SIZEV3F, &v3V) ;
|
|
++ m_nCount ;
|
|
}
|
|
glVertexPointer( 3, GL_FLOAT, 0, ((void*)(0))) ;
|
|
glEnableClientState( GL_VERTEX_ARRAY) ;
|
|
glBindVertexArray( 0) ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjNewGraphics::Draw( void)
|
|
{
|
|
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
|
return false ;
|
|
|
|
// se vuoto non faccio alcunché
|
|
if ( m_nCount == 0)
|
|
return true ;
|
|
|
|
if ( m_nVaoId != 0) {
|
|
glBindVertexArray( m_nVaoId) ;
|
|
glDrawArrays( m_nMode, 0, m_nCount) ;
|
|
glBindVertexArray( 0) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjNewGraphics::DeleteVaoVbo( void)
|
|
{
|
|
if ( m_pScene == nullptr || ! m_pScene->MakeCurrent())
|
|
return false ;
|
|
|
|
// cancellazione VAO/VBO
|
|
if ( m_nCount > 0) {
|
|
glBindBuffer( GL_ARRAY_BUFFER, 0) ;
|
|
glDeleteBuffers( 1, &m_nVboId) ;
|
|
glBindVertexArray( 0) ;
|
|
glDeleteVertexArrays( 1, &m_nVaoId) ;
|
|
m_nCount = 0 ;
|
|
}
|
|
|
|
return true ;
|
|
}
|