mirror of
https://github.com/edubart/otclient.git
synced 2025-10-17 13:03:27 +02:00
fix outfit problems
This commit is contained in:
@@ -60,8 +60,8 @@ void Painter::drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer&
|
||||
return;
|
||||
|
||||
program->setProjectionMatrix(m_projectionMatrix);
|
||||
program->setOpacity(m_currentOpacity);
|
||||
program->setColor(m_currentColor);
|
||||
program->setOpacity(m_opacity);
|
||||
program->setColor(m_color);
|
||||
program->draw(coordsBuffer, drawMode);
|
||||
}
|
||||
|
||||
@@ -141,4 +141,32 @@ void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
||||
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
|
||||
break;
|
||||
}
|
||||
m_compostionMode = compositionMode;
|
||||
}
|
||||
|
||||
void Painter::saveAndResetState()
|
||||
{
|
||||
m_oldCustomProgram = m_customProgram;
|
||||
m_oldProjectionMatrix = m_projectionMatrix;
|
||||
m_oldColor = m_color;
|
||||
m_oldOpacity = m_opacity;
|
||||
m_oldCompostionMode = m_compostionMode;
|
||||
|
||||
releaseCustomProgram();
|
||||
setColor(Fw::white);
|
||||
setOpacity(1);
|
||||
setCompositionMode(CompositionMode_Normal);
|
||||
}
|
||||
|
||||
void Painter::restoreSavedState()
|
||||
{
|
||||
setCustomProgram(m_oldCustomProgram);
|
||||
setColor(m_oldColor);
|
||||
setOpacity(m_oldOpacity);
|
||||
setCompositionMode(m_oldCompostionMode);
|
||||
|
||||
m_oldCustomProgram = nullptr;
|
||||
m_oldColor = Fw::white;
|
||||
m_oldOpacity = 1;
|
||||
m_oldCompostionMode = CompositionMode_Normal;
|
||||
}
|
||||
|
@@ -50,11 +50,11 @@ public:
|
||||
void drawFilledRect(const Rect& dest);
|
||||
void drawBoundingRect(const Rect& dest, int innerLineWidth = 1);
|
||||
|
||||
void setColor(const Color& color) { m_currentColor = color; }
|
||||
Color getColor() { return m_currentColor; }
|
||||
void setColor(const Color& color) { m_color = color; }
|
||||
Color getColor() { return m_color; }
|
||||
|
||||
void setOpacity(float opacity) { m_currentOpacity = opacity; }
|
||||
float getOpacity() { return m_currentOpacity; }
|
||||
void setOpacity(float opacity) { m_opacity = opacity; }
|
||||
float getOpacity() { return m_opacity; }
|
||||
|
||||
void setCustomProgram(PainterShaderProgramPtr program);
|
||||
void releaseCustomProgram() { m_customProgram = nullptr; }
|
||||
@@ -64,14 +64,24 @@ public:
|
||||
void setProjectionMatrix(const Matrix3& projectionMatrix) { m_projectionMatrix = projectionMatrix; }
|
||||
Matrix3 getProjectionMatrix() { return m_projectionMatrix; }
|
||||
|
||||
void saveAndResetState();
|
||||
void restoreSavedState();
|
||||
|
||||
private:
|
||||
PainterShaderProgramPtr m_drawTexturedProgram;
|
||||
PainterShaderProgramPtr m_drawSolidColorProgram;
|
||||
PainterShaderProgramPtr m_customProgram;
|
||||
Matrix3 m_projectionMatrix;
|
||||
Color m_currentColor;
|
||||
float m_currentOpacity;
|
||||
Color m_color;
|
||||
float m_opacity;
|
||||
CompositionMode m_compostionMode;
|
||||
CoordsBuffer m_coordsBuffer;
|
||||
|
||||
PainterShaderProgramPtr m_oldCustomProgram;
|
||||
Matrix3 m_oldProjectionMatrix;
|
||||
Color m_oldColor;
|
||||
float m_oldOpacity;
|
||||
CompositionMode m_oldCompostionMode;
|
||||
};
|
||||
|
||||
extern Painter g_painter;
|
||||
|
@@ -26,6 +26,11 @@
|
||||
#include "texturemanager.h"
|
||||
#include <framework/core/clock.h>
|
||||
|
||||
PainterShaderProgram::PainterShaderProgram()
|
||||
{
|
||||
m_textures.fill(std::make_tuple(-1, 0));
|
||||
}
|
||||
|
||||
bool PainterShaderProgram::link()
|
||||
{
|
||||
bindAttributeLocation(VERTEX_COORDS_ATTR, "vertexCoord");
|
||||
@@ -63,12 +68,9 @@ void PainterShaderProgram::setOpacity(float opacity)
|
||||
|
||||
void PainterShaderProgram::setUniformTexture(int location, const TexturePtr& texture, int index)
|
||||
{
|
||||
if(index > 0)
|
||||
glActiveTexture(GL_TEXTURE0 + index);
|
||||
glBindTexture(GL_TEXTURE_2D, texture ? texture->getId() : 0);
|
||||
if(index > 0)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
setUniformValue(location, index);
|
||||
assert(index >= 0 && index <= 1);
|
||||
|
||||
m_textures[index] = std::make_tuple(location, texture ? texture->getId() : 0);
|
||||
}
|
||||
|
||||
void PainterShaderProgram::setTexture(const TexturePtr& texture)
|
||||
@@ -112,6 +114,18 @@ void PainterShaderProgram::draw(const CoordsBuffer& coordsBuffer, DrawMode drawM
|
||||
mustDisableTexCoordsArray = true;
|
||||
}
|
||||
|
||||
for(int i=0;i<(int)m_textures.size();++i) {
|
||||
int location = std::get<0>(m_textures[i]);
|
||||
if(location == -1)
|
||||
break;
|
||||
int id = std::get<1>(m_textures[i]);
|
||||
setUniformValue(location, i);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0+i);
|
||||
glBindTexture(GL_TEXTURE_2D, id);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
glDrawArrays(drawMode, 0, numVertices);
|
||||
|
||||
if(mustDisableVertexArray)
|
||||
|
@@ -45,6 +45,8 @@ public:
|
||||
TriangleStrip = GL_TRIANGLE_STRIP
|
||||
};
|
||||
|
||||
PainterShaderProgram();
|
||||
|
||||
bool link();
|
||||
|
||||
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
||||
@@ -57,6 +59,7 @@ public:
|
||||
private:
|
||||
DrawMode m_drawMode;
|
||||
Timer m_startTimer;
|
||||
std::array<std::tuple<int, int>, 4> m_textures;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -122,8 +122,10 @@ std::vector<uint8> Texture::getPixels()
|
||||
FrameBufferPtr fb(new FrameBuffer(m_size));
|
||||
std::vector<uint8> pixels(m_size.area()*4, 0);
|
||||
fb->bind();
|
||||
g_painter.saveAndResetState();
|
||||
g_painter.drawTexturedRect(Rect(0,0,m_size), shared_from_this());
|
||||
glReadPixels(0, 0, m_size.width(), m_size.height(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
|
||||
g_painter.restoreSavedState();
|
||||
fb->release();
|
||||
return pixels;
|
||||
}
|
||||
|
Reference in New Issue
Block a user