Added Renderers

Added UI Renderer
Added OpenGL 3.3 UI Renderer
Reimplemented most of UI drawing functionality to use UI Renderer
TODO: fix OpenGL errors
dev
Tomasz Kapuściński 2021-06-16 02:33:15 +02:00
parent 704e3f2f0d
commit 465fe59dfb
27 changed files with 828 additions and 265 deletions

View File

@ -98,6 +98,7 @@ add_library(colobotbase STATIC
graphics/core/texture.h
graphics/core/type.cpp
graphics/core/type.h
graphics/core/renderers.h
graphics/core/vertex.h
graphics/engine/camera.cpp
graphics/engine/camera.h
@ -144,6 +145,8 @@ add_library(colobotbase STATIC
graphics/model/model_triangle.h
graphics/opengl/gl33device.cpp
graphics/opengl/gl33device.h
graphics/opengl/gl33renderers.cpp
graphics/opengl/gl33renderers.h
graphics/opengl/glframebuffer.cpp
graphics/opengl/glframebuffer.h
graphics/opengl/glutil.cpp

View File

@ -49,6 +49,7 @@ namespace Gfx
{
class CFramebuffer;
class CUIRenderer;
struct FramebufferParams;
struct Light;
struct Material;
@ -374,6 +375,8 @@ public:
//! Sets current rendering mode
virtual void SetRenderMode(RenderMode mode) = 0;
//! Returns UI renderer
virtual CUIRenderer* GetUIRenderer() = 0;
//! Sets the transform matrix of given type
virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0;
@ -424,6 +427,8 @@ public:
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
//! Renders primitive composed of vertices with solid color
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0;
//! Renders primitive using UI renderer
virtual void DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount) = 0;
//! Renders primitives composed of lists of vertices with single texture
virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices,

View File

@ -0,0 +1,69 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file graphics/core/renderers.h
* \brief Abstract classes representing renderers
*/
#pragma once
#include "graphics/core/vertex.h"
#include <glm/glm.hpp>
// Graphics module namespace
namespace Gfx
{
enum PrimitiveType;
struct Texture;
/**
* \class CRenderer
* \brief Common abstract interface for renderers
*/
class CRenderer
{
public:
virtual ~CRenderer() { }
//! Flush buffered content
virtual void Flush() = 0;
};
/**
* \class CRenderer
* \brief Abstract interface for UI renderers
*/
class CUIRenderer : public CRenderer
{
public:
virtual ~CUIRenderer() { }
//! Sets ortographic projection with given parameters
virtual void SetProjection(float left, float right, float bottom, float top) = 0;
//! Sets texture, setting texture 0 means using white texture
virtual void SetTexture(const Texture& texture) = 0;
//! Draws primitive
virtual void DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) = 0;
};
} // namespace Gfx

View File

@ -36,6 +36,7 @@
#include "graphics/core/device.h"
#include "graphics/core/framebuffer.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h"
@ -356,6 +357,10 @@ bool CEngine::Create()
m_matWorldInterface.LoadIdentity();
m_matViewInterface.LoadIdentity();
auto renderer = m_device->GetUIRenderer();
renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
Math::LoadOrthoProjectionMatrix(m_matProjInterface, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
TextureCreateParams params;
@ -1971,6 +1976,8 @@ void CEngine::SetState(int state, const Color& color)
if (state == m_lastState && color == m_lastColor)
return;
m_device->GetUIRenderer()->Flush();
m_lastState = state;
m_lastColor = color;
@ -3631,20 +3638,21 @@ void CEngine::DrawCaptured3DScene()
m_device->SetRenderState(RENDER_STATE_BLENDING, false);
m_device->SetRenderState(RENDER_STATE_CULLING, false);
Vertex vertices[4];
Vertex2D vertices[4];
vertices[0] = Vertex(Math::Vector(-1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 0.0f));
vertices[1] = Vertex(Math::Vector(1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 0.0f));
vertices[2] = Vertex(Math::Vector(-1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 1.0f));
vertices[3] = Vertex(Math::Vector(1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 1.0f));
vertices[0] = { { 0.0f, 0.0f }, { 0.0f, 0.0f } };
vertices[1] = { { 1.0f, 0.0f }, { 1.0f, 0.0f } };
vertices[2] = { { 0.0f, 1.0f }, { 0.0f, 1.0f } };
vertices[3] = { { 1.0f, 1.0f }, { 1.0f, 1.0f } };
m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
m_device->SetTexture(TEXTURE_PRIMARY, m_capturedWorldTexture);
m_device->SetTextureEnabled(TEXTURE_PRIMARY, true);
m_device->SetTextureEnabled(TEXTURE_SECONDARY, false);
auto renderer = m_device->GetUIRenderer();
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4);
renderer->SetTexture(m_capturedWorldTexture);
renderer->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, 4, vertices);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
}
void CEngine::RenderDebugSphere(const Math::Sphere& sphere, const Math::Matrix& transform, const Gfx::Color& color)
@ -4859,23 +4867,20 @@ void CEngine::DrawBackgroundImage()
v2 -= margin_v;
}
SetTexture(m_backgroundTex);
SetState(ENG_RSTATE_OPAQUE_TEXTURE | ENG_RSTATE_WRAP);
SetUITexture(m_backgroundTex);
m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface);
m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface);
m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface);
Vertex vertex[4] =
Vertex2D vertices[4] =
{
Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)),
Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)),
Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)),
Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1))
{ { p1.x, p1.y }, { u1, v2 } },
{ { p1.x, p2.y }, { u1, v1 } },
{ { p2.x, p1.y }, { u2, v2 } },
{ { p2.x, p2.y }, { u2, v1 } }
};
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4);
AddStatisticTriangle(2);
m_device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
void CEngine::DrawPlanet()
@ -5079,6 +5084,8 @@ void CEngine::DrawMouse()
m_device->SetMaterial(material);
m_device->SetTexture(0, m_miceTexture);
SetUITexture(m_miceTexture);
Math::Point mousePos = CInput::GetInstancePointer()->GetMousePos();
Math::IntPoint pos(mousePos.x * m_size.x, m_size.y - mousePos.y * m_size.y);
pos.x -= MOUSE_TYPES.at(m_mouseType).hotPoint.x;
@ -5119,18 +5126,18 @@ void CEngine::DrawMouseSprite(Math::IntPoint pos, Math::IntPoint size, int icon)
u2 -= dp;
v2 -= dp;
Math::Vector normal(0.0f, 0.0f, -1.0f);
Vertex vertex[4] =
Vertex2D vertex[4] =
{
Vertex(Math::Vector(p1.x, p2.y, 0.0f), normal, Math::Point(u1, v2)),
Vertex(Math::Vector(p1.x, p1.y, 0.0f), normal, Math::Point(u1, v1)),
Vertex(Math::Vector(p2.x, p2.y, 0.0f), normal, Math::Point(u2, v2)),
Vertex(Math::Vector(p2.x, p1.y, 0.0f), normal, Math::Point(u2, v1))
{ { p1.x, p2.y }, { u1, v2 } },
{ { p1.x, p1.y }, { u1, v1 } },
{ { p2.x, p2.y }, { u2, v2 } },
{ { p2.x, p1.y }, { u2, v1 } }
};
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
AddStatisticTriangle(2);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
}
void CEngine::DrawStats()
@ -5145,17 +5152,18 @@ void CEngine::DrawStats()
Math::Point pos(0.05f * m_size.x/m_size.y, 0.05f + TOTAL_LINES * height);
SetState(ENG_RSTATE_TCOLOR_ALPHA);
SetUITexture(Texture{});
Gfx::Color black(0.0f, 0.0f, 0.0f, 0.75f);
glm::u8vec4 black = { 0, 0, 0, 192 };
Math::Point margin = Math::Point(5.f / m_size.x, 5.f / m_size.y);
VertexCol vertex[4] =
Vertex2D vertex[4] =
{
VertexCol(Math::Vector(pos.x - margin.x, pos.y - (TOTAL_LINES + 1) * height - margin.y, 0.0f), black),
VertexCol(Math::Vector(pos.x - margin.x, pos.y + height + margin.y, 0.0f), black),
VertexCol(Math::Vector(pos.x + width + margin.x, pos.y - (TOTAL_LINES + 1) * height - margin.y, 0.0f), black),
VertexCol(Math::Vector(pos.x + width + margin.x, pos.y + height + margin.y, 0.0f), black)
{ { pos.x - margin.x, pos.y - (TOTAL_LINES + 1) * height - margin.y }, {}, black },
{ { pos.x - margin.x, pos.y + height + margin.y }, {}, black },
{ { pos.x + width + margin.x, pos.y - (TOTAL_LINES + 1) * height - margin.y }, {}, black },
{ { pos.x + width + margin.x, pos.y + height + margin.y }, {}, black }
};
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
@ -5233,6 +5241,8 @@ void CEngine::DrawStats()
std::stringstream str;
str << std::fixed << std::setprecision(2) << m_statisticPos.x << "; " << m_statisticPos.z;
drawStatsLine( "Position", str.str(), "");
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
}
void CEngine::DrawTimer()
@ -5241,6 +5251,8 @@ void CEngine::DrawTimer()
Math::Point pos(0.98f, 0.98f-m_text->GetAscent(FONT_COMMON, 15.0f));
m_text->DrawText(m_timerText, FONT_COMMON, 15.0f, pos, 1.0f, TEXT_ALIGN_RIGHT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
}
void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector<Gfx::ModelTriangle>& triangles)
@ -5525,6 +5537,11 @@ void CEngine::SetInterfaceCoordinates()
m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface);
m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface);
m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface);
auto renderer = m_device->GetUIRenderer();
renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
}
void CEngine::EnablePauseBlur()
@ -5555,6 +5572,25 @@ void CEngine::SetWindowCoordinates()
m_device->SetTransform(TRANSFORM_VIEW, matViewWindow);
m_device->SetTransform(TRANSFORM_PROJECTION, matProjWindow);
m_device->SetTransform(TRANSFORM_WORLD, matWorldWindow);
auto renderer = m_device->GetUIRenderer();
renderer->SetProjection(0.0f, m_size.x, m_size.y, 0.0f);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
}
void CEngine::SetUITexture(const std::string& name)
{
auto texture = LoadTexture(name);
SetUITexture(texture);
}
void CEngine::SetUITexture(const Texture& texture)
{
auto renderer = m_device->GetUIRenderer();
renderer->SetTexture(texture);
}
} // namespace Gfx

