Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Skybox.h"
- #include <cmath>
- #include <fstream>
- #include <iostream>
- #include <QMessageBox>
- #include "Model.h"
- using namespace std;
- Skybox::Skybox() {
- // the position buffer
- positionBuffer = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
- positionBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
- positionBuffer.create();
- positionBuffer.bind();
- positionBuffer.allocate(&positions[0],
- positions.size() * sizeof(QVector3D));
- positionBuffer.release();
- // An dieser Stelle wird wieder die nullte Texturebene genutzt.
- //glActiveTexture(GL_TEXTURE0);
- skyImages.resize(6);
- skyImages[0] = std::unique_ptr<QImage>(new QImage(
- QString("skybox/right.png")));
- skyImages[1] =
- std::unique_ptr<QImage>(new QImage(QString("skybox/back.png")));
- skyImages[2] = std::unique_ptr<QImage>(
- new QImage(QString("skybox/down.png")));
- skyImages[3] = std::unique_ptr<QImage>(new QImage(
- QString("skybox/front.png")));
- skyImages[4] = std::unique_ptr<QImage>(
- new QImage(QString("skybox/left.png")));
- skyImages[5] = std::unique_ptr<QImage>(new QImage(QString("skybox/up.png")));
- texture = std::make_shared<QOpenGLTexture>(QOpenGLTexture::TargetCubeMap);
- texture->create();
- texture->setSize(skyImages[0]->width(), skyImages[0]->height(), skyImages[0]->depth());
- texture->setFormat(QOpenGLTexture::RGBA8U);
- texture->allocateStorage();
- for (size_t i = 0; i < faces.size(); i++) {
- texture->setData(0, 0, faces[i], QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, skyImages[i]->constBits());
- }
- texture->setWrapMode(QOpenGLTexture::ClampToEdge);
- texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
- texture->setMagnificationFilter(QOpenGLTexture::LinearMipMapLinear);
- texture->generateMipMaps();
- }
- void Skybox::render(std::shared_ptr<QOpenGLShaderProgram> program, QVector3D cameraPosition) {
- int positionAttributeID = program->attributeLocation("position");
- program->enableAttributeArray(positionAttributeID);
- positionBuffer = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
- positionBuffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
- positionBuffer.create();
- positionBuffer.bind();
- positionBuffer.allocate(positions.data(), positions.size() * sizeof(QVector3D));
- //positionBuffer.bind();
- program->setAttributeBuffer(positionAttributeID, GL_FLOAT, 0, 3);
- positionBuffer.release();
- //glDrawArrays(GL_TRIANGLES, 0, 3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement