void CGUITextureGL::Begin(UTILS::Color color) { CBaseTexture* texture = m_texture.m_textures[m_currentFrame]; texture->LoadToGPU(); if (m_diffuse.size()) m_diffuse.m_textures[0]->LoadToGPU(); texture->BindToUnit(0); // Setup Colors m_col[0] = (GLubyte)GET_R(color); m_col[1] = (GLubyte)GET_G(color); m_col[2] = (GLubyte)GET_B(color); m_col[3] = (GLubyte)GET_A(color); bool hasAlpha = m_texture.m_textures[m_currentFrame]->HasAlpha() || m_col[3] < 255; if (m_diffuse.size()) { if (m_col[0] == 255 && m_col[1] == 255 && m_col[2] == 255 && m_col[3] == 255 ) { m_renderSystem->EnableShader(SM_MULTI); } else { m_renderSystem->EnableShader(SM_MULTI_BLENDCOLOR); } hasAlpha |= m_diffuse.m_textures[0]->HasAlpha(); m_diffuse.m_textures[0]->BindToUnit(1); } else { if (m_col[0] == 255 && m_col[1] == 255 && m_col[2] == 255 && m_col[3] == 255) { m_renderSystem->EnableShader(SM_TEXTURE_NOBLEND); } else { m_renderSystem->EnableShader(SM_TEXTURE); } } if (hasAlpha) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE); glEnable(GL_BLEND); } else { glDisable(GL_BLEND); } m_packedVertices.clear(); m_idx.clear(); }
void CGUITextureD3D::Begin(color_t color) { CBaseTexture* texture = m_texture.m_textures[m_currentFrame]; LPDIRECT3DDEVICE9 p3DDevice = g_Windowing.Get3DDevice(); texture->LoadToGPU(); if (m_diffuse.size()) m_diffuse.m_textures[0]->LoadToGPU(); // Set state to render the image texture->BindToUnit(0); p3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); p3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); if (m_diffuse.size()) { m_diffuse.m_textures[0]->BindToUnit(1); p3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); p3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT ); p3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE); p3DDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE); } else { p3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE); p3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); } p3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); p3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 ); p3DDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL ); p3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE ); p3DDevice->SetRenderState( D3DRS_FOGENABLE, FALSE ); p3DDevice->SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_NONE ); p3DDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); p3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); p3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); p3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); p3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); p3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE); p3DDevice->SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 ); m_col = color; }
void CGUITextureGL::Begin(color_t color) { m_col[0] = (GLubyte)GET_R(color); m_col[1] = (GLubyte)GET_G(color); m_col[2] = (GLubyte)GET_B(color); m_col[3] = (GLubyte)GET_A(color); CBaseTexture* texture = m_texture.m_textures[m_currentFrame]; texture->LoadToGPU(); if (m_diffuse.size()) m_diffuse.m_textures[0]->LoadToGPU(); texture->BindToUnit(0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // Turn Blending On glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // diffuse coloring glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); VerifyGLState(); if (m_diffuse.size()) { m_diffuse.m_textures[0]->BindToUnit(1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); VerifyGLState(); } //glDisable(GL_TEXTURE_2D); // uncomment these 2 lines to switch to wireframe rendering //glBegin(GL_LINE_LOOP); glBegin(GL_QUADS); }
void CGUITextureD3D::Begin(color_t color) { int unit = 0; CBaseTexture* texture = m_texture.m_textures[m_currentFrame]; LPDIRECT3DDEVICE9 p3DDevice = g_Windowing.Get3DDevice(); texture->LoadToGPU(); if (m_diffuse.size()) m_diffuse.m_textures[0]->LoadToGPU(); // Set state to render the image texture->BindToUnit(unit); p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP , D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); unit++; if (m_diffuse.size()) { m_diffuse.m_textures[0]->BindToUnit(1); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_CURRENT ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_MODULATE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAARG2, D3DTA_CURRENT ); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP , D3DTOP_MODULATE ); unit++; } if(g_Windowing.UseLimitedColor()) { m_col = D3DCOLOR_RGBA(GET_R(color) * (235 - 16) / 255 , GET_G(color) * (235 - 16) / 255 , GET_B(color) * (235 - 16) / 255 , GET_A(color)); p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP , D3DTOP_ADD ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG1, D3DTA_CURRENT) ; p3DDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_RGBA(16,16,16, 0) ); p3DDevice->SetTextureStageState( unit, D3DTSS_COLORARG2, D3DTA_TFACTOR ); unit++; } else m_col = color; p3DDevice->SetTextureStageState( unit, D3DTSS_COLOROP, D3DTOP_DISABLE); p3DDevice->SetTextureStageState( unit, D3DTSS_ALPHAOP, D3DTOP_DISABLE); p3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); p3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 ); p3DDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL ); p3DDevice->SetRenderState( D3DRS_ZENABLE, FALSE ); p3DDevice->SetRenderState( D3DRS_FOGENABLE, FALSE ); p3DDevice->SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_NONE ); p3DDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); p3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); p3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); p3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); p3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); p3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE); p3DDevice->SetFVF( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 ); }