View File

@ -1189,6 +1189,10 @@ public:
void EnablePauseBlur();
void DisablePauseBlur();
void SetUITexture(const std::string& name);
void SetUITexture(const Texture& texture);
//! Reloads all textures
/** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/
void ReloadAllTextures();

View File

@ -29,6 +29,8 @@
#include "common/resources/resourcemanager.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h"
#include "math/func.h"
@ -113,7 +115,7 @@ public:
/// Add a quad to be rendered.
/// This may trigger a call to Flush() if necessary.
void Add(Vertex vertices[4], unsigned int texID, EngineRenderState renderState, Color color)
void Add(Vertex2D vertices[4], unsigned int texID, EngineRenderState renderState, Color color)
{
if (texID != m_texID || renderState != m_renderState || color != m_color)
{
@ -132,6 +134,7 @@ public:
m_engine.SetState(m_renderState);
m_engine.GetDevice()->SetTexture(0, m_texID);
m_engine.SetUITexture(Texture{ m_texID });
assert(m_firsts.size() == m_counts.size());
if (m_firsts.size() < m_quads.size())
@ -148,16 +151,24 @@ public:
}
}
const Vertex* vertices = m_quads.front().vertices;
m_engine.GetDevice()->DrawPrimitives(PRIMITIVE_TRIANGLE_STRIP, vertices, m_firsts.data(),
m_counts.data(), static_cast<int>(m_quads.size()), m_color);
for (const auto& quad : m_quads)
{
m_engine.GetDevice()->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad.vertices, 4);
}
m_engine.GetDevice()->GetUIRenderer()->Flush();
m_engine.GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
//const Vertex* vertices = m_quads.front().vertices;
//m_engine.GetDevice()->DrawPrimitives(PRIMITIVE_TRIANGLE_STRIP, vertices, m_firsts.data(),
// m_counts.data(), static_cast<int>(m_quads.size()), m_color);
m_engine.AddStatisticTriangle(static_cast<int>(m_quads.size() * 2));
m_quads.clear();
}
private:
CEngine& m_engine;
struct Quad { Vertex vertices[4]; };
struct Quad { Vertex2D vertices[4]; };
std::vector<Quad> m_quads;
std::vector<int> m_firsts;
std::vector<int> m_counts;
@ -1026,8 +1037,6 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::I
Math::IntPoint p1(pos.x, pos.y - height);
Math::IntPoint p2(pos.x + width, pos.y);
Math::Vector n(0.0f, 0.0f, -1.0f); // normal
// For whatever reason ch.c1 is a SIGNED char, we need to fix that
unsigned char icon = static_cast<unsigned char>(ch.c1);
@ -1047,12 +1056,14 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::I
uv2.x -= dp;
uv2.y -= dp;
Vertex quad[4] =
glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 };
Vertex2D quad[4] =
{
Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv2.y)),
Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv1.y)),
Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv2.y)),
Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv1.y))
{ { p1.x, p2.y }, { uv1.x, uv2.y }, col },
{ { p1.x, p1.y }, { uv1.x, uv1.y }, col },
{ { p2.x, p2.y }, { uv2.x, uv2.y }, col },
{ { p2.x, p1.y }, { uv2.x, uv1.y }, col }
};
m_quadBatch->Add(quad, texID, ENG_RSTATE_TTEXTURE_WHITE, color);
@ -1083,14 +1094,15 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::I
static_cast<float>(tex.charPos.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y);
Math::Point texCoord2(static_cast<float>(tex.charPos.x + tex.charSize.x - halfPixelMargin) / FONT_TEXTURE_SIZE.x,
static_cast<float>(tex.charPos.y + tex.charSize.y - halfPixelMargin) / FONT_TEXTURE_SIZE.y);
Math::Vector n(0.0f, 0.0f, -1.0f); // normal
Vertex quad[4] =
glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 };
Vertex2D quad[4] =
{
Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(texCoord1.x, texCoord2.y)),
Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(texCoord1.x, texCoord1.y)),
Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(texCoord2.x, texCoord2.y)),
Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(texCoord2.x, texCoord1.y))
{ { p1.x, p2.y }, { texCoord1.x, texCoord2.y }, col },
{ { p1.x, p1.y }, { texCoord1.x, texCoord1.y }, col },
{ { p2.x, p2.y }, { texCoord2.x, texCoord2.y }, col },
{ { p2.x, p1.y }, { texCoord2.x, texCoord1.y }, col }
};
m_quadBatch->Add(quad, tex.id, ENG_RSTATE_TEXT, color);

View File

@ -31,6 +31,7 @@
#include "graphics/engine/engine.h"
#include "graphics/opengl/glframebuffer.h"
#include "graphics/opengl/gl33renderers.h"
#include "math/geometry.h"
@ -40,6 +41,8 @@
#include <cassert>
#include <glm/gtc/type_ptr.hpp>
// Graphics module namespace
namespace Gfx
@ -511,6 +514,8 @@ bool CGL33Device::Create()
glUniform1f(uni.alphaReference, 1.0f);
}
m_uiRenderer = std::make_unique<CGL33UIRenderer>();
SetRenderMode(RENDER_MODE_NORMAL);
// create default framebuffer object
@ -570,6 +575,8 @@ void CGL33Device::Destroy()
m_currentTextures.clear();
m_texturesEnabled.clear();
m_textureStageParams.clear();
m_uiRenderer = nullptr;
}
void CGL33Device::ConfigChanged(const DeviceConfig& newConfig)
@ -615,6 +622,8 @@ void CGL33Device::Clear()
void CGL33Device::SetRenderMode(RenderMode mode)
{
m_uiRenderer->Flush();
switch (mode)
{
case RENDER_MODE_NORMAL:
@ -641,6 +650,11 @@ void CGL33Device::SetRenderMode(RenderMode mode)
UpdateTextureState(2);
}
CUIRenderer* CGL33Device::GetUIRenderer()
{
return m_uiRenderer.get();
}
void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix)
{
if (type == TRANSFORM_WORLD)
@ -1170,6 +1184,11 @@ void CGL33Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, i
glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount);
}
void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount)
{
m_uiRenderer->DrawPrimitive(type, vertexCount, vertices);
}
void CGL33Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices,
int first[], int count[], int drawCount, Color color)
{
@ -1834,16 +1853,12 @@ void CGL33Device::UpdateLights()
inline void CGL33Device::BindVBO(GLuint vbo)
{
if (m_currentVBO == vbo) return;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
m_currentVBO = vbo;
}
inline void CGL33Device::BindVAO(GLuint vao)
{
if (m_currentVAO == vao) return;
glBindVertexArray(vao);
m_currentVAO = vao;
}

View File

@ -57,6 +57,8 @@ struct DynamicBuffer
unsigned int offset = 0;
};
class CGL33UIRenderer;
/**
\class CGL33Device
\brief Implementation of CDevice interface in OpenGL 3.3
@ -90,6 +92,7 @@ public:
void Clear() override;
void SetRenderMode(RenderMode mode) override;
CUIRenderer* GetUIRenderer() override;
void SetTransform(TransformType type, const Math::Matrix &matrix) override;
@ -121,6 +124,8 @@ public:
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) override;
virtual void DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount) override;
virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices,
int first[], int count[], int drawCount,
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override;
@ -314,6 +319,9 @@ private:
UniformLocations m_uniforms[3];
//! Uniform locations for current mode
UniformLocations* m_uni = nullptr;
//! Interface renderer
std::unique_ptr<CGL33UIRenderer> m_uiRenderer;
};
} // namespace Gfx

View File

@ -0,0 +1,195 @@
#include "graphics/opengl/gl33renderers.h"
#include "graphics/opengl/glutil.h"
#include "graphics/core/vertex.h"
#include "common/logger.h"
#include <GL/glew.h>
#include <glm/gtc/type_ptr.hpp>
namespace Gfx
{
CGL33UIRenderer::CGL33UIRenderer()
{
GLint shaders[2];
shaders[0] = LoadShader(GL_VERTEX_SHADER, "shaders/gl33/ui_vs.glsl");
if (shaders[0] == 0)
{
GetLogger()->Error("Cound not create vertex shader from file 'ui_vs.glsl'\n");
return;
}
shaders[1] = LoadShader(GL_FRAGMENT_SHADER, "shaders/gl33/ui_fs.glsl");
if (shaders[1] == 0)
{
GetLogger()->Error("Cound not create fragment shader from file 'ui_fs.glsl'\n");
return;
}
m_program = LinkProgram(2, shaders);
if (m_program == 0)
{
GetLogger()->Error("Cound not link shader program for normal rendering\n");
return;
}
glDeleteShader(shaders[0]);
glDeleteShader(shaders[1]);
glUseProgram(m_program);
m_projectionMatrix = glGetUniformLocation(m_program, "uni_ProjectionMatrix");
auto matrix = glm::ortho(0.0f, +1.0f, 0.0f, +1.0f);
glUniformMatrix4fv(m_projectionMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
// Set texture unit to 8th
auto texture = glGetUniformLocation(m_program, "uni_Texture");
glUniform1i(texture, 8);
// Generic buffer
glGenBuffers(1, &m_bufferVBO);
glBindBuffer(GL_COPY_WRITE_BUFFER, m_bufferVBO);
glBufferData(GL_COPY_WRITE_BUFFER, m_bufferCapacity, nullptr, GL_STREAM_DRAW);
glGenVertexArrays(1, &m_bufferVAO);
glBindVertexArray(m_bufferVAO);
// White texture
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &m_whiteTexture);
glBindTexture(GL_TEXTURE_2D, m_whiteTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ONE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ONE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ONE);
glUseProgram(0);
}
CGL33UIRenderer::~CGL33UIRenderer()
{
glDeleteProgram(m_program);
glDeleteTextures(1, &m_whiteTexture);
glDeleteBuffers(1, &m_bufferVBO);
glDeleteVertexArrays(1, &m_bufferVAO);
}
void CGL33UIRenderer::SetProjection(float left, float right, float bottom, float top)
{
Flush();
glUseProgram(m_program);
auto matrix = glm::ortho(left, right, bottom, top);
glUniformMatrix4fv(m_projectionMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
glUseProgram(0);
}
void CGL33UIRenderer::SetTexture(const Texture& texture)
{
if (m_currentTexture == texture.id) return;
Flush();
glActiveTexture(GL_TEXTURE8);
m_currentTexture = texture.id;
if (m_currentTexture == 0)
glBindTexture(GL_TEXTURE_2D, m_whiteTexture);
else
glBindTexture(GL_TEXTURE_2D, m_currentTexture);
}
void CGL33UIRenderer::DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices)
{
// If too much data would be buffered, flush
size_t totalSize = (m_buffer.size() + count) * sizeof(Vertex2D);
if (totalSize > m_bufferCapacity)
Flush();
// Buffer data
GLint first = m_buffer.size();
m_buffer.insert(m_buffer.end(), vertices, vertices + count);
m_types.push_back(TranslateGfxPrimitive(type));
m_firsts.push_back(first);
m_counts.push_back(count);
}
void CGL33UIRenderer::Flush()
{
if (m_types.empty()) return;
glUseProgram(m_program);
// Increase buffer size if necessary
size_t size = m_buffer.size() * sizeof(Vertex2D);
if (m_bufferCapacity < size)
m_bufferCapacity = size;
// Send new vertices to GPU
glBindBuffer(GL_ARRAY_BUFFER, m_bufferVBO);
glBufferData(GL_ARRAY_BUFFER, m_bufferCapacity, nullptr, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, size, m_buffer.data());
// Respecify vertex attributes
glBindVertexArray(m_bufferVAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, position)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, uv)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, color)));
// Draw primitives by grouping by type
for (size_t i = 0; i < m_types.size(); i++)
{
//glDrawArrays(m_types[i], m_firsts[i], m_counts[i]);
//*
size_t count = 1;
for (; i + count < m_types.size(); count++)
{
if (m_types[i] != m_types[i + count])
break;
}
glMultiDrawArrays(m_types[i], &m_firsts[i], &m_counts[i], count);
i += count;
// */
}
// Clear buffers
m_buffer.clear();
m_types.clear();
m_firsts.clear();
m_counts.clear();
glUseProgram(0);
}
} // namespace Gfx

