Esempio n. 1
0
void KPboardView::Draw(bool render /* = true */) const
{
#ifdef DRAW_TEST
    DrawCuboid(-0.5);
    return;
#else

    GLfloat x0, y0;

    // set material
    glCallList(DisplayList + BRONZE_MATERIAL);

    ///////////////////////////////////////////////////////////////////////
    // Draw all Tokens
    //
    // Loop for drawing all tokens according to their position on the board
    // One token may be in animation mode or not
    ///////////////////////////////////////////////////////////////////////
    auto tokenId = TokenId::GREEN1;

    do
    {
        glColor4f(1.0, 1.0, 1.0, 1.0);
        glEnable(GL_TEXTURE_2D);

        switch (tokenId)
        {
            case TokenId::GREEN1:
            case TokenId::GREEN2:
            case TokenId::GREEN3:
            case TokenId::GREEN4:
                glBindTexture(GL_TEXTURE_2D, textureIds[0]);
                break;

            case TokenId::WHITE1:
            case TokenId::WHITE2:
            case TokenId::WHITE3:
            case TokenId::WHITE4:
            case TokenId::WHITE5:
                glBindTexture(GL_TEXTURE_2D, textureIds[1]);
                break;

            case TokenId::RED1:
                glBindTexture(GL_TEXTURE_2D, textureIds[2]);
                break;

            default:
                break;
        }

        auto tokenIndex = static_cast<std::size_t>(tokenId);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        GetTokenCoordinates(tokenId, &x0, &y0);

        if (emphasizedToken == tokenId)
        {
            continue;
        }

        glTranslatef(x0, y0, 0.0);
        // needed for Token Selection:
        glLoadName(tokenIndex);
        DrawToken(tokenId);
        glTranslatef(-x0, -y0, 0.0);
    }
    while (++tokenId != TokenId::GREEN1);

    //////////////////////////////////////
    // Draw the board (after the tokens!)
    //////////////////////////////////////
    glBindTexture(GL_TEXTURE_2D, textureIds[3]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    if (render)
    {
        glCallList(DisplayList + BOARD);
    }

    ////////////////////////////////////////////////////////////
    // Draw emphasized token separatey with depth buffer set to
    // readonly and blending over texture and emission color
    ////////////////////////////////////////////////////////////
    tokenId = emphasizedToken;

    if (tokenId != TokenId::EMPTY)
    {
        GetTokenCoordinates(tokenId, &x0, &y0);
        glTranslatef(x0, y0, 0.0);
        // needed for Token Selection:
        glLoadName(static_cast<std::size_t>(tokenId));

        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
        GLfloat color[] =
        {
            0.6f + 0.4f * mat_value, 0.0f, 0.0f, 1.0f
        };
        glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);
        DrawToken(tokenId);

        glTranslatef(-x0, -y0, 0.0);
    }

    // Avoid to bind the texture by another glTexImage2D:
    glBindTexture(GL_TEXTURE_2D, 0);
#endif
    glDisable(GL_TEXTURE_2D);
}
void CGameTokenSystem::DebugDraw()
{
	#ifdef _GAMETOKENSDEBUGINFO	

	static bool drawnLastFrame = false;
	float color[]={1.0f, 1.0f, 1.0f, 1.0f};

	if (CGameTokenSystem::m_CVarShowDebugInfo==0 || CGameTokenSystem::m_CVarShowDebugInfo==3)
	{
		drawnLastFrame = false;
		return;
	}
	
	if (!drawnLastFrame)
		ClearDebugHistory();
	
	drawnLastFrame = true;
	
	if (gEnv->pConsole->IsOpened())
		return;
	
	IRenderer * pRenderer = gEnv->pRenderer;
	if(!pRenderer)
		return;
	
	int linesDrawn = 0;
	
	{
		TDebugListMap::iterator iter = m_debugList.begin();
		int i = 0;
		while (iter != m_debugList.end())
		{
			CGameToken* pToken = GetToken( iter->c_str() );
			
			DrawToken( iter->c_str(), GetTokenDebugString( pToken ), pToken ? pToken->GetLastChangeTime() : CTimeValue(), i );
				
			++iter;
			++i;
		}
		linesDrawn = i;
	}
	
	{
		int numHistoryLines = GetHistoryBufferSize();
		if (numHistoryLines>0)
		{
			string buf;
			pRenderer->Draw2dLabel(20.0f+m_CVarPosX,20.0f+m_CVarPosY+12.0f*(float)linesDrawn, 1.2f, color, false, "---------------HISTORY----------------");
			linesDrawn++;
			for (int i=0; i<numHistoryLines; i++)
			{
				uint index = ( m_historyStart + i ) % numHistoryLines;
				SDebugHistoryEntry& entry = m_debugHistory[index];
				DrawToken( entry.tokenName, entry.value, entry.timeChanged, linesDrawn+i );
			}
		}
	}
	
	
	#endif
}