fix alpha blending issues

This commit is contained in:
Eduardo Bart 2012-06-01 20:21:45 -03:00
parent 6fce78d519
commit ba01909088
9 changed files with 43 additions and 28 deletions

View File

@ -17,7 +17,6 @@ Module
dofile 'settings' dofile 'settings'
dofile 'keyboard' dofile 'keyboard'
dofile 'mouse' dofile 'mouse'
dofile 'string'
dofiles 'ui' dofiles 'ui'
dofiles 'widgets' dofiles 'widgets'

View File

@ -21,3 +21,25 @@ end
function string.trim(s) function string.trim(s)
return string.match(s, '^%s*(.*%S)') or '' return string.match(s, '^%s*(.*%S)') or ''
end end
function string.explode(str, sep, limit)
if(type(sep) ~= 'string' or tostring(str):len() == 0 or sep:len() == 0) then
return {}
end
local i, pos, tmp, t = 0, 1, "", {}
for s, e in function() return string.find(str, sep, pos) end do
tmp = str:sub(pos, s - 1):trim()
table.insert(t, tmp)
pos = e + 1
i = i + 1
if(limit ~= nil and i == limit) then
break
end
end
tmp = str:sub(pos):trim()
table.insert(t, tmp)
return t
end

View File

@ -1,21 +0,0 @@
string.explode = function (str, sep, limit)
if(type(sep) ~= 'string' or tostring(str):len() == 0 or sep:len() == 0) then
return {}
end
local i, pos, tmp, t = 0, 1, "", {}
for s, e in function() return string.find(str, sep, pos) end do
tmp = str:sub(pos, s - 1):trim()
table.insert(t, tmp)
pos = e + 1
i = i + 1
if(limit ~= nil and i == limit) then
break
end
end
tmp = str:sub(pos):trim()
table.insert(t, tmp)
return t
end

View File

@ -157,6 +157,7 @@ void FrameBuffer::internalRelease()
// restore screen original content // restore screen original content
g_painter->setCompositionMode(Painter::CompositionMode_Replace); g_painter->setCompositionMode(Painter::CompositionMode_Replace);
g_painter->drawTexturedRect(screenRect, m_screenBackup, screenRect); g_painter->drawTexturedRect(screenRect, m_screenBackup, screenRect);
g_painter->resetCompositionMode();
} }
} }

View File

@ -330,3 +330,14 @@ bool Graphics::canUseClampToEdge()
return m_useClampToEdge; return m_useClampToEdge;
#endif #endif
} }
bool Graphics::canUseBlendFuncSeparate()
{
#ifdef OPENGL_ES
return true;
#else
if(!GLEW_VERSION_1_4)
return false;
return true;
#endif
}

View File

@ -63,6 +63,7 @@ public:
bool canUseMipmaps(); bool canUseMipmaps();
bool canUseHardwareMipmaps(); bool canUseHardwareMipmaps();
bool canUseClampToEdge(); bool canUseClampToEdge();
bool canUseBlendFuncSeparate();
private: private:
Size m_viewportSize; Size m_viewportSize;

View File

@ -132,7 +132,11 @@ void Painter::updateGlCompositionMode()
{ {
switch(m_compositionMode) { switch(m_compositionMode) {
case CompositionMode_Normal: case CompositionMode_Normal:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if(g_graphics.canUseBlendFuncSeparate())
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
break; break;
case CompositionMode_Multiply: case CompositionMode_Multiply:
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);

View File

@ -304,7 +304,7 @@ void WIN32Window::internalChooseGLVisual()
PFD_TYPE_RGBA, PFD_TYPE_RGBA,
32, // Select Our Color Depth 32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, 0, 0, 0, 0, 0, // Color Bits Ignored
1, // Alpha Buffer Bits 8, // Alpha Buffer Bits
0, // Shift Bit Ignored 0, // Shift Bit Ignored
0, // No Accumulation Buffer 0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored 0, 0, 0, 0, // Accumulation Bits Ignored

View File

@ -77,13 +77,11 @@ void MapView::draw(const Rect& rect)
Rect clearRect = Rect(0, 0, m_drawDimension * m_tileSize); Rect clearRect = Rect(0, 0, m_drawDimension * m_tileSize);
// drawing a black rect is actually faster than FrameBuffer::clear() // drawing a black rect is actually faster than FrameBuffer::clear()
/*
g_painter->setColor(Color::black); g_painter->setColor(Color::black);
g_painter->drawFilledRect(clearRect); g_painter->drawFilledRect(clearRect);
g_painter->setColor(Color::white); g_painter->setColor(Color::white);
*/
m_framebuffer->clear(Color::black); //m_framebuffer->clear(Color::black);
} }
auto it = m_cachedVisibleTiles.begin(); auto it = m_cachedVisibleTiles.begin();
@ -148,8 +146,8 @@ void MapView::draw(const Rect& rect)
#else #else
m_framebuffer->draw(rect, srcRect); m_framebuffer->draw(rect, srcRect);
#endif #endif
g_painter->restoreSavedState(); g_painter->restoreSavedState();
//g_painter->resetShaderProgram(); //g_painter->resetShaderProgram();
// this could happen if the player position is not known yet // this could happen if the player position is not known yet