View File

@ -0,0 +1,77 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file graphics/opengl/gl33renderers.h
* \brief OpenGL 3.3 renderers
*/
#pragma once
#include "graphics/core/renderers.h"
#include <gl/glew.h>
#include <array>
#include <vector>
// Graphics module namespace
namespace Gfx
{
class CGL33UIRenderer : public CUIRenderer
{
public:
CGL33UIRenderer();
virtual ~CGL33UIRenderer();
virtual void SetProjection(float left, float right, float bottom, float top) override;
virtual void SetTexture(const Texture& texture) override;
virtual void DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) override;
virtual void Flush() override;
private:
// location of uni_ProjectionMatrix uniform
GLint m_projectionMatrix = -1;
// Vertex buffer object
GLuint m_bufferVBO = 0;
// Vertex array object
GLuint m_bufferVAO = 0;
// VBO capacity
GLsizei m_bufferCapacity = 4 * 1024;
// Buffered vertex data
std::vector<Vertex2D> m_buffer;
std::vector<GLenum> m_types;
std::vector<GLint> m_firsts;
std::vector<GLsizei> m_counts;
// Shader program
GLuint m_program = 0;
// 1x1 white texture
GLuint m_whiteTexture = 0;
// Currently bound texture
GLuint m_currentTexture = 0;
};
} // namespace Gfx

View File

