summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/app.cpp8
-rw-r--r--src/common/image.cpp8
-rw-r--r--src/graphics/core/device.h12
-rw-r--r--src/graphics/engine/engine.cpp43
-rw-r--r--src/graphics/engine/text.cpp32
-rw-r--r--src/graphics/engine/text.h16
-rw-r--r--src/graphics/opengl/gldevice.cpp42
-rw-r--r--src/graphics/opengl/gldevice.h10
-rw-r--r--src/math/intpoint.h10
-rw-r--r--src/ui/maindialog.cpp5
10 files changed, 111 insertions, 75 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 79ccdbf..81d874d 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -873,6 +873,14 @@ Event CApplication::ProcessSystemEvent()
{
event.type = EVENT_QUIT;
}
+ /*else if (m_private->currentEvent.type == SDL_VIDEORESIZE)
+ {
+ Gfx::GLDeviceConfig newConfig = m_deviceConfig;
+ newConfig.size.x = m_private->currentEvent.resize.w;
+ newConfig.size.y = m_private->currentEvent.resize.h;
+ if (newConfig.size != m_deviceConfig.size)
+ ChangeVideoConfig(newConfig);
+ }*/
else if ( (m_private->currentEvent.type == SDL_KEYDOWN) ||
(m_private->currentEvent.type == SDL_KEYUP) )
{
diff --git a/src/common/image.cpp b/src/common/image.cpp
index f78ea94..adb8ce7 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -200,8 +200,8 @@ Math::IntPoint CImage::GetSize() const
Gfx::IntColor CImage::GetPixelInt(Math::IntPoint pixel)
{
assert(m_data != nullptr);
- assert(pixel.x >= 0 || pixel.x <= m_data->surface->w);
- assert(pixel.y >= 0 || pixel.y <= m_data->surface->h);
+ assert(pixel.x >= 0 && pixel.x < m_data->surface->w);
+ assert(pixel.y >= 0 && pixel.y < m_data->surface->h);
int bpp = m_data->surface->format->BytesPerPixel;
int index = pixel.y * m_data->surface->pitch + pixel.x * bpp;
@@ -260,8 +260,8 @@ Gfx::Color CImage::GetPixel(Math::IntPoint pixel)
void CImage::SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color)
{
assert(m_data != nullptr);
- assert(pixel.x >= 0 || pixel.x <= m_data->surface->w);
- assert(pixel.y >= 0 || pixel.y <= m_data->surface->h);
+ assert(pixel.x >= 0 && pixel.x < m_data->surface->w);
+ assert(pixel.y >= 0 && pixel.y < m_data->surface->h);
int bpp = m_data->surface->format->BytesPerPixel;
int index = pixel.y * m_data->surface->pitch + pixel.x * bpp;
diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h
index 0777396..ba5af6e 100644
--- a/src/graphics/core/device.h
+++ b/src/graphics/core/device.h
@@ -72,7 +72,7 @@ struct DeviceConfig
size = Math::IntPoint(800, 600);
bpp = 32;
fullScreen = false;
- resizeable = false;
+ resizeable = true;
doubleBuf = true;
noFrame = false;
}
@@ -308,11 +308,13 @@ public:
virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) = 0;
//! Renders primitive composed of vertices with single texture
- virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount) = 0;
- //! Renders primitive composed of vertices with color information and single texture
- virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0;
+ virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
+ Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
//! Renders primitive composed of vertices with multitexturing (2 textures)
- virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount) = 0;
+ virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
+ Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
+ //! Renders primitive composed of vertices with color information
+ virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0;
//! Tests whether a sphere intersects the 6 clipping planes of projection volume
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius) = 0;
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 7e00134..f3eb1dc 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -333,6 +333,8 @@ void CEngine::Destroy()
void CEngine::ResetAfterDeviceChanged()
{
+ m_text->FlushCache();
+
// TODO reload textures, reset device state, etc.
}
@@ -2254,13 +2256,14 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
int dx = img.GetSize().x;
- int dy = img.GetSize().x;
+ int dy = img.GetSize().y;
+
+ int sx = static_cast<int>(Math::Max(ts.x*dx, 0));
+ int sy = static_cast<int>(Math::Max(ts.y*dy, 0));
- int sx = static_cast<int>(ts.x*dx);
- int sy = static_cast<int>(ts.y*dy);
+ int ex = static_cast<int>(Math::Min(ti.x*dx, dx));
+ int ey = static_cast<int>(Math::Min(ti.y*dy, dy));
- int ex = static_cast<int>(ti.x*dx);
- int ey = static_cast<int>(ti.y*dy);
ColorHSV cr1 = RGB2HSV(colorRef1);
ColorHSV cn1 = RGB2HSV(colorNew1);
@@ -2286,9 +2289,9 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
if (c.h < 0.0f) c.h -= 1.0f;
if (c.h > 1.0f) c.h += 1.0f;
color = HSV2RGB(c);
- color.r += shift;
- color.g += shift;
- color.b += shift;
+ color.r = Math::Norm(color.r + shift);
+ color.g = Math::Norm(color.g + shift);
+ color.b = Math::Norm(color.b + shift);
img.SetPixel(Math::IntPoint(x, y), color);
}
else if (tolerance2 != -1.0f &&
@@ -2300,9 +2303,9 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
if (c.h < 0.0f) c.h -= 1.0f;
if (c.h > 1.0f) c.h += 1.0f;
color = HSV2RGB(c);
- color.r += shift;
- color.g += shift;
- color.b += shift;
+ color.r = Math::Norm(color.r + shift);
+ color.g = Math::Norm(color.g + shift);
+ color.b = Math::Norm(color.b + shift);
img.SetPixel(Math::IntPoint(x, y), color);
}
}
@@ -2312,9 +2315,9 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
fabs(color.g - colorRef1.g) +
fabs(color.b - colorRef1.b) < tolerance1 * 3.0f)
{
- color.r = colorNew1.r + color.r - colorRef1.r + shift;
- color.g = colorNew1.g + color.g - colorRef1.g + shift;
- color.b = colorNew1.b + color.b - colorRef1.b + shift;
+ color.r = Math::Norm(colorNew1.r + color.r - colorRef1.r + shift);
+ color.g = Math::Norm(colorNew1.g + color.g - colorRef1.g + shift);
+ color.b = Math::Norm(colorNew1.b + color.b - colorRef1.b + shift);
img.SetPixel(Math::IntPoint(x, y), color);
}
else if (tolerance2 != -1 &&
@@ -2322,9 +2325,9 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
fabs(color.g - colorRef2.g) +
fabs(color.b - colorRef2.b) < tolerance2 * 3.0f)
{
- color.r = colorNew2.r + color.r - colorRef2.r + shift;
- color.g = colorNew2.g + color.g - colorRef2.g + shift;
- color.b = colorNew2.b + color.b - colorRef2.b + shift;
+ color.r = Math::Norm(colorNew2.r + color.r - colorRef2.r + shift);
+ color.g = Math::Norm(colorNew2.g + color.g - colorRef2.g + shift);
+ color.b = Math::Norm(colorNew2.b + color.b - colorRef2.b + shift);
img.SetPixel(Math::IntPoint(x, y), color);
}
}
@@ -3891,7 +3894,7 @@ void CEngine::DrawStats()
std::string triangleText = str.str();
float height = m_text->GetAscent(FONT_COLOBOT, 12.0f);
- float width = 0.15f;
+ float width = 0.2f;
Math::Point pos(0.04f, 0.04f + height);
@@ -3911,11 +3914,11 @@ void CEngine::DrawStats()
SetState(ENG_RSTATE_TEXT);
- m_text->DrawText(triangleText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0);
+ m_text->DrawText(triangleText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
pos.y -= height;
- m_text->DrawText(m_fpsText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0);
+ m_text->DrawText(m_fpsText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
}
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 9091905..6355aed 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -151,7 +151,7 @@ void CText::FlushCache()
void CText::DrawText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, Math::Point pos, float width, TextAlign align,
- int eol)
+ int eol, Color color)
{
float sw = 0.0f;
@@ -168,12 +168,12 @@ void CText::DrawText(const std::string &text, std::map<unsigned int, FontMetaCha
pos.x -= sw;
}
- DrawString(text, format, size, pos, width, eol);
+ DrawString(text, format, size, pos, width, eol, color);
}
void CText::DrawText(const std::string &text, FontType font,
float size, Math::Point pos, float width, TextAlign align,
- int eol)
+ int eol, Color color)
{
float sw = 0.0f;
@@ -190,7 +190,7 @@ void CText::DrawText(const std::string &text, FontType font,
pos.x -= sw;
}
- DrawString(text, font, size, pos, width, eol);
+ DrawString(text, font, size, pos, width, eol, color);
}
void CText::SizeText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
@@ -500,7 +500,7 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs
}
void CText::DrawString(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
- float size, Math::Point pos, float width, int eol)
+ float size, Math::Point pos, float width, int eol, Color color)
{
m_engine->SetState(ENG_RSTATE_TEXT);
@@ -538,7 +538,7 @@ void CText::DrawString(const std::string &text, std::map<unsigned int, FontMetaC
DrawHighlight(hl, pos, charSize);
}
- DrawCharAndAdjustPos(ch, font, size, pos);
+ DrawCharAndAdjustPos(ch, font, size, pos, color);
fmtIndex++;
}
@@ -569,7 +569,7 @@ void CText::StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &
}
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, Color color)
{
assert(font != FONT_BUTTON);
@@ -579,7 +579,7 @@ void CText::DrawString(const std::string &text, FontType font,
StringToUTFCharList(text, chars);
for (auto it = chars.begin(); it != chars.end(); ++it)
{
- DrawCharAndAdjustPos(*it, font, size, pos);
+ DrawCharAndAdjustPos(*it, font, size, pos, color);
}
}
@@ -663,7 +663,7 @@ void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size)
m_device->SetTextureEnabled(0, true);
}
-void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos)
+void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos, Color color)
{
// TODO: if (font == FONT_BUTTON)
if (font == FONT_BUTTON) return;
@@ -674,14 +674,14 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P
if (cf == nullptr)
return;
-
+
int width = 1;
if (ch.c1 < 32) { // FIXME add support for chars with code 9 10 23
- ch.c1 = ' ';
- ch.c2 = 0;
- ch.c3 = 0;
- if (ch.c1 == '\t')
- width = 4;
+ ch.c1 = ' ';
+ ch.c2 = 0;
+ ch.c3 = 0;
+ if (ch.c1 == '\t')
+ width = 4;
}
auto it = cf->cache.find(ch);
@@ -714,7 +714,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P
};
m_device->SetTexture(0, tex.id);
- m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4);
+ m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4, color);
m_engine->AddStatisticTriangle(2);
pos.x += tex.charSize.x * width;
diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h
index 7fa8768..4575c37 100644
--- a/src/graphics/engine/text.h
+++ b/src/graphics/engine/text.h
@@ -23,6 +23,8 @@
#pragma once
+#include "graphics/core/color.h"
+
#include "math/point.h"
#include <vector>
@@ -39,9 +41,9 @@ class CEngine;
class CDevice;
//! Standard small font size
-const float FONT_SIZE_SMALL = 10.0f;
+const float FONT_SIZE_SMALL = 12.0f;
//! Standard big font size
-const float FONT_SIZE_BIG = 15.0f;
+const float FONT_SIZE_BIG = 18.0f;
/**
* \enum TextAlign
@@ -244,11 +246,11 @@ public:
//! Draws text (multi-format)
void DrawText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, Math::Point pos, float width, TextAlign align,
- int eol);
+ int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f));
//! Draws text (one font)
void DrawText(const std::string &text, FontType font,
float size, Math::Point pos, float width, TextAlign align,
- int eol);
+ int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f));
//! Calculates dimensions for text (multi-format)
void SizeText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
@@ -291,11 +293,11 @@ protected:
CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font);
void DrawString(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
- float size, Math::Point pos, float width, int eol);
+ float size, Math::Point pos, float width, int eol, Color color);
void 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, Color color);
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, Color color);
void StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars);
protected:
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index 78a77bd..dbf91c7 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -853,7 +853,8 @@ GLenum TranslateGfxPrimitive(PrimitiveType type)
return flag;
}
-void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount)
+void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount,
+ Color color)
{
Vertex* vs = const_cast<Vertex*>(vertices);
@@ -867,7 +868,7 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int ve
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), reinterpret_cast<GLfloat*>(&vs[0].texCoord));
- glColor3f(1.0f, 1.0f, 1.0f);
+ glColor4fv(color.Array());
glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount);
@@ -876,23 +877,8 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int ve
glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE0
}
-void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount)
-{
- VertexCol* vs = const_cast<VertexCol*>(vertices);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, sizeof(VertexCol), reinterpret_cast<GLfloat*>(&vs[0].coord));
-
- glEnableClientState(GL_COLOR_ARRAY);
- glColorPointer(4, GL_FLOAT, sizeof(VertexCol), reinterpret_cast<GLfloat*>(&vs[0].color));
-
- glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
-}
-
-void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount)
+void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
+ Color color)
{
VertexTex2* vs = const_cast<VertexTex2*>(vertices);
@@ -910,7 +896,7 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].texCoord2));
- glColor3f(1.0f, 1.0f, 1.0f);
+ glColor4fv(color.Array());
glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount);
@@ -921,6 +907,22 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
+void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount)
+{
+ VertexCol* vs = const_cast<VertexCol*>(vertices);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3, GL_FLOAT, sizeof(VertexCol), reinterpret_cast<GLfloat*>(&vs[0].coord));
+
+ glEnableClientState(GL_COLOR_ARRAY);
+ glColorPointer(4, GL_FLOAT, sizeof(VertexCol), reinterpret_cast<GLfloat*>(&vs[0].color));
+
+ glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+}
+
bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius)
{
float distance = (originPlane + Math::DotProduct(normal, center)) / normal.Length();
diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h
index 8af864e..cda7b02 100644
--- a/src/graphics/opengl/gldevice.h
+++ b/src/graphics/opengl/gldevice.h
@@ -119,9 +119,13 @@ public:
virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT);
- virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount);
- virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount);
- virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount);
+ //! Renders primitive composed of vertices with single texture
+ virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
+ Color color = Color(1.0f, 1.0f, 1.0f, 1.0f));
+ //! Renders primitive composed of vertices with multitexturing (2 textures)
+ virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
+ Color color = Color(1.0f, 1.0f, 1.0f, 1.0f));
+ virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount);
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius);
diff --git a/src/math/intpoint.h b/src/math/intpoint.h
index 0f59af6..ebd9c5e 100644
--- a/src/math/intpoint.h
+++ b/src/math/intpoint.h
@@ -39,6 +39,16 @@ struct IntPoint
int y;
IntPoint(int aX = 0, int aY = 0) : x(aX), y(aY) {}
+
+ inline bool operator==(const IntPoint& p) const
+ {
+ return x == p.x && y == p.y;
+ }
+
+ inline bool operator!=(const IntPoint& p) const
+ {
+ return !operator==(p);
+ }
};
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index f07fc38..d7295eb 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -1164,6 +1164,10 @@ pb->SetState(STATE_SHADOW);
if ( m_phase == PHASE_SETUPd || // setup/display ?
m_phase == PHASE_SETUPds )
{
+
+// TODO: device settings
+#if 0
+
pos.x = ox+sx*3;
pos.y = oy+sy*9;
ddim.x = dim.x*6;
@@ -1205,6 +1209,7 @@ pb->SetState(STATE_SHADOW);
pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_FULL);
pc->SetState(STATE_SHADOW);
pc->SetState(STATE_CHECK, m_setupFull);
+#endif
ddim.x = dim.x*6;
ddim.y = dim.y*1;