本文整理汇总了C++中CShaderProgramPtr::BindTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ CShaderProgramPtr::BindTexture方法的具体用法?C++ CShaderProgramPtr::BindTexture怎么用?C++ CShaderProgramPtr::BindTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CShaderProgramPtr
的用法示例。
在下文中一共展示了CShaderProgramPtr::BindTexture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrepareShader
/**
* Set up all the uniforms for a shader pass.
*/
void TerrainRenderer::PrepareShader(const CShaderProgramPtr& shader, ShadowMap* shadow)
{
shader->Uniform("transform", g_Renderer.GetViewCamera().GetViewProjection());
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
if (shadow)
{
shader->BindTexture("shadowTex", shadow->GetTexture());
shader->Uniform("shadowTransform", shadow->GetTextureMatrix());
const float* offsets = shadow->GetFilterOffsets();
shader->Uniform("shadowOffsets1", offsets[0], offsets[1], offsets[2], offsets[3]);
shader->Uniform("shadowOffsets2", offsets[4], offsets[5], offsets[6], offsets[7]);
}
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
shader->BindTexture("losTex", los.GetTexture());
shader->Uniform("losTransform", los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);
shader->Uniform("ambient", lightEnv.m_TerrainAmbientColor);
shader->Uniform("sunColor", lightEnv.m_SunColor);
shader->BindTexture("blendTex", g_Renderer.m_hCompositeAlphaMap);
}
示例2: PrepareShader
/**
* Set up all the uniforms for a shader pass.
*/
void TerrainRenderer::PrepareShader(const CShaderProgramPtr& shader, ShadowMap* shadow)
{
shader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
shader->Uniform(str_cameraPos, g_Renderer.GetViewCamera().GetOrientation().GetTranslation());
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
if (shadow)
{
shader->BindTexture(str_shadowTex, shadow->GetTexture());
shader->Uniform(str_shadowTransform, shadow->GetTextureMatrix());
int width = shadow->GetWidth();
int height = shadow->GetHeight();
shader->Uniform(str_shadowScale, width, height, 1.0f / width, 1.0f / height);
}
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
shader->BindTexture(str_losTex, los.GetTextureSmooth());
shader->Uniform(str_losTransform, los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);
shader->Uniform(str_ambient, lightEnv.m_TerrainAmbientColor);
shader->Uniform(str_sunColor, lightEnv.m_SunColor);
shader->Uniform(str_sunDir, lightEnv.GetSunDir());
shader->Uniform(str_fogColor, lightEnv.m_FogColor);
shader->Uniform(str_fogParams, lightEnv.m_FogFactor, lightEnv.m_FogMax, 0.f, 0.f);
}
示例3: ApplyEffect
void CPostprocManager::ApplyEffect(CShaderTechniquePtr &shaderTech1, int pass)
{
// select the other FBO for rendering
if (!m_WhichBuffer)
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PingFbo);
else
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PongFbo);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
shaderTech1->BeginPass(pass);
CShaderProgramPtr shader = shaderTech1->GetShader(pass);
shader->Bind();
// Use the textures from the current FBO as input to the shader.
// We also bind a bunch of other textures and parameters, but since
// this only happens once per frame the overhead is negligible.
if (m_WhichBuffer)
shader->BindTexture(str_renderedTex, m_ColourTex1);
else
shader->BindTexture(str_renderedTex, m_ColourTex2);
shader->BindTexture(str_depthTex, m_DepthTex);
shader->BindTexture(str_blurTex2, m_BlurTex2a);
shader->BindTexture(str_blurTex4, m_BlurTex4a);
shader->BindTexture(str_blurTex8, m_BlurTex8a);
shader->Uniform(str_width, m_Width);
shader->Uniform(str_height, m_Height);
shader->Uniform(str_zNear, g_Game->GetView()->GetNear());
shader->Uniform(str_zFar, g_Game->GetView()->GetFar());
shader->Uniform(str_brightness, g_LightEnv.m_Brightness);
shader->Uniform(str_hdr, g_LightEnv.m_Contrast);
shader->Uniform(str_saturation, g_LightEnv.m_Saturation);
shader->Uniform(str_bloom, g_LightEnv.m_Bloom);
glBegin(GL_QUADS);
glColor4f(1.f, 1.f, 1.f, 1.f);
glTexCoord2f(1.0, 1.0); glVertex2f(1,1);
glTexCoord2f(0.0, 1.0); glVertex2f(-1,1);
glTexCoord2f(0.0, 0.0); glVertex2f(-1,-1);
glTexCoord2f(1.0, 0.0); glVertex2f(1,-1);
glEnd();
shader->Unbind();
shaderTech1->EndPass(pass);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
m_WhichBuffer = !m_WhichBuffer;
}
示例4: InterpolateLOS
void CLOSTexture::InterpolateLOS()
{
if (CRenderer::IsInitialised() && !g_Renderer.m_Options.m_SmoothLOS)
return;
if (m_Dirty)
{
RecomputeTexture(0);
m_Dirty = false;
}
GLint originalFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &originalFBO);
pglBindFramebufferEXT(GL_FRAMEBUFFER, m_smoothFbo);
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
whichTex ? m_TextureSmooth2 : m_TextureSmooth1, 0);
GLenum status = pglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
{
LOGWARNING(L"LOS framebuffer object incomplete: 0x%04X", status);
}
m_smoothShader->BeginPass();
CShaderProgramPtr shader = m_smoothShader->GetShader();
shader->Bind();
shader->BindTexture("losTex1", m_Texture);
shader->BindTexture("losTex2", whichTex ? m_TextureSmooth1 : m_TextureSmooth2);
shader->Uniform("delta", (float)g_Renderer.GetTimeManager().GetFrameDelta() * 4.0f, 0.0f, 0.0f, 0.0f);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, m_TextureSize, m_TextureSize);
glBegin(GL_QUADS);
glColor4f(1.f, 1.f, 1.f, 1.f);
glTexCoord2f(1.0, 1.0); glVertex2f(1,1);
glTexCoord2f(0.0, 1.0); glVertex2f(-1,1);
glTexCoord2f(0.0, 0.0); glVertex2f(-1,-1);
glTexCoord2f(1.0, 0.0); glVertex2f(1,-1);
glEnd();
glPopAttrib();
shader->Unbind();
m_smoothShader->EndPass();
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, originalFBO);
whichTex = !whichTex;
}
示例5: Bind
void CParticleEmitter::Bind(const CShaderProgramPtr& shader)
{
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
shader->BindTexture(str_losTex, los.GetTextureSmooth());
shader->Uniform(str_losTransform, los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
shader->Uniform(str_sunColor, lightEnv.m_SunColor);
shader->Uniform(str_fogColor, lightEnv.m_FogColor);
shader->Uniform(str_fogParams, lightEnv.m_FogFactor, lightEnv.m_FogMax, 0.f, 0.f);
shader->BindTexture(str_baseTex, m_Type->m_Texture);
pglBlendEquationEXT(m_Type->m_BlendEquation);
glBlendFunc(m_Type->m_BlendFuncSrc, m_Type->m_BlendFuncDst);
}
示例6: Render
void CTexturedLineRData::Render(const SOverlayTexturedLine& line, const CShaderProgramPtr& shader)
{
if (!m_VB || !m_VBIndices)
return; // might have failed to allocate
// -- render main line quad strip ----------------------
const int streamFlags = shader->GetStreamFlags();
shader->BindTexture("baseTex", line.m_TextureBase->GetHandle());
shader->BindTexture("maskTex", line.m_TextureMask->GetHandle());
shader->Uniform("objectColor", line.m_Color);
GLsizei stride = sizeof(CTexturedLineRData::SVertex);
CTexturedLineRData::SVertex* vertexBase = reinterpret_cast<CTexturedLineRData::SVertex*>(m_VB->m_Owner->Bind());
if (streamFlags & STREAM_POS)
shader->VertexPointer(3, GL_FLOAT, stride, &vertexBase->m_Position[0]);
if (streamFlags & STREAM_UV0)
shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, stride, &vertexBase->m_UVs[0]);
if (streamFlags & STREAM_UV1)
shader->TexCoordPointer(GL_TEXTURE1, 2, GL_FLOAT, stride, &vertexBase->m_UVs[0]);
u8* indexBase = m_VBIndices->m_Owner->Bind();
shader->AssertPointersBound();
glDrawElements(GL_TRIANGLES, m_VBIndices->m_Count, GL_UNSIGNED_SHORT, indexBase + sizeof(u16)*m_VBIndices->m_Index);
g_Renderer.GetStats().m_DrawCalls++;
g_Renderer.GetStats().m_OverlayTris += m_VBIndices->m_Count/3;
}
示例7: Bind
void CParticleEmitter::Bind(const CShaderProgramPtr& shader)
{
shader->BindTexture("baseTex", m_Type->m_Texture);
shader->Uniform("fogColor", g_Renderer.GetLightEnv().m_FogColor);
shader->Uniform("fogParams", g_Renderer.GetLightEnv().m_FogFactor, g_Renderer.GetLightEnv().m_FogMax, 0.f, 0.f);
pglBlendEquationEXT(m_Type->m_BlendEquation);
glBlendFunc(m_Type->m_BlendFuncSrc, m_Type->m_BlendFuncDst);
}
示例8:
void CPostprocManager::ApplyBlurDownscale2x(GLuint inTex, GLuint outTex, int inWidth, int inHeight)
{
// Bind inTex to framebuffer for rendering.
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_BloomFbo);
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, outTex, 0);
// Get bloom shader with instructions to simply copy texels.
CShaderDefines defines;
defines.Add(str_BLOOM_NOP, str_1);
CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_bloom,
g_Renderer.GetSystemShaderDefines(), defines);
tech->BeginPass();
CShaderProgramPtr shader = tech->GetShader();
GLuint renderedTex = inTex;
// Cheat by creating high quality mipmaps for inTex, so the copying operation actually
// produces good scaling due to hardware filtering.
glBindTexture(GL_TEXTURE_2D, renderedTex);
pglGenerateMipmapEXT(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
shader->BindTexture(str_renderedTex, renderedTex);
const SViewPort oldVp = g_Renderer.GetViewport();
const SViewPort vp = { 0, 0, inWidth / 2, inHeight / 2 };
g_Renderer.SetViewport(vp);
float quadVerts[] = {
1.0f, 1.0f,
-1.0f, 1.0f,
-1.0f, -1.0f,
-1.0f, -1.0f,
1.0f, -1.0f,
1.0f, 1.0f
};
float quadTex[] = {
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f
};
shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 0, quadTex);
shader->VertexPointer(2, GL_FLOAT, 0, quadVerts);
shader->AssertPointersBound();
glDrawArrays(GL_TRIANGLES, 0, 6);
g_Renderer.SetViewport(oldVp);
tech->EndPass();
}
示例9: BeginPass
int ShaderRenderModifier::BeginPass(int pass)
{
m_Technique.BeginPass(pass);
CShaderProgramPtr shader = m_Technique.GetShader(pass);
if (GetShadowMap() && shader->HasTexture("shadowTex"))
{
shader->BindTexture("shadowTex", GetShadowMap()->GetTexture());
shader->Uniform("shadowTransform", GetShadowMap()->GetTextureMatrix());
const float* offsets = GetShadowMap()->GetFilterOffsets();
shader->Uniform("shadowOffsets1", offsets[0], offsets[1], offsets[2], offsets[3]);
shader->Uniform("shadowOffsets2", offsets[4], offsets[5], offsets[6], offsets[7]);
}
if (GetLightEnv())
{
shader->Uniform("ambient", GetLightEnv()->m_UnitsAmbientColor);
shader->Uniform("sunDir", GetLightEnv()->GetSunDir());
shader->Uniform("sunColor", GetLightEnv()->m_SunColor);
}
if (shader->HasTexture("losTex"))
{
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
shader->BindTexture("losTex", los.GetTexture());
// Don't bother sending the whole matrix, we just need two floats (scale and translation)
shader->Uniform("losTransform", los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);
}
m_BindingInstancingTransform = shader->GetUniformBinding("instancingTransform");
m_BindingShadingColor = shader->GetUniformBinding("shadingColor");
m_BindingObjectColor = shader->GetUniformBinding("objectColor");
m_BindingPlayerColor = shader->GetUniformBinding("playerColor");
return shader->GetStreamFlags();
}
示例10: BeginPass
void ShaderRenderModifier::BeginPass(const CShaderProgramPtr& shader)
{
shader->Uniform("transform", g_Renderer.GetViewCamera().GetViewProjection());
shader->Uniform("cameraPos", g_Renderer.GetViewCamera().GetOrientation().GetTranslation());
if (GetShadowMap() && shader->GetTextureBinding("shadowTex").Active())
{
shader->BindTexture("shadowTex", GetShadowMap()->GetTexture());
shader->Uniform("shadowTransform", GetShadowMap()->GetTextureMatrix());
int width = GetShadowMap()->GetWidth();
int height = GetShadowMap()->GetHeight();
shader->Uniform("shadowScale", width, height, 1.0f / width, 1.0f / height);
}
if (GetLightEnv())
{
shader->Uniform("ambient", GetLightEnv()->m_UnitsAmbientColor);
shader->Uniform("sunDir", GetLightEnv()->GetSunDir());
shader->Uniform("sunColor", GetLightEnv()->m_SunColor);
shader->Uniform("fogColor", GetLightEnv()->m_FogColor);
shader->Uniform("fogParams", GetLightEnv()->m_FogFactor, GetLightEnv()->m_FogMax, 0.f, 0.f);
}
if (shader->GetTextureBinding("losTex").Active())
{
CLOSTexture& los = g_Renderer.GetScene().GetLOSTexture();
shader->BindTexture("losTex", los.GetTextureSmooth());
// Don't bother sending the whole matrix, we just need two floats (scale and translation)
shader->Uniform("losTransform", los.GetTextureMatrix()[0], los.GetTextureMatrix()[12], 0.f, 0.f);
}
m_BindingInstancingTransform = shader->GetUniformBinding("instancingTransform");
m_BindingShadingColor = shader->GetUniformBinding("shadingColor");
m_BindingPlayerColor = shader->GetUniformBinding("playerColor");
}
示例11: RenderDebugTexture
void ShadowMap::RenderDebugTexture()
{
glDepthMask(0);
glDisable(GL_DEPTH_TEST);
#if !CONFIG2_GLES
g_Renderer.BindTexture(0, m->Texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
#endif
CShaderTechniquePtr texTech = g_Renderer.GetShaderManager().LoadEffect("gui_basic");
texTech->BeginPass();
CShaderProgramPtr texShader = texTech->GetShader();
texShader->Uniform("transform", GetDefaultGuiMatrix());
texShader->BindTexture("tex", m->Texture);
float s = 256.f;
float boxVerts[] = {
0,0, 0,s, s,0,
s,0, 0,s, s,s
};
float boxUV[] = {
0,0, 0,1, 1,0,
1,0, 0,1, 1,1
};
texShader->VertexPointer(2, GL_FLOAT, 0, boxVerts);
texShader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 0, boxUV);
texShader->AssertPointersBound();
glDrawArrays(GL_TRIANGLES, 0, 6);
texTech->EndPass();
#if !CONFIG2_GLES
g_Renderer.BindTexture(0, m->Texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
#endif
glEnable(GL_DEPTH_TEST);
glDepthMask(1);
}
示例12:
void CPostprocManager::ApplyBlurDownscale2x(GLuint inTex, GLuint outTex, int inWidth, int inHeight)
{
// Bind inTex to framebuffer for rendering.
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_BloomFbo);
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, outTex, 0);
// Get bloom shader with instructions to simply copy texels.
CShaderDefines defines;
defines.Add(str_BLOOM_NOP, str_1);
CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_bloom,
g_Renderer.GetSystemShaderDefines(), defines);
tech->BeginPass();
CShaderProgramPtr shader = tech->GetShader();
GLuint renderedTex = inTex;
// Cheat by creating high quality mipmaps for inTex, so the copying operation actually
// produces good scaling due to hardware filtering.
glBindTexture(GL_TEXTURE_2D, renderedTex);
pglGenerateMipmapEXT(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
shader->BindTexture(str_renderedTex, renderedTex);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, inWidth / 2, inHeight / 2);
glBegin(GL_QUADS);
glColor4f(1.f, 1.f, 1.f, 1.f);
glTexCoord2f(1.0, 1.0); glVertex2f(1,1);
glTexCoord2f(0.0, 1.0); glVertex2f(-1,1);
glTexCoord2f(0.0, 0.0); glVertex2f(-1,-1);
glTexCoord2f(1.0, 0.0); glVertex2f(1,-1);
glEnd();
glPopAttrib();
tech->EndPass();
}
示例13: Draw
// TODO: render the minimap in a framebuffer and just draw the frambuffer texture
// most of the time, updating the framebuffer twice a frame.
// Here it updates as ping-pong either texture or vertex array each sec to lower gpu stalling
// (those operations cause a gpu sync, which slows down the way gpu works)
void CMiniMap::Draw()
{
PROFILE3("render minimap");
// The terrain isn't actually initialized until the map is loaded, which
// happens when the game is started, so abort until then.
if(!(GetGUI() && g_Game && g_Game->IsGameStarted()))
return;
CSimulation2* sim = g_Game->GetSimulation2();
CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY);
ENSURE(cmpRangeManager);
// Set our globals in case they hadn't been set before
m_Camera = g_Game->GetView()->GetCamera();
m_Terrain = g_Game->GetWorld()->GetTerrain();
m_Width = (u32)(m_CachedActualSize.right - m_CachedActualSize.left);
m_Height = (u32)(m_CachedActualSize.bottom - m_CachedActualSize.top);
m_MapSize = m_Terrain->GetVerticesPerSide();
m_TextureSize = (GLsizei)round_up_to_pow2((size_t)m_MapSize);
m_MapScale = (cmpRangeManager->GetLosCircular() ? 1.f : 1.414f);
if(!m_TerrainTexture || g_GameRestarted)
CreateTextures();
// only update 2x / second
// (note: since units only move a few pixels per second on the minimap,
// we can get away with infrequent updates; this is slow)
// TODO: store frequency in a config file?
static double last_time;
const double cur_time = timer_Time();
const bool doUpdate = cur_time - last_time > 0.5;
if(doUpdate)
{
last_time = cur_time;
if(m_TerrainDirty)
RebuildTerrainTexture();
}
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
CMatrix3D matrix = GetDefaultGuiMatrix();
glLoadMatrixf(&matrix._11);
// Disable depth updates to prevent apparent z-fighting-related issues
// with some drivers causing units to get drawn behind the texture
glDepthMask(0);
CShaderProgramPtr shader;
CShaderTechniquePtr tech;
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
CShaderDefines defines;
defines.Add(str_MINIMAP_BASE, str_1);
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), defines);
tech->BeginPass();
shader = tech->GetShader();
}
const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom;
const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top;
const float z = GetBufferedZ();
const float texCoordMax = (float)(m_MapSize - 1) / (float)m_TextureSize;
const float angle = GetAngle();
// Draw the main textured quad
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
shader->BindTexture(str_baseTex, m_TerrainTexture);
else
g_Renderer.BindTexture(0, m_TerrainTexture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
DrawTexture(shader, texCoordMax, angle, x, y, x2, y2, z);
// Draw territory boundaries
CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture();
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
shader->BindTexture(str_baseTex, territoryTexture.GetTexture());
else
territoryTexture.BindTexture(0);
glEnable(GL_BLEND);
glMatrixMode(GL_TEXTURE);
glLoadMatrixf(territoryTexture.GetMinimapTextureMatrix());
glMatrixMode(GL_MODELVIEW);
DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z);
//.........这里部分代码省略.........
示例14: RenderSky
///////////////////////////////////////////////////////////////////
// Render sky
void SkyManager::RenderSky()
{
#if CONFIG2_GLES
#warning TODO: implement SkyManager::RenderSky for GLES
#else
// Draw the sky as a small box around the camera position, with depth write enabled.
// This will be done before anything else is drawn so we'll be overlapped by everything else.
// Note: The coordinates for this were set up through a rather cumbersome trial-and-error
// process - there might be a smarter way to do it, but this seems to work.
// Do nothing unless SetSkySet was called
if (m_SkySet.empty())
return;
glDepthMask( GL_FALSE );
pglActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Translate so we are at the camera in the X and Z directions, but
// put the horizon at a fixed height regardless of camera Y
const CCamera& camera = g_Renderer.GetViewCamera();
CVector3D pos = camera.m_Orientation.GetTranslation();
glTranslatef( pos.X, m_HorizonHeight, pos.Z );
// Rotate so that the "left" face, which contains the brightest part of each
// skymap, is in the direction of the sun from our light environment
glRotatef( 90.0f + RADTODEG(g_Renderer.GetLightEnv().GetRotation()), 0.0f, 1.0f, 0.0f );
// Distance to draw the faces at
const float D = 2000.0;
CShaderProgramPtr shader;
CShaderTechniquePtr skytech;
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
{
skytech = g_Renderer.GetShaderManager().LoadEffect("sky_simple");
skytech->BeginPass();
shader = skytech->GetShader();
}
// Front face (positive Z)
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
shader->BindTexture("baseTex", m_SkyTexture[FRONT]);
else
m_SkyTexture[FRONT]->Bind();
glBegin( GL_QUADS );
glTexCoord2f( 0, 1 );
glVertex3f( -D, -D, +D );
glTexCoord2f( 1, 1 );
glVertex3f( +D, -D, +D );
glTexCoord2f( 1, 0 );
glVertex3f( +D, +D, +D );
glTexCoord2f( 0, 0 );
glVertex3f( -D, +D, +D );
glEnd();
// Back face (negative Z)
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
shader->BindTexture("baseTex", m_SkyTexture[BACK]);
else
m_SkyTexture[BACK]->Bind();
glBegin( GL_QUADS );
glTexCoord2f( 1, 1 );
glVertex3f( -D, -D, -D );
glTexCoord2f( 1, 0 );
glVertex3f( -D, +D, -D );
glTexCoord2f( 0, 0 );
glVertex3f( +D, +D, -D );
glTexCoord2f( 0, 1 );
glVertex3f( +D, -D, -D );
glEnd();
// Right face (negative X)
if (g_Renderer.GetRenderPath() == CRenderer::RP_SHADER)
shader->BindTexture("baseTex", m_SkyTexture[RIGHT]);
else
m_SkyTexture[RIGHT]->Bind();
glBegin( GL_QUADS );
glTexCoord2f( 0, 1 );
glVertex3f( -D, -D, -D );
glTexCoord2f( 1, 1 );
glVertex3f( -D, -D, +D );
glTexCoord2f( 1, 0 );
glVertex3f( -D, +D, +D );
glTexCoord2f( 0, 0 );
glVertex3f( -D, +D, -D );
glEnd();
//.........这里部分代码省略.........
示例15: Draw
void GUIRenderer::Draw(DrawCalls& Calls, float Z)
{
// Called every frame, to draw the object (based on cached calculations)
// TODO: batching by shader/texture/etc would be nice
CMatrix3D matrix = GetDefaultGuiMatrix();
glDisable(GL_BLEND);
// Set LOD bias so mipmapped textures are prettier
#if CONFIG2_GLES
#warning TODO: implement GUI LOD bias for GLES
#else
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -1.f);
#endif
// Iterate through each DrawCall, and execute whatever drawing code is being called
for (DrawCalls::const_iterator cit = Calls.begin(); cit != Calls.end(); ++cit)
{
cit->m_Shader->BeginPass();
CShaderProgramPtr shader = cit->m_Shader->GetShader();
shader->Uniform(str_transform, matrix);
if (cit->m_HasTexture)
{
shader->Uniform(str_color, cit->m_ShaderColorParameter);
shader->BindTexture(str_tex, cit->m_Texture);
if (cit->m_EnableBlending || cit->m_Texture->HasAlpha()) // (shouldn't call HasAlpha before BindTexture)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
}
CRect TexCoords = cit->ComputeTexCoords();
// Ensure the quad has the correct winding order, and update texcoords to match
CRect Verts = cit->m_Vertices;
if (Verts.right < Verts.left)
{
std::swap(Verts.right, Verts.left);
std::swap(TexCoords.right, TexCoords.left);
}
if (Verts.bottom < Verts.top)
{
std::swap(Verts.bottom, Verts.top);
std::swap(TexCoords.bottom, TexCoords.top);
}
std::vector<float> data;
#define ADD(u, v, x, y, z) STMT(data.push_back(u); data.push_back(v); data.push_back(x); data.push_back(y); data.push_back(z))
ADD(TexCoords.left, TexCoords.bottom, Verts.left, Verts.bottom, Z + cit->m_DeltaZ);
ADD(TexCoords.right, TexCoords.bottom, Verts.right, Verts.bottom, Z + cit->m_DeltaZ);
ADD(TexCoords.right, TexCoords.top, Verts.right, Verts.top, Z + cit->m_DeltaZ);
ADD(TexCoords.right, TexCoords.top, Verts.right, Verts.top, Z + cit->m_DeltaZ);
ADD(TexCoords.left, TexCoords.top, Verts.left, Verts.top, Z + cit->m_DeltaZ);
ADD(TexCoords.left, TexCoords.bottom, Verts.left, Verts.bottom, Z + cit->m_DeltaZ);
#undef ADD
shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]);
shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]);
glDrawArrays(GL_TRIANGLES, 0, 6);
}
else
{
shader->Uniform(str_color, cit->m_BackColor);
if (cit->m_EnableBlending)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
}
// Ensure the quad has the correct winding order
CRect Verts = cit->m_Vertices;
if (Verts.right < Verts.left)
std::swap(Verts.right, Verts.left);
if (Verts.bottom < Verts.top)
std::swap(Verts.bottom, Verts.top);
std::vector<float> data;
#define ADD(x, y, z) STMT(data.push_back(x); data.push_back(y); data.push_back(z))
ADD(Verts.left, Verts.bottom, Z + cit->m_DeltaZ);
ADD(Verts.right, Verts.bottom, Z + cit->m_DeltaZ);
ADD(Verts.right, Verts.top, Z + cit->m_DeltaZ);
ADD(Verts.right, Verts.top, Z + cit->m_DeltaZ);
ADD(Verts.left, Verts.top, Z + cit->m_DeltaZ);
ADD(Verts.left, Verts.bottom, Z + cit->m_DeltaZ);
shader->VertexPointer(3, GL_FLOAT, 3*sizeof(float), &data[0]);
glDrawArrays(GL_TRIANGLES, 0, 6);
if (cit->m_BorderColor != CColor())
{
shader->Uniform(str_color, cit->m_BorderColor);
data.clear();
//.........这里部分代码省略.........