@ -0,0 +1,36 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
// FRAGMENT SHADER - UI RENDERER
#version 330 core
uniform sampler2D uni_Texture;
in VertexData
{
vec4 Color;
vec2 TexCoord;
} data;
out vec4 out_FragColor;
void main()
{
out_FragColor = data.Color * texture(uni_Texture, data.TexCoord);
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
// VERTEX SHADER - UI RENDERER
#version 330 core
uniform mat4 uni_ProjectionMatrix;
layout(location = 0) in vec4 in_VertexCoord;
layout(location = 1) in vec2 in_TexCoord;
layout(location = 2) in vec4 in_Color;
out VertexData
{
vec4 Color;
vec2 TexCoord;
} data;
void main()
{
gl_Position = uni_ProjectionMatrix * in_VertexCoord;
data.Color = in_Color;
data.TexCoord = in_TexCoord;
}

View File

@ -24,6 +24,7 @@
#include "common/restext.h"
#include "graphics/engine/engine.h"
#include "graphics/core/device.h"
namespace Ui
@ -141,6 +142,8 @@ void CButton::Draw()
Math::Point pos, dim, uv1, uv2;
float dp;
auto device = m_engine->GetDevice();
if ( (m_state & STATE_VISIBLE) == 0 ) return;
if ( m_state & STATE_WARNING ) // shading yellow-black?
@ -167,8 +170,8 @@ void CButton::Draw()
(m_state & STATE_CARD ) == 0 &&
(m_state & STATE_SIMPLY) == 0 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
m_engine->SetUITexture("textures/interface/button2.png");
dp = 0.5f / 256.0f;
@ -199,6 +202,8 @@ void CButton::Draw()
pos.x = m_pos.x + m_dim.x - 5.0f / 640.0f - 3.0f / 640.0f;
DrawIcon(pos, dim, uv1, uv2, 0.0f);
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}

View File

@ -23,6 +23,7 @@
#include "common/event.h"
#include "common/restext.h"
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/text.h"
@ -92,6 +93,8 @@ void CCheck::Draw()
float zoomExt, zoomInt;
int icon;
auto device = m_engine->GetDevice();
if ( (m_state & STATE_VISIBLE) == 0 ) return;
iDim = m_dim;
@ -102,8 +105,8 @@ void CCheck::Draw()
DrawShadow(m_pos, m_dim);
}
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
m_engine->SetUITexture("textures/interface/button1.png");
zoomExt = 1.00f;
zoomInt = 0.95f;
@ -146,6 +149,8 @@ void CCheck::Draw()
}
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
m_dim = iDim;
// Draw the name.

View File

