Fog color fix; refactoring
- fixed fog color setting - removed unused glSecondaryColor and altered struct VertexCol - minor refactoring in CTextdev-ui
parent
b06544871a
commit
45fd8aad33
src
graphics
|
@ -69,36 +69,28 @@ struct Vertex
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \struct VertexCol
|
* \struct VertexCol
|
||||||
* \brief Vertex with color information
|
* \brief Colored vertex
|
||||||
*
|
|
||||||
* This structure was created as analog to DirectX's D3DLVERTEX.
|
|
||||||
*
|
*
|
||||||
* It contains:
|
* It contains:
|
||||||
* - vertex coordinates (x,y,z) as Math::Vector,
|
* - vertex coordinates (x,y,z) as Math::Vector,
|
||||||
* - RGBA color as Color,
|
* - RGBA color as Color
|
||||||
* - RGBA specular color as Color,
|
|
||||||
* - texture coordinates (u,v) as Math::Point.
|
|
||||||
*/
|
*/
|
||||||
struct VertexCol
|
struct VertexCol
|
||||||
{
|
{
|
||||||
Math::Vector coord;
|
Math::Vector coord;
|
||||||
Color color;
|
Color color;
|
||||||
Color specular;
|
|
||||||
Math::Point texCoord;
|
|
||||||
|
|
||||||
explicit VertexCol(Math::Vector aCoord = Math::Vector(),
|
explicit VertexCol(Math::Vector aCoord = Math::Vector(),
|
||||||
Color aColor = Color(),
|
Color aColor = Color(),
|
||||||
Color aSpecular = Color(),
|
|
||||||
Math::Point aTexCoord = Math::Point())
|
Math::Point aTexCoord = Math::Point())
|
||||||
: coord(aCoord), color(aColor), specular(aSpecular), texCoord(aTexCoord) {}
|
: coord(aCoord), color(aColor) {}
|
||||||
|
|
||||||
//! Returns a string "(c: [...], col: [...], sp: [...], tc: [...])"
|
//! Returns a string "(c: [...], col: [...])"
|
||||||
inline std::string ToString() const
|
inline std::string ToString() const
|
||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s.precision(3);
|
s.precision(3);
|
||||||
s << "(c: " << coord.ToString() << ", col: " << color.ToString() << ", sp: "
|
s << "(c: " << coord.ToString() << ", col: " << color.ToString() << ")";
|
||||||
<< specular.ToString() << ", tc: " << texCoord.ToString() << ")";
|
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3417,10 +3417,10 @@ void CEngine::DrawBackgroundGradient(const Color& up, const Color& down)
|
||||||
|
|
||||||
VertexCol vertex[4] =
|
VertexCol vertex[4] =
|
||||||
{
|
{
|
||||||
VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color[1], color[2]),
|
VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color[1]),
|
||||||
VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color[0], color[2]),
|
VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color[0]),
|
||||||
VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color[1], color[2]),
|
VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color[1]),
|
||||||
VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color[0], color[2])
|
VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color[0])
|
||||||
};
|
};
|
||||||
|
|
||||||
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
|
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
|
||||||
|
@ -3567,10 +3567,10 @@ void CEngine::DrawOverColor()
|
||||||
|
|
||||||
VertexCol vertex[4] =
|
VertexCol vertex[4] =
|
||||||
{
|
{
|
||||||
VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color[1], color[2]),
|
VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color[1]),
|
||||||
VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color[0], color[2]),
|
VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color[0]),
|
||||||
VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color[1], color[2]),
|
VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color[1]),
|
||||||
VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color[0], color[2])
|
VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color[0])
|
||||||
};
|
};
|
||||||
|
|
||||||
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
|
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
|
||||||
|
|
|
@ -150,8 +150,8 @@ void CText::FlushCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &format,
|
void CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &format,
|
||||||
float size, Math::Point pos, float width, TextAlign align,
|
float size, Math::Point pos, float width, TextAlign align,
|
||||||
int eol)
|
int eol)
|
||||||
{
|
{
|
||||||
float sw = 0.0f;
|
float sw = 0.0f;
|
||||||
|
|
||||||
|
@ -172,8 +172,8 @@ void CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &f
|
||||||
}
|
}
|
||||||
|
|
||||||
void CText::DrawText(const std::string &text, FontType font,
|
void CText::DrawText(const std::string &text, FontType font,
|
||||||
float size, Math::Point pos, float width, TextAlign align,
|
float size, Math::Point pos, float width, TextAlign align,
|
||||||
int eol)
|
int eol)
|
||||||
{
|
{
|
||||||
float sw = 0.0f;
|
float sw = 0.0f;
|
||||||
|
|
||||||
|
@ -194,8 +194,8 @@ void CText::DrawText(const std::string &text, FontType font,
|
||||||
}
|
}
|
||||||
|
|
||||||
void CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &format,
|
void CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &format,
|
||||||
float size, Math::Point pos, TextAlign align,
|
float size, Math::Point pos, TextAlign align,
|
||||||
Math::Point &start, Math::Point &end)
|
Math::Point &start, Math::Point &end)
|
||||||
{
|
{
|
||||||
start = end = pos;
|
start = end = pos;
|
||||||
|
|
||||||
|
@ -217,8 +217,8 @@ void CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &f
|
||||||
}
|
}
|
||||||
|
|
||||||
void CText::SizeText(const std::string &text, FontType font,
|
void CText::SizeText(const std::string &text, FontType font,
|
||||||
float size, Math::Point pos, TextAlign align,
|
float size, Math::Point pos, TextAlign align,
|
||||||
Math::Point &start, Math::Point &end)
|
Math::Point &start, Math::Point &end)
|
||||||
{
|
{
|
||||||
start = end = pos;
|
start = end = pos;
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ float CText::GetHeight(FontType font, float size)
|
||||||
|
|
||||||
|
|
||||||
float CText::GetStringWidth(const std::string &text,
|
float CText::GetStringWidth(const std::string &text,
|
||||||
const std::vector<FontMetaChar> &format, float size)
|
const std::vector<FontMetaChar> &format, float size)
|
||||||
{
|
{
|
||||||
assert(StrUtils::Utf8StringLength(text) == format.size());
|
assert(StrUtils::Utf8StringLength(text) == format.size());
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset)
|
||||||
|
|
||||||
|
|
||||||
int CText::Justify(const std::string &text, const std::vector<FontMetaChar> &format,
|
int CText::Justify(const std::string &text, const std::vector<FontMetaChar> &format,
|
||||||
float size, float width)
|
float size, float width)
|
||||||
{
|
{
|
||||||
assert(StrUtils::Utf8StringLength(text) == format.size());
|
assert(StrUtils::Utf8StringLength(text) == format.size());
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ int CText::Justify(const std::string &text, FontType font, float size, float wid
|
||||||
}
|
}
|
||||||
|
|
||||||
int CText::Detect(const std::string &text, const std::vector<FontMetaChar> &format,
|
int CText::Detect(const std::string &text, const std::vector<FontMetaChar> &format,
|
||||||
float size, float offset)
|
float size, float offset)
|
||||||
{
|
{
|
||||||
assert(StrUtils::Utf8StringLength(text) == format.size());
|
assert(StrUtils::Utf8StringLength(text) == format.size());
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs
|
||||||
}
|
}
|
||||||
|
|
||||||
void CText::DrawString(const std::string &text, const std::vector<FontMetaChar> &format,
|
void CText::DrawString(const std::string &text, const std::vector<FontMetaChar> &format,
|
||||||
float size, Math::Point pos, float width, int eol)
|
float size, Math::Point pos, float width, int eol)
|
||||||
{
|
{
|
||||||
assert(StrUtils::Utf8StringLength(text) == format.size());
|
assert(StrUtils::Utf8StringLength(text) == format.size());
|
||||||
|
|
||||||
|
@ -511,9 +511,10 @@ void CText::DrawString(const std::string &text, const std::vector<FontMetaChar>
|
||||||
|
|
||||||
unsigned int fmtIndex = 0;
|
unsigned int fmtIndex = 0;
|
||||||
|
|
||||||
std::vector<UTF8Char> chars = StringToUTFCharList(text);
|
std::vector<UTF8Char> chars;
|
||||||
for(auto it=chars.begin(); it != chars.end(); ++it){
|
StringToUTFCharList(text, chars);
|
||||||
|
for (auto it = chars.begin(); it != chars.end(); ++it)
|
||||||
|
{
|
||||||
font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
|
font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
|
||||||
|
|
||||||
// TODO: if (font == FONT_BUTTON)
|
// TODO: if (font == FONT_BUTTON)
|
||||||
|
@ -546,37 +547,38 @@ void CText::DrawString(const std::string &text, const std::vector<FontMetaChar>
|
||||||
// TODO: eol
|
// TODO: eol
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<UTF8Char> CText::StringToUTFCharList(const std::string &text) {
|
void CText::StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars)
|
||||||
std::vector<UTF8Char> v;
|
{
|
||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
while (index < text.length())
|
while (index < text.length())
|
||||||
{
|
{
|
||||||
UTF8Char ch;
|
UTF8Char ch;
|
||||||
|
|
||||||
int len = StrUtils::Utf8CharSizeAt(text, index);
|
int len = StrUtils::Utf8CharSizeAt(text, index);
|
||||||
if (len >= 1)
|
if (len >= 1)
|
||||||
ch.c1 = text[index];
|
ch.c1 = text[index];
|
||||||
if (len >= 2)
|
if (len >= 2)
|
||||||
ch.c2 = text[index+1];
|
ch.c2 = text[index+1];
|
||||||
if (len >= 3)
|
if (len >= 3)
|
||||||
ch.c3 = text[index+2];
|
ch.c3 = text[index+2];
|
||||||
|
|
||||||
index += len;
|
index += len;
|
||||||
|
|
||||||
v.push_back(ch);
|
chars.push_back(ch);
|
||||||
}
|
}
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CText::DrawString(const std::string &text, FontType font,
|
void CText::DrawString(const std::string &text, FontType font,
|
||||||
float size, Math::Point pos, float width, int eol)
|
float size, Math::Point pos, float width, int eol)
|
||||||
{
|
{
|
||||||
assert(font != FONT_BUTTON);
|
assert(font != FONT_BUTTON);
|
||||||
|
|
||||||
m_engine->SetState(ENG_RSTATE_TEXT);
|
m_engine->SetState(ENG_RSTATE_TEXT);
|
||||||
|
|
||||||
std::vector<UTF8Char> chars = StringToUTFCharList(text);
|
std::vector<UTF8Char> chars;
|
||||||
for(auto it=chars.begin(); it != chars.end(); ++it){
|
StringToUTFCharList(text, chars);
|
||||||
|
for (auto it = chars.begin(); it != chars.end(); ++it)
|
||||||
|
{
|
||||||
DrawCharAndAdjustPos(*it, font, size, pos);
|
DrawCharAndAdjustPos(*it, font, size, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,11 +293,10 @@ protected:
|
||||||
float size, Math::Point pos, float width, int eol);
|
float size, Math::Point pos, float width, int eol);
|
||||||
void DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size);
|
void DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size);
|
||||||
void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos);
|
void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos);
|
||||||
std::vector<UTF8Char>
|
void StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars);
|
||||||
StringToUTFCharList(const std::string &text);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CInstanceManager* m_iMan;
|
CInstanceManager* m_iMan;
|
||||||
CEngine* m_engine;
|
CEngine* m_engine;
|
||||||
CDevice* m_device;
|
CDevice* m_device;
|
||||||
|
|
||||||
|
@ -307,7 +306,7 @@ protected:
|
||||||
std::map<FontType, MultisizeFont*> m_fonts;
|
std::map<FontType, MultisizeFont*> m_fonts;
|
||||||
|
|
||||||
FontType m_lastFontType;
|
FontType m_lastFontType;
|
||||||
int m_lastFontSize;
|
int m_lastFontSize;
|
||||||
CachedFont* m_lastCachedFont;
|
CachedFont* m_lastCachedFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ bool CGLDevice::Create()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) || (! GLEW_EXT_secondary_color) )
|
if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) )
|
||||||
{
|
{
|
||||||
GetLogger()->Error("GLEW reports required extensions not supported\n");
|
GetLogger()->Error("GLEW reports required extensions not supported\n");
|
||||||
return false;
|
return false;
|
||||||
|
@ -887,8 +887,6 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int
|
||||||
for (int i = 0; i < vertexCount; ++i)
|
for (int i = 0; i < vertexCount; ++i)
|
||||||
{
|
{
|
||||||
glColor4fv(const_cast<GLfloat*>(vertices[i].color.Array()));
|
glColor4fv(const_cast<GLfloat*>(vertices[i].color.Array()));
|
||||||
glSecondaryColor3fv(const_cast<GLfloat*>(vertices[i].specular.Array()));
|
|
||||||
glMultiTexCoord2fv(GL_TEXTURE0, const_cast<GLfloat*>(vertices[i].texCoord.Array()));
|
|
||||||
glVertex3fv(const_cast<GLfloat*>(vertices[i].coord.Array()));
|
glVertex3fv(const_cast<GLfloat*>(vertices[i].coord.Array()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1244,6 +1242,7 @@ void CGLDevice::SetFogParams(FogMode mode, const Color &color, float start, floa
|
||||||
glFogf(GL_FOG_START, start);
|
glFogf(GL_FOG_START, start);
|
||||||
glFogf(GL_FOG_END, end);
|
glFogf(GL_FOG_END, end);
|
||||||
glFogf(GL_FOG_DENSITY, density);
|
glFogf(GL_FOG_DENSITY, density);
|
||||||
|
glFogfv(GL_FOG_COLOR, color.Array());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLDevice::GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density)
|
void CGLDevice::GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density)
|
||||||
|
@ -1258,6 +1257,9 @@ void CGLDevice::GetFogParams(FogMode &mode, Color &color, float &start, float &e
|
||||||
glGetFloatv(GL_FOG_START, static_cast<GLfloat*>(&start));
|
glGetFloatv(GL_FOG_START, static_cast<GLfloat*>(&start));
|
||||||
glGetFloatv(GL_FOG_END, static_cast<GLfloat*>(&end));
|
glGetFloatv(GL_FOG_END, static_cast<GLfloat*>(&end));
|
||||||
glGetFloatv(GL_FOG_DENSITY, static_cast<GLfloat*>(&density));
|
glGetFloatv(GL_FOG_DENSITY, static_cast<GLfloat*>(&density));
|
||||||
|
GLfloat col[4] = { 0.0f };
|
||||||
|
glGetFloatv(GL_FOG_COLOR, col);
|
||||||
|
color = Color(col[0], col[1], col[2], col[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGLDevice::SetCullMode(CullMode mode)
|
void CGLDevice::SetCullMode(CullMode mode)
|
||||||
|
|
|
@ -190,10 +190,10 @@ void CColor::Draw()
|
||||||
m_engine->SetTexture(""); // no texture
|
m_engine->SetTexture(""); // no texture
|
||||||
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
|
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
|
||||||
|
|
||||||
vertex[0] = Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color, Gfx::Color(), Math::Point(0.0f, 0.0f));
|
vertex[0] = Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color);
|
||||||
vertex[1] = Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color, Gfx::Color(), Math::Point(0.0f, 0.0f));
|
vertex[1] = Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color);
|
||||||
vertex[2] = Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color, Gfx::Color(), Math::Point(0.0f, 0.0f));
|
vertex[2] = Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color);
|
||||||
vertex[3] = Gfx::VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color, Gfx::Color(), Math::Point(0.0f, 0.0f));
|
vertex[3] = Gfx::VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color);
|
||||||
|
|
||||||
device = m_engine->GetDevice();
|
device = m_engine->GetDevice();
|
||||||
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
|
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
|
||||||
|
|
Loading…
Reference in New Issue