forked from Mirrors/openclonk
104 lines
2.2 KiB
C++
104 lines
2.2 KiB
C++
|
|
||
|
#include "C4Include.h"
|
||
|
#include "C4FoWDrawStrategy.h"
|
||
|
#include "C4FoWLight.h"
|
||
|
#include "C4FoWRegion.h"
|
||
|
#include "C4DrawGL.h"
|
||
|
|
||
|
const float C4FoWDrawLightTextureStrategy::C4FoWSmooth = 8.0;
|
||
|
|
||
|
void C4FoWDrawLightTextureStrategy::Begin(int32_t passPar)
|
||
|
{
|
||
|
pass = passPar;
|
||
|
|
||
|
glShadeModel( GL_SMOOTH );
|
||
|
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||
|
|
||
|
glBlendFunc(GL_ONE, GL_ONE);
|
||
|
if(pass == 0)
|
||
|
{
|
||
|
glBlendEquation( GL_FUNC_ADD );
|
||
|
}
|
||
|
else if(pass == 1)
|
||
|
{
|
||
|
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawLightTextureStrategy::End(int32_t pass)
|
||
|
{
|
||
|
glBlendEquation( GL_FUNC_ADD );
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawLightTextureStrategy::DrawVertex(float x, float y, bool shadeLight)
|
||
|
{
|
||
|
if(pass == 0)
|
||
|
{
|
||
|
float dx = x - light->getX();
|
||
|
float dy = y - light->getY();
|
||
|
float dist = sqrt(dx*dx+dy*dy);
|
||
|
float mult = Min(0.5f / light->getSize(), 0.5f / dist);
|
||
|
float normX = (0.5f + dx * mult) / 1.5f / C4FoWSmooth;
|
||
|
float normY = (0.5f + dy * mult) / 1.5f / C4FoWSmooth;
|
||
|
if(shadeLight) glColor3f(0.5f/C4FoWSmooth, normX, normY);
|
||
|
else glColor3f(0.0f, normX, normY);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
glColor3f(0.0f, 0.5f/1.5f/C4FoWSmooth, 0.5f/1.5f/C4FoWSmooth);
|
||
|
}
|
||
|
|
||
|
// global coords -> region coords
|
||
|
x += -region->getRegion().x;
|
||
|
y += -region->getRegion().y;
|
||
|
|
||
|
glVertex2f(x,y);
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawLightTextureStrategy::DrawDarkVertex(float x, float y)
|
||
|
{
|
||
|
DrawVertex(x,y, false);
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawLightTextureStrategy::DrawLightVertex(float x, float y)
|
||
|
{
|
||
|
DrawVertex(x,y, true);
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawWireframeStrategy::Begin(int32_t pass)
|
||
|
{
|
||
|
glShadeModel( GL_SMOOTH );
|
||
|
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawWireframeStrategy::End(int32_t pass)
|
||
|
{
|
||
|
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||
|
glBlendEquation( GL_FUNC_ADD );
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawWireframeStrategy::DrawVertex(float x, float y)
|
||
|
{
|
||
|
// global coords -> screen pos and zoom
|
||
|
x += screen->X - screen->TargetX;
|
||
|
y += screen->Y - screen->TargetY;
|
||
|
pGL->ApplyZoom(x,y);
|
||
|
glVertex2f(x,y);
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawWireframeStrategy::DrawDarkVertex(float x, float y)
|
||
|
{
|
||
|
if(!draw) return;
|
||
|
glColor3f(0.5f, 0.5f, 0.0f);
|
||
|
DrawVertex(x, y);
|
||
|
}
|
||
|
|
||
|
void C4FoWDrawWireframeStrategy::DrawLightVertex(float x, float y)
|
||
|
{
|
||
|
if(!draw) return;
|
||
|
glColor3f(1.0f, 0.0f, 0.0f);
|
||
|
DrawVertex(x, y);
|
||
|
}
|
||
|
|