1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| void CubeMapMaterial::init(const std::string &path)
{
QOpenGLFunctions_4_3_Core *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_3_Core>();
GLfloat vertices[] = {
// Positions
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f
};
m_vao.create();
m_vbo = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
m_vbo->create();
if (m_vao.isCreated())
{
m_vao.bind();
m_vbo->bind();
m_vbo->allocate(vertices, sizeof(vertices));
m_vbo->setUsagePattern(QOpenGLBuffer::StaticDraw);
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
f->glEnableVertexAttribArray(0);
m_vao.release();
}
QImage sidePosX = QImage(QString::fromStdString(path)+ "/xpos.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
QImage sidePosY = QImage(QString::fromStdString(path)+ "/ypos.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
QImage sidePosZ = QImage(QString::fromStdString(path)+ "/zpos.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
QImage sideNegX = QImage(QString::fromStdString(path)+ "/xneg.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
QImage sideNegY = QImage(QString::fromStdString(path)+ "/yneg.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
QImage sideNegZ = QImage(QString::fromStdString(path)+ "/zneg.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
m_textureCubeMap = new QOpenGLTexture(QOpenGLTexture::TargetCubeMap);
m_textureCubeMap->create();
m_textureCubeMap->bind();
m_textureCubeMap->setSize(sidePosX.width(), sidePosX.height(), sidePosX.depth());
m_textureCubeMap->setFormat(QOpenGLTexture::RGBA8_UNorm);
m_textureCubeMap->allocateStorage();
m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapPositiveX, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sidePosX.constBits(), 0);
m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapPositiveY, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sidePosY.constBits(), 0);
m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapPositiveZ, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sidePosZ.constBits(), 0);
m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapNegativeX, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sideNegX.constBits(), 0);
m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapNegativeY, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sideNegY.constBits(), 0);
m_textureCubeMap->setData(0, 0, QOpenGLTexture::CubeMapNegativeZ, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, (const void*)sideNegZ.constBits(), 0);
m_textureCubeMap->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear);
m_textureCubeMap->setWrapMode(QOpenGLTexture::DirectionS, QOpenGLTexture::ClampToEdge);
m_textureCubeMap->setWrapMode(QOpenGLTexture::DirectionT, QOpenGLTexture::ClampToEdge);
m_textureCubeMap->setWrapMode(QOpenGLTexture::DirectionR, QOpenGLTexture::ClampToEdge);
m_textureCubeMap->release();
} |
Partager