@ -124,10 +124,9 @@ bool CColor::EventProcess(const Event &event)
// Draw the button.
void CColor::Draw()
{
Gfx::CDevice* device;
Gfx::VertexCol vertex[4]; // 2 triangles
Gfx::Color color;
Math::Point p1, p2;
Gfx::Vertex2D vertex[4]; // 2 triangles
Gfx::Color color;
Math::Point p1, p2;
if ( (m_state & STATE_VISIBLE) == 0 ) return;
@ -136,7 +135,7 @@ void CColor::Draw()
DrawShadow(m_pos, m_dim);
}
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
CControl::Draw();
@ -147,19 +146,23 @@ void CColor::Draw()
color = GetColor();
m_engine->SetTexture(""); // no texture
glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 };
m_engine->SetUITexture(Gfx::Texture{0}); // no texture
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
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);
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);
auto device = m_engine->GetDevice();
vertex[0] = { { p1.x, p1.y }, {}, col };
vertex[1] = { { p1.x, p2.y }, {}, col };
vertex[2] = { { p2.x, p1.y }, {}, col };
vertex[3] = { { p2.x, p2.y }, {}, col };
device = m_engine->GetDevice();
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
m_engine->AddStatisticTriangle(2);
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
void CColor::SetRepeat(bool bRepeat)
{

View File

@ -453,8 +453,9 @@ void CControl::Draw()
if ( (m_state & STATE_VISIBLE) == 0 ) return;
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
m_engine->SetUITexture("textures/interface/button1.png");
auto device = m_engine->GetDevice();
zoomExt = 1.00f;
zoomInt = 0.95f;
@ -507,7 +508,7 @@ void CControl::Draw()
if ( m_state & STATE_OKAY )
{
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
icon = 3; // yellow with green point pressed
}
@ -555,6 +556,8 @@ void CControl::Draw()
m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, m_dim.x, m_textAlign, 0);
}
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draw the vertex array.
@ -606,26 +609,22 @@ void CControl::DrawPart(int icon, float zoom, float ex)
void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2,
float ex)
{
Gfx::CDevice* device;
Gfx::Vertex vertex[8]; // 6 triangles
Math::Point p1, p2, p3, p4;
Math::Vector n;
Gfx::Vertex2D vertex[8]; // 6 triangles
glm::vec2 p1, p2, p3, p4;
device = m_engine->GetDevice();
auto device = m_engine->GetDevice();
p1.x = pos.x;
p1.y = pos.y;
p2.x = pos.x + dim.x;
p2.y = pos.y + dim.y;
n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
if ( ex == 0.0f ) // one piece?
{
vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x,uv2.y));
vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x,uv1.y));
vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x,uv2.y));
vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x,uv1.y));
vertex[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } };
vertex[1] = { { p1.x, p2.y }, { uv1.x, uv1.y } };
vertex[2] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertex[3] = { { p2.x, p2.y }, { uv2.x, uv1.y } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
m_engine->AddStatisticTriangle(2);
@ -637,14 +636,14 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math:
p3.x = p1.x + ex*dim.y / (uv2.y - uv1.y);
p4.x = p2.x - ex*dim.y / (uv2.y - uv1.y);
vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y));
vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y));
vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p1.y, 0.0f), n, Math::Point(uv1.x+ex,uv2.y));
vertex[3] = Gfx::Vertex(Math::Vector(p3.x, p2.y, 0.0f), n, Math::Point(uv1.x+ex,uv1.y));
vertex[4] = Gfx::Vertex(Math::Vector(p4.x, p1.y, 0.0f), n, Math::Point(uv2.x-ex,uv2.y));
vertex[5] = Gfx::Vertex(Math::Vector(p4.x, p2.y, 0.0f), n, Math::Point(uv2.x-ex,uv1.y));
vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y));
vertex[7] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y));
vertex[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } };
vertex[1] = { { p1.x, p2.y }, { uv1.x, uv1.y } };
vertex[2] = { { p3.x, p1.y }, { uv1.x+ex,uv2.y } };
vertex[3] = { { p3.x, p2.y }, { uv1.x+ex,uv1.y } };
vertex[4] = { { p4.x, p1.y }, { uv2.x-ex,uv2.y } };
vertex[5] = { { p4.x, p2.y }, { uv2.x-ex,uv1.y } };
vertex[6] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertex[7] = { { p2.x, p2.y }, { uv2.x, uv1.y } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8);
m_engine->AddStatisticTriangle(6);
@ -654,19 +653,21 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math:
p3.y = p1.y + ex*dim.x / (uv2.x - uv1.x);
p4.y = p2.y - ex*dim.x / (uv2.x - uv1.x);
vertex[0] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y ));
vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y ));
vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p3.y, 0.0f), n, Math::Point(uv2.x, uv2.y - ex));
vertex[3] = Gfx::Vertex(Math::Vector(p1.x, p3.y, 0.0f), n, Math::Point(uv1.x, uv2.y - ex));
vertex[4] = Gfx::Vertex(Math::Vector(p2.x, p4.y, 0.0f), n, Math::Point(uv2.x, uv1.y + ex));
vertex[5] = Gfx::Vertex(Math::Vector(p1.x, p4.y, 0.0f), n, Math::Point(uv1.x, uv1.y + ex));
vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y ));
vertex[7] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y ));
vertex[0] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertex[1] = { { p1.x, p1.y }, { uv1.x, uv2.y } };
vertex[2] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } };
vertex[3] = { { p1.x, p3.y }, { uv1.x, uv2.y - ex } };
vertex[4] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } };
vertex[5] = { { p1.x, p4.y }, { uv1.x, uv1.y + ex } };
vertex[6] = { { p2.x, p2.y }, { uv2.x, uv1.y } };
vertex[7] = { { p1.x, p2.y }, { uv1.x, uv1.y } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8);
m_engine->AddStatisticTriangle(6);
}
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draws a rectangular icon made up of 9 pieces.
@ -674,20 +675,16 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math:
void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2,
Math::Point corner, float ex)
{
Gfx::CDevice* device;
Gfx::Vertex vertex[8]; // 6 triangles
Math::Point p1, p2, p3, p4;
Math::Vector n;
Gfx::Vertex2D vertices[8]; // 6 triangles
glm::vec2 p1, p2, p3, p4;
device = m_engine->GetDevice();
auto device = m_engine->GetDevice();
p1.x = pos.x;
p1.y = pos.y;
p2.x = pos.x + dim.x;
p2.y = pos.y + dim.y;
n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
if ( corner.x > dim.x / 2.0f ) corner.x = dim.x / 2.0f;
if ( corner.y > dim.y / 2.0f ) corner.y = dim.y / 2.0f;
@ -701,40 +698,45 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math:
p4.y = p2.y - corner.y;
// Bottom horizontal band.
vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y ));
vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p3.y, 0.0f), n, Math::Point(uv1.x, uv2.y - ex));
vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p1.y, 0.0f), n, Math::Point(uv1.x + ex, uv2.y ));
vertex[3] = Gfx::Vertex(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv1.x + ex, uv2.y - ex));
vertex[4] = Gfx::Vertex(Math::Vector(p4.x, p1.y, 0.0f), n, Math::Point(uv2.x - ex, uv2.y ));
vertex[5] = Gfx::Vertex(Math::Vector(p4.x, p3.y, 0.0f), n, Math::Point(uv2.x - ex, uv2.y - ex));
vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y ));
vertex[7] = Gfx::Vertex(Math::Vector(p2.x, p3.y, 0.0f), n, Math::Point(uv2.x, uv2.y - ex));
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8);
vertices[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } };
vertices[1] = { { p1.x, p3.y }, { uv1.x, uv2.y - ex } };
vertices[2] = { { p3.x, p1.y }, { uv1.x + ex, uv2.y } };
vertices[3] = { { p3.x, p3.y }, { uv1.x + ex, uv2.y - ex } };
vertices[4] = { { p4.x, p1.y }, { uv2.x - ex, uv2.y } };
vertices[5] = { { p4.x, p3.y }, { uv2.x - ex, uv2.y - ex } };
vertices[6] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertices[7] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 8);
m_engine->AddStatisticTriangle(6);
// Central horizontal band.
vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p3.y, 0.0f), n, Math::Point(uv1.x, uv2.y - ex));
vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p4.y, 0.0f), n, Math::Point(uv1.x, uv1.y + ex));
vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv1.x + ex, uv2.y - ex));
vertex[3] = Gfx::Vertex(Math::Vector(p3.x, p4.y, 0.0f), n, Math::Point(uv1.x + ex, uv1.y + ex));
vertex[4] = Gfx::Vertex(Math::Vector(p4.x, p3.y, 0.0f), n, Math::Point(uv2.x - ex, uv2.y - ex));
vertex[5] = Gfx::Vertex(Math::Vector(p4.x, p4.y, 0.0f), n, Math::Point(uv2.x - ex, uv1.y + ex));
vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p3.y, 0.0f), n, Math::Point(uv2.x, uv2.y - ex));
vertex[7] = Gfx::Vertex(Math::Vector(p2.x, p4.y, 0.0f), n, Math::Point(uv2.x, uv1.y + ex));
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8);
vertices[0] = { { p1.x, p3.y }, { uv1.x, uv2.y - ex } };
vertices[1] = { { p1.x, p4.y }, { uv1.x, uv1.y + ex } };
vertices[2] = { { p3.x, p3.y }, { uv1.x + ex, uv2.y - ex } };
vertices[3] = { { p3.x, p4.y }, { uv1.x + ex, uv1.y + ex } };
vertices[4] = { { p4.x, p3.y }, { uv2.x - ex, uv2.y - ex } };
vertices[5] = { { p4.x, p4.y }, { uv2.x - ex, uv1.y + ex } };
vertices[6] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } };
vertices[7] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 8);
m_engine->AddStatisticTriangle(6);
// Top horizontal band.
vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p4.y, 0.0f), n, Math::Point(uv1.x, uv1.y + ex));
vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y ));
vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p4.y, 0.0f), n, Math::Point(uv1.x + ex, uv1.y + ex));
vertex[3] = Gfx::Vertex(Math::Vector(p3.x, p2.y, 0.0f), n, Math::Point(uv1.x + ex, uv1.y ));
vertex[4] = Gfx::Vertex(Math::Vector(p4.x, p4.y, 0.0f), n, Math::Point(uv2.x - ex, uv1.y + ex));
vertex[5] = Gfx::Vertex(Math::Vector(p4.x, p2.y, 0.0f), n, Math::Point(uv2.x - ex, uv1.y ));
vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p4.y, 0.0f), n, Math::Point(uv2.x, uv1.y + ex));
vertex[7] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y ));
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8);
vertices[0] = { { p1.x, p4.y }, { uv1.x, uv1.y + ex } };
vertices[1] = { { p1.x, p2.y }, { uv1.x, uv1.y } };
vertices[2] = { { p3.x, p4.y }, { uv1.x + ex, uv1.y + ex } };
vertices[3] = { { p3.x, p2.y }, { uv1.x + ex, uv1.y } };
vertices[4] = { { p4.x, p4.y }, { uv2.x - ex, uv1.y + ex } };
vertices[5] = { { p4.x, p2.y }, { uv2.x - ex, uv1.y } };
vertices[6] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } };
vertices[7] = { { p2.x, p2.y }, { uv2.x, uv1.y } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 8);
m_engine->AddStatisticTriangle(6);
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draw round the hatch of a button.
@ -746,8 +748,9 @@ void CControl::DrawWarning(Math::Point pos, Math::Point dim)
dp = 0.5f / 256.0f;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
m_engine->SetUITexture("textures/interface/button2.png");
auto device = m_engine->GetDevice();
uv1.x = 64.0f / 256.0f;
uv1.y = 208.0f / 256.0f;
@ -779,6 +782,8 @@ void CControl::DrawWarning(Math::Point pos, Math::Point dim)
pos.x += dim.x;
DrawIcon(pos, dim, uv1, uv2);
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draw the shade under a button.
@ -790,8 +795,9 @@ void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep)
dp = 0.5f/256.0f;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState( Gfx::ENG_RSTATE_TTEXTURE_WHITE);
m_engine->SetUITexture("textures/interface/button2.png");
auto device = m_engine->GetDevice();
pos.x += deep * 0.010f * 0.75f;
pos.y -= deep * 0.015f;
@ -812,6 +818,8 @@ void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep)
corner.y = 10.0f / 480.0f;
DrawIcon(pos, dim, uv1, uv2, corner, 6.0f / 256.0f);
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
@ -841,7 +849,9 @@ int CControl::SetButtonTextureForIcon(int icon)
{
int iconIdx = icon%64;
int buttonFile = (icon/64) + 1;
m_engine->SetTexture("textures/interface/button" + StrUtils::ToString<int>(buttonFile) + ".png");
m_engine->SetUITexture("textures/interface/button" + StrUtils::ToString<int>(buttonFile) + ".png");
return iconIdx;
}

View File

