EgtGraphics :

- migliorata gestione textures.
This commit is contained in:
Dario Sassi
2015-10-01 20:48:12 +00:00
parent b839d7ac36
commit 17dc39c758
5 changed files with 105 additions and 39 deletions
+5 -1
View File
@@ -163,7 +163,11 @@ class Scene : public IEGrScene
return true ; }
// Texture
virtual bool LoadTexture( const std::string& sName, const std::string& sFile,
double dDimX, double dDimY, bool bRepeat) ;
double dMMxPix, double dDimX, double dDimY, bool bRepeat) ;
virtual bool UnloadTexture( const std::string& sName) ;
virtual bool GetTexturePixels( const std::string& sName, int& nWidth, int& nHeight) ;
virtual bool GetTextureDimensions( const std::string& sName, double& dDimX, double& dDimY) ;
virtual bool ChangeTextureDimensions( const std::string& sName, double dDimX, double dDimY) ;
public :
// Basic
+28 -32
View File
@@ -416,46 +416,42 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
// eventuale texture
string sTxtName ;
if ( iIter.GetInfo( "!TXT", sTxtName)) {
Frame3d frRef ;
iIter.GetGlobFrame( frRef) ;
if ( iIter.GetInfo( "!TNA", sTxtName)) {
// rendo corrente la texture
GLuint texName ;
double dTextDimS = 400 ;
double dTextDimT = 200 ;
m_TextMgr.GetTextureData( sTxtName, texName, dTextDimS, dTextDimT) ;
double dTextDimS ;
double dTextDimT ;
if ( m_TextMgr.GetTextureData( sTxtName, texName, dTextDimS, dTextDimT)) {
glEnable( GL_TEXTURE_2D) ;
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) ;
glBindTexture( GL_TEXTURE_2D, texName) ;
}
glEnable( GL_TEXTURE_2D) ;
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) ;
glBindTexture( GL_TEXTURE_2D, texName) ;
GLfloat PlaneS[4] ;
GLfloat PlaneT[4] ;
Point3d ptOri(-4009.4378,-2415.5604,0) ;
ptOri.ToLoc( frRef) ;
Vector3d vtX = X_AX ;
vtX.ToLoc( frRef) ;
//vtX.Rotate( Z_AX, 30) ;
Vector3d vtY = Y_AX ;
vtY.ToLoc( frRef) ;
//vtY.Rotate( Z_AX, 30) ;
// recupero il riferimento dell' oggetto
//Frame3d frRef ;
//iIter.GetGlobFrame( frRef) ;
// recupero il riferimento della texture
Frame3d frTxt ;
iIter.GetInfo( "!TFR", frTxt) ;
//frTxt.ToLoc( frRef) ;
// creo piano per la S
PlaneS[0] = GLfloat( vtX.x / dTextDimS) ;
PlaneS[1] = GLfloat( vtX.y / dTextDimS) ;
PlaneS[2] = GLfloat( vtX.z / dTextDimS) ;
PlaneS[3] = GLfloat( - vtX * ( ptOri - ORIG) / dTextDimS) ;
GLfloat PlaneS[4] ;
PlaneS[0] = GLfloat( frTxt.VersX().x / dTextDimS) ;
PlaneS[1] = GLfloat( frTxt.VersX().y / dTextDimS) ;
PlaneS[2] = GLfloat( frTxt.VersX().z / dTextDimS) ;
PlaneS[3] = GLfloat( - frTxt.VersX() * ( frTxt.Orig() - ORIG) / dTextDimS) ;
// creo piano per la T
PlaneT[0] = GLfloat( vtY.x / dTextDimT) ;
PlaneT[1] = GLfloat( vtY.y / dTextDimT) ;
PlaneT[2] = GLfloat( vtY.z / dTextDimT) ;
PlaneT[3] = GLfloat( - vtY * ( ptOri - ORIG) / dTextDimT) ;
// setto generazione texture automatica
GLfloat PlaneT[4] ;
PlaneT[0] = GLfloat( frTxt.VersY().x / dTextDimT) ;
PlaneT[1] = GLfloat( frTxt.VersY().y / dTextDimT) ;
PlaneT[2] = GLfloat( frTxt.VersY().z / dTextDimT) ;
PlaneT[3] = GLfloat( - frTxt.VersY() * ( frTxt.Orig() - ORIG) / dTextDimT) ;
// setto generazione automatica coordinate S e T per texture
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR) ;
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR) ;
glTexGenfv( GL_S, GL_OBJECT_PLANE, PlaneS) ;
glTexGenfv( GL_T, GL_OBJECT_PLANE, PlaneT) ;
glEnable( GL_TEXTURE_GEN_S) ;
glEnable( GL_TEXTURE_GEN_T) ;
}
@@ -463,7 +459,7 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, const MdStMkCol& siObj)
// eseguo visualizzazione
bool bOk = pGraphics->Draw( siObj.nStat, siObj.nMark, bSurfSha, nAlpha, bShowAux) ;
// !!! per textures !!!
// disabilito textures
glDisable( GL_TEXTURE_GEN_S) ;
glDisable( GL_TEXTURE_GEN_T) ;
glDisable( GL_TEXTURE_2D) ;
+34 -3
View File
@@ -15,11 +15,42 @@
#include "stdafx.h"
#include "Scene.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
Scene::LoadTexture( const std::string& sName, const std::string& sFile,
double dDimX, double dDimY, bool bRepeat)
Scene::LoadTexture( const string& sName, const string& sFile,
double dMMxPix, double dDimX, double dDimY, bool bRepeat)
{
return m_TextMgr.LoadTexture( sName, sFile, dDimX, dDimY, bRepeat) ;
return m_TextMgr.LoadTexture( sName, sFile, dMMxPix, dDimX, dDimY, bRepeat) ;
}
//----------------------------------------------------------------------------
bool
Scene::UnloadTexture( const string& sName)
{
return m_TextMgr.UnloadTexture( sName) ;
}
//----------------------------------------------------------------------------
bool
Scene::GetTexturePixels( const string& sName, int& nWidth, int& nHeight)
{
return m_TextMgr.GetPixels( sName, nWidth, nHeight) ;
}
//----------------------------------------------------------------------------
bool
Scene::GetTextureDimensions( const string& sName, double& dDimX, double& dDimY)
{
return m_TextMgr.GetDimensions( sName, dDimX, dDimY) ;
}
//----------------------------------------------------------------------------
bool
Scene::ChangeTextureDimensions( const string& sName, double dDimX, double dDimY)
{
return m_TextMgr.ChangeDimensions( sName, dDimX, dDimY) ;
}
+35 -2
View File
@@ -21,7 +21,6 @@
using namespace std ;
//----------------------------------------------------------------------------
TextureMgr::TextureMgr( void)
{
@@ -42,7 +41,7 @@ TextureMgr::~TextureMgr( void)
//----------------------------------------------------------------------------
bool
TextureMgr::LoadTexture( const string& sName, const string& sFile, double dDimX, double dDimY, bool bRepeat)
TextureMgr::LoadTexture( const string& sName, const string& sFile, double dMMxPix, double dDimX, double dDimY, bool bRepeat)
{
// verifico se immagine già caricata
auto iIter = m_umTextData.find( sName) ;
@@ -93,6 +92,12 @@ TextureMgr::LoadTexture( const string& sName, const string& sFile, double dDimX,
// rendo non corrente questa texture
glBindTexture( GL_TEXTURE_2D, 0) ;
// se dati mm/pixel determino le dimensioni fisiche della texture
if ( dMMxPix > EPS_SMALL && ( dDimX < EPS_SMALL || dDimY < EPS_SMALL)) {
dDimX = dMMxPix * nWidth ;
dDimY = dMMxPix * nHeight ;
}
// salvo i dati
TextureData textData( sFile, dDimX, dDimY, nWidth, nHeight, nTexName, bRepeat) ;
m_umTextData.emplace( sName, textData) ;
@@ -116,6 +121,34 @@ TextureMgr::UnloadTexture( const std::string& sName)
return true ;
}
//----------------------------------------------------------------------------
bool
TextureMgr::GetPixels( const std::string& sName, int& nWidth, int& nHeight)
{
// ricerca della texture di nome dato
auto iIter = m_umTextData.find( sName) ;
if ( iIter == m_umTextData.end())
return false ;
// restituisco le dimensioni in pixel
nWidth = iIter->second.nWidth ;
nHeight = iIter->second.nHeight ;
return true ;
}
//----------------------------------------------------------------------------
bool
TextureMgr::GetDimensions( const std::string& sName, double& dDimX, double& dDimY)
{
// ricerca della texture di nome dato
auto iIter = m_umTextData.find( sName) ;
if ( iIter == m_umTextData.end())
return false ;
// restituisco le dimensioni fisiche
dDimX = iIter->second.dDimX ;
dDimY = iIter->second.dDimY ;
return true ;
}
//----------------------------------------------------------------------------
bool
TextureMgr::ChangeDimensions( const std::string& sName, double dDimX, double dDimY)
+3 -1
View File
@@ -44,7 +44,9 @@ class TextureMgr
public :
bool LoadTexture( const std::string& sName, const std::string& sPath,
double dDimX, double dDimY, bool bRepeat) ;
double dMMxPix, double dDimX, double dDimY, bool bRepeat) ;
bool GetPixels( const std::string& sName, int& nWidth, int& nHeight) ;
bool GetDimensions( const std::string& sName, double& dDimX, double& dDimY) ;
bool ChangeDimensions( const std::string& sName, double dDimX, double dDimY) ;
bool UnloadTexture( const std::string& sName) ;
bool GetTextureData( const std::string& sName, unsigned int& nId, double& dDimX, double& dDimY) ;