Skip to content

Commit

Permalink
Fix colors of StelPainter-colored renders
Browse files Browse the repository at this point in the history
  • Loading branch information
10110111 committed Apr 8, 2023
1 parent 18e47d8 commit 60c4ab0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/StelPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "StelLocaleMgr.hpp"
#include "StelProjector.hpp"
#include "StelProjectorClasses.hpp"
#include "StelSRGB.hpp"
#include "StelUtils.hpp"
#include "StelTextureMgr.hpp"
#include "SaturationShader.hpp"
Expand Down Expand Up @@ -766,7 +767,7 @@ void StelPainter::drawText(float x, float y, const QString& str, float angleDeg,
QFont tmpFont = currentFont;
tmpFont.setPixelSize(currentFont.pixelSize()*static_cast<int>(static_cast<float>(prj->getDevicePixelsPerPixel())*StelApp::getInstance().getGlobalScalingRatio()));
painter.setFont(tmpFont);
painter.setPen(currentColor.toQColor());
painter.setPen(srgbToLinear(currentColor).toQColor());

float scaleRatio = StelApp::getInstance().getGlobalScalingRatio();
xshift*=scaleRatio;
Expand Down Expand Up @@ -2441,7 +2442,7 @@ void StelPainter::drawFromArray(DrawingMode mode, int count, int offset, bool do
pr->setAttributeBuffer(wideLineShaderVars.vertex, projectedVertexArray.type, 0, projectedVertexArray.size);
pr->enableAttributeArray(wideLineShaderVars.vertex);
pr->setUniformValue(wideLineShaderVars.projectionMatrix, qMat);
pr->setUniformValue(wideLineShaderVars.color, currentColor[0], currentColor[1], currentColor[2], currentColor[3]);
pr->setUniformValue(wideLineShaderVars.color, srgbToLinear(currentColor).toQVector());
pr->setUniformValue(wideLineShaderVars.lineWidth, glState.lineWidth);
GLint viewport[4] = {};
glGetIntegerv(GL_VIEWPORT, viewport);
Expand All @@ -2456,7 +2457,7 @@ void StelPainter::drawFromArray(DrawingMode mode, int count, int offset, bool do
pr->setAttributeBuffer(basicShaderVars.vertex, projectedVertexArray.type, 0, projectedVertexArray.size);
pr->enableAttributeArray(basicShaderVars.vertex);
pr->setUniformValue(basicShaderVars.projectionMatrix, qMat);
pr->setUniformValue(basicShaderVars.color, currentColor[0], currentColor[1], currentColor[2], currentColor[3]);
pr->setUniformValue(basicShaderVars.color, srgbToLinear(currentColor).toQVector());
}
}
else if (texCoordArray.enabled && !colorArray.enabled && !normalArray.enabled && !wideLineMode)
Expand All @@ -2476,7 +2477,7 @@ void StelPainter::drawFromArray(DrawingMode mode, int count, int offset, bool do
pr->setAttributeBuffer(texturesShaderVars.vertex, projectedVertexArray.type, 0, projectedVertexArray.size);
pr->enableAttributeArray(texturesShaderVars.vertex);
pr->setUniformValue(texturesShaderVars.projectionMatrix, qMat);
pr->setUniformValue(texturesShaderVars.texColor, currentColor[0], currentColor[1], currentColor[2], currentColor[3]);
pr->setUniformValue(texturesShaderVars.texColor, srgbToLinear(currentColor).toQVector());
pr->setAttributeBuffer(texturesShaderVars.texCoord, texCoordArray.type, texCoordDataOffset, texCoordArray.size);
pr->enableAttributeArray(texturesShaderVars.texCoord);
//pr->setUniformValue(texturesShaderVars.texture, 0); // use texture unit 0
Expand Down
9 changes: 9 additions & 0 deletions src/core/StelSRGB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ F srgbToLinear(const F c)
: c / F(12.92);
}

template<typename F>
Vector4<F> srgbToLinear(const Vector4<F>& srgba)
{
return {srgbToLinear(srgba[0]),
srgbToLinear(srgba[1]),
srgbToLinear(srgba[2]),
srgba[3]};
}

template<typename F>
Vector3<F> srgbToLinear(const Vector3<F>& srgb)
{
Expand Down
13 changes: 13 additions & 0 deletions src/core/VecMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,19 @@ template<> QColor Vec4f::toQColor() const
return QColor::fromRgbF(static_cast<qreal>(v[0]), static_cast<qreal>(v[1]), static_cast<qreal>(v[2]), static_cast<qreal>(v[3]));
}

template<> QVector4D Vec4f::toQVector() const
{
return QVector4D(v[0], v[1], v[2], v[3]);
}

template<> QVector4D Vec4d::toQVector() const
{
return QVector4D(static_cast<float>(v[0]),
static_cast<float>(v[1]),
static_cast<float>(v[2]),
static_cast<float>(v[3]));
}

template<> QColor Vec4d::toQColor() const
{
return QColor::fromRgbF(v[0], v[1], v[2], v[3]);
Expand Down
2 changes: 2 additions & 0 deletions src/core/VecMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ template<class T> class Vector4
QString toStr() const;
//! Convert to a QColor.
QColor toQColor() const;
//! Convert to a QVector3D.
QVector4D toQVector() const;

T v[4]; // The 4 values
};
Expand Down

0 comments on commit 60c4ab0

Please sign in to comment.