@ -1155,6 +1155,8 @@ void CEdit::Draw()
{
m_scroll->Draw();
}
m_engine->GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draw an image part.
@ -1182,7 +1184,7 @@ void CEdit::DrawImage(Math::Point pos, std::string name, float width,
params.padToNearestPowerOfTwo = true;
Gfx::Texture tex = m_engine->LoadTexture(PrepareImageFilename(name), params);
m_engine->SetTexture(tex);
m_engine->SetUITexture(tex);
uv1.x = 0.0f;
uv2.x = 1.0f;
@ -1214,7 +1216,7 @@ void CEdit::DrawBack(Math::Point pos, Math::Point dim)
if ( m_bGeneric ) return;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
if ( m_bMulti )
@ -1267,12 +1269,15 @@ void CEdit::DrawHorizontalGradient(Math::Point pos, Math::Point dim, Gfx::Color
p2.x = pos.x + dim.x;
p2.y = pos.y + dim.y;
Gfx::VertexCol quad[] =
glm::u8vec4 col1 = { color1.r * 255, color1.g * 255, color1.b * 255, color1.a * 255 };
glm::u8vec4 col2 = { color2.r * 255, color2.g * 255, color2.b * 255, color2.a * 255 };
Gfx::Vertex2D quad[] =
{
Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color1),
Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color1),
Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color2),
Gfx::VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color2)
{ { p1.x, p1.y }, {}, col1 },
{ { p1.x, p2.y }, {}, col1 },
{ { p2.x, p1.y }, {}, col2 },
{ { p2.x, p2.y }, {}, col2 }
};
m_engine->GetDevice()->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4);

View File

@ -78,7 +78,7 @@ void CGauge::Draw()
if ( (m_state & STATE_VISIBLE) == 0 ) return;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
dp = 0.5f/256.0f;

View File

@ -23,6 +23,7 @@
#include "common/event.h"
#include "common/restext.h"
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
@ -79,6 +80,8 @@ void CGroup::Draw()
float dp;
int icon;
auto device = m_engine->GetDevice();
if ( (m_state & STATE_VISIBLE) == 0 ) return;
if ( m_state & STATE_SHADOW )
@ -90,8 +93,9 @@ void CGroup::Draw()
if ( m_icon == 0 ) // hollow frame?
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 160.0f / 256.0f;
uv1.y = 192.0f / 256.0f; // u-v texture
uv2.x = 192.0f / 256.0f;
@ -106,8 +110,9 @@ void CGroup::Draw()
}
if ( m_icon == 1 ) // orange solid opaque?
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
m_engine->SetUITexture("textures/interface/button2.png");
uv1.x = 104.0f / 256.0f;
uv1.y = 48.0f / 256.0f;
uv2.x = 112.0f / 256.0f;
@ -120,8 +125,9 @@ void CGroup::Draw()
}
if ( m_icon == 2 ) // orange degrade -> transparent?
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
m_engine->SetUITexture("textures/interface/button2.png");
uv1.x = 112.0f / 256.0f;
uv1.y = 48.0f / 256.0f;
uv2.x = 120.0f / 256.0f;
@ -134,8 +140,9 @@ void CGroup::Draw()
}
if ( m_icon == 3 ) // transparent gradient -> gray?
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
m_engine->SetUITexture("textures/interface/button2.png");
uv1.x = 120.0f / 256.0f;
uv1.y = 48.0f / 256.0f;
uv2.x = 128.0f / 256.0f;
@ -148,8 +155,9 @@ void CGroup::Draw()
}
if ( m_icon == 4 ) // degrade blue corner?
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
m_engine->SetUITexture("textures/interface/button2.png");
uv1.x = 192.0f / 256.0f;
uv1.y = 128.0f / 256.0f;
uv2.x = 224.0f / 256.0f;
@ -162,8 +170,9 @@ void CGroup::Draw()
}
if ( m_icon == 5 ) // degrade orange corner?
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
m_engine->SetUITexture("textures/interface/button2.png");
uv1.x = 224.0f / 256.0f;
uv1.y = 128.0f / 256.0f;
uv2.x = 256.0f / 256.0f;
@ -176,8 +185,9 @@ void CGroup::Draw()
}
if ( m_icon == 6 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 0.0f / 256.0f; // brown transparent
uv1.y = 75.0f / 256.0f;
uv2.x = 64.0f / 256.0f;
@ -192,8 +202,9 @@ void CGroup::Draw()
}
if ( m_icon == 7 )
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f;
uv1.y = 0.0f / 256.0f;
uv2.x = 96.0f / 256.0f;
@ -206,8 +217,9 @@ void CGroup::Draw()
}
if ( m_icon == 8 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f / 256.0f; // green transparent
uv1.y = 160.0f / 256.0f;
uv2.x = 160.0f / 256.0f;
@ -220,8 +232,9 @@ void CGroup::Draw()
}
if ( m_icon == 9 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f / 256.0f; // red transparent
uv1.y = 176.0f/256.0f;
uv2.x = 160.0f/256.0f;
@ -234,8 +247,9 @@ void CGroup::Draw()
}
if ( m_icon == 10 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f / 256.0f; // blue transparent
uv1.y = 192.0f / 256.0f;
uv2.x = 160.0f / 256.0f;
@ -248,7 +262,7 @@ void CGroup::Draw()
}
if ( m_icon == 11 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f / 256.0f; // yellow transparent
uv1.y = 224.0f / 256.0f;
@ -265,7 +279,7 @@ void CGroup::Draw()
dim.x = m_dim.x / 2.0f;
dim.y = m_dim.y / 2.0f;
m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetUITexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/300.0f;
pos.y = m_pos.y+m_dim.y/300.0f+dim.y;
@ -304,7 +318,7 @@ void CGroup::Draw()
}
if ( m_icon == 13 ) // corner upper / left?
{
m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetUITexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f;
@ -325,7 +339,7 @@ void CGroup::Draw()
}
if ( m_icon == 14 ) // corner upper / right?
{
m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetUITexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f;
@ -346,7 +360,7 @@ void CGroup::Draw()
}
if ( m_icon == 15 ) // corner lower / left?
{
m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetUITexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f;
@ -367,7 +381,7 @@ void CGroup::Draw()
}
if ( m_icon == 16 ) // corner lower / left?
{
m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetUITexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f;
@ -388,7 +402,7 @@ void CGroup::Draw()
}
if ( m_icon == 17 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f / 256.0f; // blue frame
uv1.y = 75.0f / 256.0f;
@ -404,7 +418,7 @@ void CGroup::Draw()
}
if ( m_icon == 18 ) // arrow> for SatCom?
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 0.0f / 256.0f; // >
uv1.y = 192.0f / 256.0f;
@ -418,7 +432,7 @@ void CGroup::Draw()
}
if ( m_icon == 19 ) // SatCom symbol?
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 224.0f / 256.0f; // SatCom symbol
uv1.y = 224.0f / 256.0f;
@ -432,7 +446,7 @@ void CGroup::Draw()
}
if ( m_icon == 20 ) // solid blue background?
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 224.0f / 256.0f;
uv1.y = 32.0f / 256.0f;
@ -446,7 +460,7 @@ void CGroup::Draw()
}
if ( m_icon == 21 ) // stand-by symbol?
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 160.0f / 256.0f;
uv1.y = 32.0f / 256.0f;
@ -460,7 +474,7 @@ void CGroup::Draw()
}
if ( m_icon == 22 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f; // opaque yellow
uv1.y = 224.0f / 256.0f;
@ -477,7 +491,7 @@ void CGroup::Draw()
if ( m_icon == 23 )
{
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f; // yellow
uv1.y = 192.0f / 256.0f;
@ -493,7 +507,7 @@ void CGroup::Draw()
}
if ( m_icon == 24 )
{
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 80.0f / 256.0f; // orange
uv1.y = 192.0f / 256.0f;
@ -509,7 +523,7 @@ void CGroup::Draw()
}
if ( m_icon == 25 )
{
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f; // orange
uv1.y = 208.0f / 256.0f;
@ -525,7 +539,7 @@ void CGroup::Draw()
}
if ( m_icon == 26 )
{
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 80.0f / 256.0f; // red
uv1.y = 208.0f / 256.0f;
@ -541,7 +555,7 @@ void CGroup::Draw()
}
if ( m_icon == 27 )
{
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 32.0f / 256.0f;
uv1.y = 0.0f / 256.0f;
@ -558,8 +572,7 @@ void CGroup::Draw()
{
pos = m_pos;
dim = m_dim;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 32.0f / 256.0f;
uv1.y = 32.0f / 256.0f;
@ -571,7 +584,7 @@ void CGroup::Draw()
uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2);
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
pos.x += 8.0f / 640.0f;
pos.y += 8.0f / 480.0f;
@ -633,6 +646,8 @@ void CGroup::Draw()
uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2);
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}

