From b3f1d8f8745832883d3444e3abf7c27a9a955def Mon Sep 17 00:00:00 2001 From: Kevin Slaughter Date: Fri, 18 Jun 2004 11:02:40 +0000 Subject: [PATCH] Added GL cel shading option for models --- stepmania/src/DancingCharacters.cpp | 51 +++++++++++++------------ stepmania/src/Model.cpp | 59 +++++++++++++++-------------- stepmania/src/Model.h | 1 + stepmania/src/PrefsManager.cpp | 6 +-- stepmania/src/PrefsManager.h | 2 +- stepmania/src/ScreenHowToPlay.cpp | 30 ++++++++------- 6 files changed, 78 insertions(+), 71 deletions(-) diff --git a/stepmania/src/DancingCharacters.cpp b/stepmania/src/DancingCharacters.cpp index a57a666475..eb9cf6cb5b 100644 --- a/stepmania/src/DancingCharacters.cpp +++ b/stepmania/src/DancingCharacters.cpp @@ -8,6 +8,8 @@ #include "song.h" #include "Character.h" #include "StageStats.h" +#include "PrefsManager.h" +#include "SDL_opengl.h" #define DC_X( choice ) THEME->GetMetricF("DancingCharacters",ssprintf("2DCharacterXP%d",choice+1)) #define DC_Y( choice ) THEME->GetMetricF("DancingCharacters",ssprintf("2DCharacterYP%d",choice+1)) @@ -127,10 +129,12 @@ DancingCharacters::DancingCharacters() if( pChar->GetModelPath().empty() ) continue; - if( GAMESTATE->GetNumPlayersEnabled()==2 ) + if( GAMESTATE->GetNumPlayersEnabled()==2 ) { m_Character[p].SetX( MODEL_X_TWO_PLAYERS[p] ); - else + } + else { m_Character[p].SetX( MODEL_X_ONE_PLAYER ); + } switch( GAMESTATE->m_PlayMode ) { @@ -168,7 +172,6 @@ void DancingCharacters::LoadNextSong() m_Character[p].PlayAnimation( "rest" ); } - int Neg1OrPos1() { return rand()%2 ? -1 : +1; } void DancingCharacters::Update( float fDelta ) @@ -176,8 +179,8 @@ void DancingCharacters::Update( float fDelta ) if( GAMESTATE->m_bFreeze ) { // spin the camera Matrix style - m_CameraPanYStart += fDelta*40; - m_CameraPanYEnd += fDelta*40; + //m_CameraPanYStart += fDelta*40; + //m_CameraPanYEnd += fDelta*40; } else { @@ -192,8 +195,9 @@ void DancingCharacters::Update( float fDelta ) FOREACH_PlayerNumber( p ) { - if( GAMESTATE->IsPlayerEnabled(p) ) + if( GAMESTATE->IsPlayerEnabled(p) ) { m_Character[p].Update( fDelta*fUpdateScale ); + } } } @@ -328,25 +332,22 @@ void DancingCharacters::DrawPrimitives() FOREACH_EnabledPlayer( p ) { - bool bFailed = g_CurStageStats.bFailed[p]; - bool bDanger = m_bDrawDangerLight; - - DISPLAY->SetLighting( true ); - RageColor ambient = bFailed ? RageColor(0.2f,0.1f,0.1f,1) : (bDanger ? RageColor(0.4f,0.1f,0.1f,1) : RageColor(0.4f,0.4f,0.4f,1)); - RageColor diffuse = bFailed ? RageColor(0.4f,0.1f,0.1f,1) : (bDanger ? RageColor(0.8f,0.1f,0.1f,1) : RageColor(0.8f,0.8f,0.8f,1)); - RageColor specular = RageColor(0.8f,0.8f,0.8f,1); - - DISPLAY->SetLightDirectional( - 0, - ambient, - diffuse, - specular, - RageVector3(+1, 0, +1) ); - - m_Character[p].Draw(); - - DISPLAY->SetLightOff( 0 ); - DISPLAY->SetLighting( false ); + if(!PREFSMAN->m_bCelShadeModels) { + bool bFailed = g_CurStageStats.bFailed[p]; + bool bDanger = m_bDrawDangerLight; + DISPLAY->SetLighting( true ); + RageColor ambient = bFailed ? RageColor(0.2f,0.1f,0.1f,1) : (bDanger ? RageColor(0.4f,0.1f,0.1f,1) : RageColor(0.4f,0.4f,0.4f,1)); + RageColor diffuse = bFailed ? RageColor(0.4f,0.1f,0.1f,1) : (bDanger ? RageColor(0.8f,0.1f,0.1f,1) : RageColor(0.8f,0.8f,0.8f,1)); + RageColor specular = RageColor(0.8f,0.8f,0.8f,1); + DISPLAY->SetLightDirectional( + 0, + ambient, + diffuse, + specular, + RageVector3(+1, 0, +1) ); + m_Character[p].Draw(); + } + else {m_Character[p].DrawCelShaded();} } diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 72349abb7f..6ae7f56c38 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -11,6 +11,7 @@ #include "ActorUtil.h" #include #include "ModelManager.h" +#include "SDL_opengl.h" const float FRAMES_PER_SECOND = 30; const CString DEFAULT_ANIMATION_NAME = "default"; @@ -421,6 +422,18 @@ bool Model::EarlyAbortDraw() return m_pGeometry == NULL || m_pGeometry->m_Meshes.empty(); } +void Model::DrawCelShaded() +{ + this->SetGlow(RageColor(0,0,0,1)); + glPolygonMode (GL_BACK, GL_LINE); + glLineWidth(4.0f); + this->Draw(); + DISPLAY->ClearZBuffer(); + this->SetGlow(RageColor(1,1,1,0)); + glPolygonMode(GL_BACK, GL_FILL); + this->Draw(); +} + void Model::DrawPrimitives() { /* Don't if we're fully transparent */ @@ -431,7 +444,6 @@ void Model::DrawPrimitives() DISPLAY->Scale( 1, -1, 1 ); // flip Y so positive is up - ////////////////////// // render the diffuse pass ////////////////////// @@ -444,11 +456,20 @@ void Model::DrawPrimitives() msMesh *pMesh = &m_pGeometry->m_Meshes[i]; const RageCompiledGeometry* TempGeometry = m_pTempGeometry ? m_pTempGeometry : m_pGeometry->m_pGeometry; + // apply mesh-specific bone (if any) + if( pMesh->nBoneIndex != -1 ) + { + DISPLAY->PushMatrix(); + + RageMatrix &mat = m_vpBones[pMesh->nBoneIndex].mFinal; + DISPLAY->PreMultMatrix( mat ); + } + if( pMesh->nMaterialIndex != -1 ) // has a material { // apply material msMaterial& mat = m_Materials[ pMesh->nMaterialIndex ]; - + RageColor Emissive = mat.Emissive; RageColor Ambient = mat.Ambient; RageColor Diffuse = mat.Diffuse; @@ -457,18 +478,11 @@ void Model::DrawPrimitives() Ambient *= m_pTempState->diffuse[0]; Diffuse *= m_pTempState->diffuse[0]; - DISPLAY->SetMaterial( - Emissive, - Ambient, - Diffuse, - mat.Specular, - mat.fShininess ); + DISPLAY->SetMaterial( Emissive, Ambient, Diffuse, mat.Specular, mat.fShininess ); // render the first pass with texture 1 DISPLAY->SetTexture( 0, mat.diffuse.ani.GetCurrentTexture() ); DISPLAY->SetSphereEnironmentMapping( mat.diffuse.bSphereMapped ); - // UGLY: This overrides the Actor's BlendMode -// DISPLAY->SetBlendMode( mat.diffuse.blendMode ); // render the second pass with texture 2 if( mat.alpha.ani.GetCurrentTexture() ) @@ -487,25 +501,12 @@ void Model::DrawPrimitives() static const RageColor diffuse( 0.7f,0.7f,0.7f,1 ); static const RageColor specular( 0.2f,0.2f,0.2f,1 ); static const float shininess = 1; - DISPLAY->SetMaterial( - emissive, - ambient, - diffuse, - specular, - shininess ); + DISPLAY->SetMaterial( emissive, ambient, diffuse, specular, shininess ); DISPLAY->ClearAllTextures(); DISPLAY->SetSphereEnironmentMapping( false ); } - - // apply mesh-specific bone (if any) - if( pMesh->nBoneIndex != -1 ) - { - DISPLAY->PushMatrix(); - - RageMatrix &mat = m_vpBones[pMesh->nBoneIndex].mFinal; - DISPLAY->PreMultMatrix( mat ); - } - + + // Draw it DISPLAY->DrawCompiledGeometry( TempGeometry, i, m_pGeometry->m_Meshes ); DISPLAY->SetSphereEnironmentMapping( false ); @@ -530,9 +531,9 @@ void Model::DrawPrimitives() // apply material RageColor emissive = m_pTempState->glow; - RageColor ambient = RageColor(0,0,0,0); - RageColor diffuse = RageColor(0,0,0,0); - RageColor specular = RageColor(0,0,0,0); + RageColor ambient = RageColor(0,0,0,1); + RageColor diffuse = RageColor(0,0,0,1); + RageColor specular = RageColor(0,0,0,1); float shininess = 1; DISPLAY->SetMaterial( diff --git a/stepmania/src/Model.h b/stepmania/src/Model.h index 123172c0b2..5bde65d55b 100644 --- a/stepmania/src/Model.h +++ b/stepmania/src/Model.h @@ -35,6 +35,7 @@ public: virtual void DrawPrimitives(); void AdvanceFrame (float dt); + void DrawCelShaded(); virtual void SetState( int iNewState ); float GetCurFrame(); diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index 63e72874bc..d12c2241fe 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -41,7 +41,7 @@ void PrefsManager::Init() m_iMaxTextureResolution = 2048; m_iRefreshRate = REFRESH_DEFAULT; m_bOnlyDedicatedMenuButtons = false; - m_bCelShadeDancers = false; // Work-In-Progress.. disable by default. + m_bCelShadeModels = false; // Work-In-Progress.. disable by default. #ifdef DEBUG m_bShowStats = true; #else @@ -332,7 +332,7 @@ void PrefsManager::ReadPrefsFromFile( CString sIni ) ini.GetValue( "Options", "ScreenWidth", m_fScreenWidth ); ini.GetValue( "Options", "ScreenHeight", m_fScreenHeight ); #endif - ini.GetValue( "Options", "CelShadeDancers", m_bCelShadeDancers ); + ini.GetValue( "Options", "CelShadeModels", m_bCelShadeModels ); ini.GetValue( "Options", "DisplayWidth", m_iDisplayWidth ); ini.GetValue( "Options", "DisplayHeight", m_iDisplayHeight ); ini.GetValue( "Options", "DisplayColorDepth", m_iDisplayColorDepth ); @@ -564,7 +564,7 @@ void PrefsManager::SaveGlobalPrefsToDisk() const IniFile ini; ini.SetValue( "Options", "Windowed", m_bWindowed ); - ini.SetValue( "Options", "CelShadeDancers", m_bCelShadeDancers ); + ini.SetValue( "Options", "CelShadeModels", m_bCelShadeModels ); ini.SetValue( "Options", "DisplayWidth", m_iDisplayWidth ); ini.SetValue( "Options", "DisplayHeight", m_iDisplayHeight ); ini.SetValue( "Options", "DisplayColorDepth", m_iDisplayColorDepth ); diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index fab00d5a17..4033cb3548 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -199,7 +199,7 @@ public: bool m_bHideDefaultNoteSkin; int m_iMaxHighScoresPerListForMachine; int m_iMaxHighScoresPerListForPlayer; - bool m_bCelShadeDancers; + bool m_bCelShadeModels; // Number of seconds it takes for a button on the controller to release // after pressed. diff --git a/stepmania/src/ScreenHowToPlay.cpp b/stepmania/src/ScreenHowToPlay.cpp index 8b20b5b11a..d1d65f3abe 100644 --- a/stepmania/src/ScreenHowToPlay.cpp +++ b/stepmania/src/ScreenHowToPlay.cpp @@ -304,19 +304,23 @@ void ScreenHowToPlay::DrawPrimitives() if( m_pmDancePad || m_pmCharacter ) { - DISPLAY->SetLighting( true ); - DISPLAY->SetLightDirectional( - 0, - RageColor(0.5,0.5,0.5,1), - RageColor(1,1,1,1), - RageColor(0,0,0,1), - RageVector3(0, 0, 1) ); - - if( m_pmCharacter ) - m_pmCharacter->Draw(); - if( m_pmDancePad ) - m_pmDancePad->Draw(); - + if(!PREFSMAN->m_bCelShadeModels) { + DISPLAY->SetLighting( true ); + DISPLAY->SetLightDirectional( + 0, + RageColor(0.5,0.5,0.5,1), + RageColor(1,1,1,1), + RageColor(0,0,0,1), + RageVector3(0, 0, 1) ); + + if( m_pmCharacter ) {m_pmCharacter->Draw();} + if( m_pmDancePad ) {m_pmDancePad->Draw();} + } + else { + if( m_pmDancePad ) {m_pmDancePad->DrawCelShaded();} + if( m_pmCharacter ) {m_pmCharacter->DrawCelShaded();} + } + DISPLAY->SetLightOff( 0 ); DISPLAY->SetLighting( false );