mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
feat(skin manager): add elytra preview
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -18,9 +18,16 @@
|
||||
*/
|
||||
|
||||
#include "ui/dialogs/skins/draw/Scene.h"
|
||||
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QOpenGLTexture>
|
||||
#include <QOpenGLWindow>
|
||||
|
||||
namespace opengl {
|
||||
Scene::Scene(const QImage& skin, bool slim, const QImage& cape) : m_slim(slim), m_capeVisible(!cape.isNull())
|
||||
Scene::Scene(const QImage& skin, bool slim, const QImage& cape) : QOpenGLFunctions(), m_slim(slim), m_capeVisible(!cape.isNull())
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
m_staticComponents = {
|
||||
// head
|
||||
new opengl::BoxGeometry(QVector3D(8, 8, 8), QVector3D(0, 4, 0), QPoint(0, 0), QVector3D(8, 8, 8)),
|
||||
@ -57,6 +64,19 @@ Scene::Scene(const QImage& skin, bool slim, const QImage& cape) : m_slim(slim),
|
||||
m_cape->rotate(10.8, QVector3D(1, 0, 0));
|
||||
m_cape->rotate(180, QVector3D(0, 1, 0));
|
||||
|
||||
auto leftWing =
|
||||
new opengl::BoxGeometry(QVector3D(12, 22, 4), QVector3D(0, -13, -2), QPoint(22, 0), QVector3D(10, 20, 2), QSize(64, 32));
|
||||
leftWing->rotate(15, QVector3D(1, 0, 0));
|
||||
leftWing->rotate(15, QVector3D(0, 0, 1));
|
||||
leftWing->rotate(1, QVector3D(1, 0, 0));
|
||||
auto rightWing =
|
||||
new opengl::BoxGeometry(QVector3D(12, 22, 4), QVector3D(0, -13, -2), QPoint(22, 0), QVector3D(10, 20, 2), QSize(64, 32));
|
||||
rightWing->scale(QVector3D(-1, 1, 1));
|
||||
rightWing->rotate(15, QVector3D(1, 0, 0));
|
||||
rightWing->rotate(15, QVector3D(0, 0, 1));
|
||||
rightWing->rotate(1, QVector3D(1, 0, 0));
|
||||
m_elytra << leftWing << rightWing;
|
||||
|
||||
// texture init
|
||||
m_skinTexture = new QOpenGLTexture(skin.mirrored());
|
||||
m_skinTexture->setMinificationFilter(QOpenGLTexture::Nearest);
|
||||
@ -68,7 +88,7 @@ Scene::Scene(const QImage& skin, bool slim, const QImage& cape) : m_slim(slim),
|
||||
}
|
||||
Scene::~Scene()
|
||||
{
|
||||
for (auto array : { m_staticComponents, m_normalArms, m_slimArms }) {
|
||||
for (auto array : { m_staticComponents, m_normalArms, m_slimArms, m_elytra }) {
|
||||
for (auto g : array) {
|
||||
delete g;
|
||||
}
|
||||
@ -95,7 +115,15 @@ void Scene::draw(QOpenGLShaderProgram* program)
|
||||
if (m_capeVisible) {
|
||||
m_capeTexture->bind();
|
||||
program->setUniformValue("texture", 0);
|
||||
m_cape->draw(program);
|
||||
if (!m_elytraVisible) {
|
||||
m_cape->draw(program);
|
||||
} else {
|
||||
glDisable(GL_CULL_FACE);
|
||||
for (auto e : m_elytra) {
|
||||
e->draw(program);
|
||||
}
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
m_capeTexture->release();
|
||||
}
|
||||
}
|
||||
@ -131,4 +159,8 @@ void Scene::setCapeVisible(bool visible)
|
||||
{
|
||||
m_capeVisible = visible;
|
||||
}
|
||||
void Scene::setElytraVisible(bool elytraVisible)
|
||||
{
|
||||
m_elytraVisible = elytraVisible;
|
||||
}
|
||||
} // namespace opengl
|
Reference in New Issue
Block a user