View File

@ -102,7 +102,7 @@ void CImage::Draw()
if ( m_icon == 0 ) // hollow frame?
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 160.0f / 256.0f;
uv1.y = 192.0f / 256.0f; // u-v texture
@ -124,7 +124,7 @@ void CImage::Draw()
params.filter = Gfx::TEX_FILTER_BILINEAR;
params.padToNearestPowerOfTwo = true;
Gfx::Texture tex = m_engine->LoadTexture(m_filename, params);
m_engine->SetTexture(tex);
m_engine->SetUITexture(tex);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
pos = m_pos;
dim = m_dim;

View File

@ -135,7 +135,7 @@ void CKey::Draw()
DrawShadow(m_pos, m_dim);
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
float zoomExt = 1.00f;

View File

@ -370,7 +370,7 @@ void CList::Draw()
if (m_icon == 0)
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f / 256.0f;
@ -380,7 +380,7 @@ void CList::Draw()
}
else
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 132.0f / 256.0f;
@ -416,7 +416,7 @@ void CList::Draw()
dim.y *= 0.4f;
pos.y -= dim.y;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw
uv1.x = 120.0f / 256.0f;
uv1.y = 64.0f / 256.0f;
@ -491,7 +491,7 @@ void CList::Draw()
if (m_items[i + m_firstLine].check)
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f;
uv1.y = 0.0f / 256.0f;
@ -516,7 +516,7 @@ void CList::Draw()
}
else
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw
if ( i + m_firstLine == m_selectLine )
{

View File

@ -344,7 +344,7 @@ void CMap::Draw()
if (m_fixImage.empty()) // drawing of the relief?
{
m_engine->SetTexture("textures/interface/map.png");
m_engine->SetUITexture("textures/interface/map.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.5f + (m_offset.x - (m_half / m_zoom)) / (m_half * 2.0f);
uv1.y = 0.5f - (m_offset.y + (m_half / m_zoom)) / (m_half * 2.0f);
@ -355,7 +355,7 @@ void CMap::Draw()
else // still image?
{
m_engine->LoadTexture(m_fixImage);
m_engine->SetTexture(m_fixImage);
m_engine->SetUITexture(m_fixImage);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f;
uv1.y = 0.0f;
@ -493,7 +493,7 @@ void CMap::DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color
uv2.x = 126.0f/256.0f;
uv2.y = 255.0f/256.0f;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
bEnding = false;
@ -553,7 +553,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
return; // flashes
}
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
if ( bUp )
{
@ -696,7 +696,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
{
if ( bSelect )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
if ( m_bToy )
{
@ -722,7 +722,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
{
if ( m_bRadar )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 64.5f/256.0f; // blue triangle
uv1.y = 240.5f/256.0f;
@ -742,7 +742,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
if ( color == MAPCOLOR_WAYPOINTb )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 192.5f/256.0f; // blue cross
uv1.y = 240.5f/256.0f;
@ -752,7 +752,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
}
if ( color == MAPCOLOR_WAYPOINTr )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 208.5f/256.0f; // red cross
uv1.y = 240.5f/256.0f;
@ -762,7 +762,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
}
if ( color == MAPCOLOR_WAYPOINTg )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 224.5f/256.0f; // green cross
uv1.y = 240.5f/256.0f;
@ -772,7 +772,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
}
if ( color == MAPCOLOR_WAYPOINTy )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 240.5f/256.0f; // yellow cross
uv1.y = 240.5f/256.0f;
@ -782,7 +782,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
}
if ( color == MAPCOLOR_WAYPOINTv )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 192.5f/256.0f; // violet cross
uv1.y = 224.5f/256.0f;
@ -803,7 +803,7 @@ void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color,
dp = 0.5f/256.0f;
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
if ( color == MAPCOLOR_MOVE )
{
@ -907,7 +907,7 @@ void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color,
case OBJECT_MOBILEit:
case OBJECT_MOBILErp:
case OBJECT_MOBILEst:
m_engine->SetTexture("textures/interface/button4.png"); break;
m_engine->SetUITexture("textures/interface/button4.png"); break;
default: ; // button3.png
}
@ -942,7 +942,7 @@ void CMap::DrawHighlight(Math::Point pos)
dim.x *= 2.0f+cosf(m_time*8.0f)*0.5f;
dim.y *= 2.0f+cosf(m_time*8.0f)*0.5f;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 160.5f/256.0f; // hilite
uv1.y = 224.5f/256.0f;
@ -957,17 +957,13 @@ void CMap::DrawHighlight(Math::Point pos)
void CMap::DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point uv1, Math::Point uv2)
{
Gfx::CDevice* device;
Gfx::VertexTex2 vertex[3]; // 1 triangle
Math::Vector n;
Gfx::Vertex2D vertex[3]; // 1 triangle
device = m_engine->GetDevice();
auto device = m_engine->GetDevice();
n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
vertex[0] = Gfx::VertexTex2(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x,uv1.y));
vertex[1] = Gfx::VertexTex2(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv1.x,uv2.y));
vertex[2] = Gfx::VertexTex2(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv2.x,uv2.y));
vertex[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } };
vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.y } };
vertex[2] = { { p3.x, p3.y }, { uv2.x, uv2.y } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, vertex, 3);
m_engine->AddStatisticTriangle(1);
@ -977,19 +973,15 @@ void CMap::DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Po
void CMap::DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point p4, Math::Point p5, Math::Point uv1, Math::Point uv2)
{
Gfx::CDevice* device;
Gfx::VertexTex2 vertex[5]; // 1 pentagon
Math::Vector n;
Gfx::Vertex2D vertex[5]; // 1 pentagon
device = m_engine->GetDevice();
auto device = m_engine->GetDevice();
n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
vertex[0] = Gfx::VertexTex2(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x,uv1.y));
vertex[1] = Gfx::VertexTex2(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv1.x,uv2.y));
vertex[2] = Gfx::VertexTex2(Math::Vector(p5.x, p5.y, 0.0f), n, Math::Point(uv2.x,uv2.y));
vertex[3] = Gfx::VertexTex2(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv2.x,uv2.y));
vertex[4] = Gfx::VertexTex2(Math::Vector(p4.x, p4.y, 0.0f), n, Math::Point(uv2.x,uv2.y));
vertex[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } };
vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.y } };
vertex[2] = { { p5.x, p5.y }, { uv2.x, uv2.y } };
vertex[3] = { { p3.x, p3.y }, { uv2.x, uv2.y } };
vertex[4] = { { p4.x, p4.y }, { uv2.x, uv2.y } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 5);
m_engine->AddStatisticTriangle(3);
@ -999,12 +991,10 @@ void CMap::DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point
void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom)
{
Gfx::CDevice* device;
Gfx::VertexTex2 vertex[4]; // 2 triangles
Gfx::Vertex2D vertex[4]; // 2 triangles
Math::Point p1, p2, c;
Math::Vector n;
device = m_engine->GetDevice();
auto device = m_engine->GetDevice();
p1.x = m_pos.x;
p1.y = m_pos.y;
@ -1024,12 +1014,10 @@ void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom)
m_mapDim.x = p2.x-p1.x;
m_mapDim.y = p2.y-p1.y;
n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
vertex[0] = Gfx::VertexTex2(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x,uv2.y));
vertex[1] = Gfx::VertexTex2(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x,uv1.y));
vertex[2] = Gfx::VertexTex2(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x,uv2.y));
vertex[3] = Gfx::VertexTex2(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x,uv1.y));
vertex[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } };
vertex[1] = { { p1.x, p2.y }, { uv1.x, uv1.y } };
vertex[2] = { { p2.x, p1.y }, { uv2.x, uv2.y } };
vertex[3] = { { p2.x, p2.y }, { uv2.x, uv1.y } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
m_engine->AddStatisticTriangle(2);
@ -1094,6 +1082,7 @@ void CMap::UpdateTerrain()
m_engine->DeleteTexture("interface/map.png");
m_engine->LoadTexture("textures/interface/map.png", &img);
m_engine->SetUITexture("textures/interface/map.png");
}
// Updates the field in the map.

View File

@ -23,6 +23,7 @@
#include "common/event.h"
#include "common/make_unique.h"
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
#include "ui/controls/button.h"
@ -306,6 +307,8 @@ void CScroll::Draw()
float hButton;
int icon, n, i;
auto device = m_engine->GetDevice();
hButton = m_buttonUp?m_dim.x/0.75f:0.0f;
// Draws the bottom.
@ -351,6 +354,8 @@ void CScroll::Draw()
{
m_buttonDown->Draw();
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draws a rectangle.
@ -360,9 +365,11 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon)
Math::Point uv1, uv2;
float ex, dp;
auto device = m_engine->GetDevice();
if ( icon == 0 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f/256.0f; // yellow rectangle
uv1.y = 32.0f/256.0f;
@ -372,7 +379,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 1 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // gray rectangle
uv1.y = 32.0f/256.0f;
@ -382,7 +389,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 2 )
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f/256.0f; // blue rectangle
uv1.y = 0.0f/256.0f;
@ -392,7 +399,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 104.0f/256.0f; // blue line -
uv1.y = 32.0f/256.0f;

View File

@ -115,7 +115,7 @@ void CShortcut::Draw()
zoom = 1.0f;
}
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
if ( icon != -1 )
{
@ -216,19 +216,19 @@ void CShortcut::Draw()
DrawIcon(m_pos, m_dim, uv1, uv2);
}
m_engine->GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draw the vertex array.
void CShortcut::DrawVertex(int icon, float zoom)
{
Gfx::CDevice* device;
Gfx::Vertex vertex[4]; // 2 triangles
Gfx::Vertex2D vertex[4]; // 2 triangles
Math::Point p1, p2, c;
Math::Vector n;
float u1, u2, v1, v2, dp;
device = m_engine->GetDevice();
auto device = m_engine->GetDevice();
p1.x = m_pos.x;
p1.y = m_pos.y;
@ -255,12 +255,10 @@ void CShortcut::DrawVertex(int icon, float zoom)
u2 -= dp;
v2 -= dp;
n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2));
vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1));
vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2));
vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1));
vertex[0] = { { p1.x, p1.y }, { u1, v2 } };
vertex[1] = { { p1.x, p2.y }, { u1, v1 } };
vertex[2] = { { p2.x, p1.y }, { u2, v2 } };
vertex[3] = { { p2.x, p2.y }, { u2, v1 } };
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
m_engine->AddStatisticTriangle(2);

View File

@ -23,6 +23,7 @@
#include "common/event.h"
#include "common/stringutils.h"
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/text.h"
@ -371,6 +372,8 @@ void CSlider::Draw()
int icon;
float h;
auto device = m_engine->GetDevice();
if ( (m_state & STATE_VISIBLE) == 0 ) return;
if (m_buttonLeft != nullptr)
@ -472,6 +475,8 @@ void CSlider::Draw()
m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_RIGHT, 0);
}
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
std::string CSlider::GetLabel()
@ -486,9 +491,12 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon)
Math::Point uv1, uv2, corner;
float ex, dp;
auto device = m_engine->GetDevice();
auto renderer = device->GetUIRenderer();
if ( icon == 0 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f/256.0f; // yellow rectangle
uv1.y = 32.0f/256.0f;
@ -500,7 +508,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 1 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // gray rectangle
uv1.y = 32.0f/256.0f;
@ -512,7 +520,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 224.0f/256.0f; // cursor
uv1.y = 32.0f/256.0f;
@ -535,6 +543,8 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon)
uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2, corner, ex);
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}

View File

@ -38,6 +38,8 @@
#include "ui/controls/slider.h"
#include "ui/controls/target.h"
#include "graphics/core/device.h"
#include <algorithm>
@ -816,6 +818,8 @@ void CWindow::Draw()
{
if ( (m_state & STATE_VISIBLE) == 0 ) return;
auto device = m_engine->GetDevice();
if ( m_state & STATE_SHADOW )
{
DrawShadow(m_pos, m_dim);
@ -862,6 +866,8 @@ void CWindow::Draw()
DrawHach(pos, dim); // right hatch
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
pos.x = m_pos.x+width/2.0f;
pos.y = m_pos.y+m_dim.y-0.01f-h*1.10f;
m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, width, Gfx::TEXT_ALIGN_CENTER, 0);
@ -886,6 +892,8 @@ void CWindow::Draw()
{
control->Draw();
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draws a rectangle.
@ -896,11 +904,13 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
float dp;
int i;
auto device = m_engine->GetDevice();
dp = 0.5f/256.0f;
if ( icon == 0 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 64.0f/256.0f; // dark blue transparent
uv1.y = 64.0f/256.0f;
@ -916,7 +926,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 1 )
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // white tooltip
uv1.y = 0.0f/256.0f;
@ -930,7 +940,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 2 )
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // yellow
uv1.y = 16.0f/256.0f;
@ -944,7 +954,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 3 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 0.0f/256.0f; // transparent blue bar with yellow upper
uv1.y = 64.0f/256.0f;
@ -963,7 +973,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
dim.x += 100.0f/640.0f;
dim.y += 60.0f/480.0f;
m_engine->SetTexture("textures/objects/human.png");
m_engine->SetUITexture("textures/object/human.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 140.0f/256.0f;
uv1.y = 32.0f/256.0f;
@ -980,7 +990,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
dim.x -= 20.0f/640.0f;
dim.y += 0.0f/480.0f;
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 192.0f/256.0f;
uv1.y = 32.0f/256.0f;
@ -999,7 +1009,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
dim.x -= 20.0f/640.0f;
dim.y -= 20.0f/480.0f;
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f/256.0f;
uv1.y = 0.0f/256.0f;
@ -1035,7 +1045,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
dim.x -= 20.0f/640.0f;
dim.y -= 20.0f/480.0f;
m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetUITexture("textures/interface/button3.png");
uv1.x = 0.0f/256.0f;
uv1.y = 224.0f/256.0f;
uv2.x = 32.0f/256.0f;
@ -1046,7 +1056,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); // dark blue background
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
uv1.x = 224.0f/256.0f;
uv1.y = 224.0f/256.0f;
uv2.x = 249.0f/256.0f;
@ -1118,7 +1128,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 5 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f/256.0f; // transparent green
uv1.y = 160.0f/256.0f;
@ -1132,7 +1142,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 6 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f/256.0f; // transparent red
uv1.y = 176.0f/256.0f;
@ -1146,7 +1156,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 7 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f/256.0f; // transparent blue
uv1.y = 192.0f/256.0f;
@ -1160,7 +1170,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 8 )
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f/256.0f; // opaque orange
uv1.y = 0.0f/256.0f;
@ -1176,7 +1186,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 9 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 32.0f/256.0f; // opaque gray
uv1.y = 32.0f/256.0f;
@ -1196,7 +1206,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 11 )
{
m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f/256.0f; // transparent yellow
uv1.y = 224.0f/256.0f;
@ -1210,7 +1220,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 12 )
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // dirty opaque gray
uv1.y = 128.0f/256.0f;
@ -1226,7 +1236,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 13 )
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 192.0f/256.0f; // dirty opaque blue
uv1.y = 128.0f/256.0f;
@ -1242,7 +1252,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 14 )
{
m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 160.0f/256.0f; // dirty opaque red
uv1.y = 128.0f/256.0f;
@ -1256,6 +1266,8 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
corner.y = 6.0f/480.0f;
DrawIcon(pos, dim, uv1, uv2, corner, 5.0f/256.0f);
}
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
// Draws hatching.
@ -1266,9 +1278,10 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim)
float dp, max, ndim;
bool bStop;
dp = 0.5f/256.0f;
auto device = m_engine->GetDevice();
m_engine->SetTexture("textures/interface/button2.png");
dp = 0.5f/256.0f;
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f/256.0f; // hatching
uv1.y = 208.0f/256.0f;
@ -1299,6 +1312,8 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim)
ppos.x += ddim.x;
}
while ( !bStop );
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
}
void CWindow::SetFocus(CControl* focusControl)