Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

I’ve seemed for an answer for a short time now nonetheless I am unsure if different individuals have encountered my identical downside. I’m attempting to attract a skybox in a clean opengl window, I’ve digicam controls and I can zoom out and see the skybox is there however not being textured accurately/ in any respect. I’ve used code from opengl and I’ve solely tried to implement it into a category.

Skybox.h

#pragma as soon as

#embrace "wrapper_glfw.h"
#embrace <vector>
#embrace <glm/glm.hpp>
#embrace <vector>
#embrace <string>
#embrace "shader_m.h"
#embrace "digicam.h"



class Skybox
{
public:
    Skybox();
    ~Skybox();
  
  void init(GLWrapper *glw);
  void makeSkybox();
  void drawSkybox(Digicam digicam, glm::mat4 projection);
  void setFaces(std::string skyboxPath);
  unsigned int loadCubemap();
 
    personal:
    std::vector<std::string> faces
    {
        "../src/pictures/skybox/default/proper.jpg",
        "../src/pictures/skybox/default/left.jpg",
        "../src/pictures/skybox/default/top.jpg",
        "../src/pictures/skybox/default/backside.jpg",
        "../src/pictures/skybox/default/entrance.jpg",
        "../src/pictures/skybox/default/again.jpg"
    };
    
    unsigned int cubemapTexture;
    unsigned int skyboxVAO, skyboxVBO;
    GLuint skyboxShader;

    //skybox, mannequin, view, projection
    GLuint skyboxID, modelID, viewID, projectionID;
;

};

Skybox.cpp

#embrace "skybox.h"
#embrace <iostream>
#embrace <filesystem>

#outline STB_IMAGE_IMPLEMENTATION
#embrace "stb_image.h"


Skybox::Skybox() 
{
}
Skybox::~Skybox()
{
  glDeleteVertexArrays(1, &skyboxVAO);
  glDeleteBuffers(1, &skyboxVBO);
}

void Skybox::init(GLWrapper *glw)
{
  skyboxShader = glw->LoadShader("shaders/skyboxShader/skybox.vert", "shaders/skyboxShader/skybox.frag");
  skyboxID = glGetUniformLocation(skyboxShader, "skybox");
  projectionID = glGetUniformLocation(skyboxShader, "projection");
  viewID = glGetUniformLocation(skyboxShader, "view");
  glUseProgram(skyboxShader);
}

void Skybox::makeSkybox()
{

float skyboxVertices[] = {
    // positions          
    -5.0f,  5.0f, -5.0f,
    -5.0f, -5.0f, -5.0f,
     5.0f, -5.0f, -5.0f,
     5.0f, -5.0f, -5.0f,
     5.0f,  5.0f, -5.0f,
    -5.0f,  5.0f, -5.0f,

    -5.0f, -5.0f,  5.0f,
    -5.0f, -5.0f, -5.0f,
    -5.0f,  5.0f, -5.0f,
    -5.0f,  5.0f, -5.0f,
    -5.0f,  5.0f,  5.0f,
    -5.0f, -5.0f,  5.0f,

     5.0f, -5.0f, -5.0f,
     5.0f, -5.0f,  5.0f,
     5.0f,  5.0f,  5.0f,
     5.0f,  5.0f,  5.0f,
     5.0f,  5.0f, -5.0f,
     5.0f, -5.0f, -5.0f,

    -5.0f, -5.0f,  5.0f,
    -5.0f,  5.0f,  5.0f,
     5.0f,  5.0f,  5.0f,
     5.0f,  5.0f,  5.0f,
     5.0f, -5.0f,  5.0f,
    -5.0f, -5.0f,  5.0f,

    -5.0f,  5.0f, -5.0f,
     5.0f,  5.0f, -5.0f,
     5.0f,  5.0f,  5.0f,
     5.0f,  5.0f,  5.0f,
    -5.0f,  5.0f,  5.0f,
    -5.0f,  5.0f, -5.0f,

    -5.0f, -5.0f, -5.0f,
    -5.0f, -5.0f,  5.0f,
     5.0f, -5.0f, -5.0f,
     5.0f, -5.0f, -5.0f,
    -5.0f, -5.0f,  5.0f,
     5.0f, -5.0f,  5.0f
}; 
  
  // skybox VAO
  glGenVertexArrays(1, &skyboxVAO);
  glGenBuffers(1, &skyboxVBO);
  glBindVertexArray(skyboxVAO);
  glBindBuffer(GL_ARRAY_BUFFER, skyboxVBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW);
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); 
    
  cubemapTexture = loadCubemap();

  // glUniform1ui(skyboxID, 0);
  glGetError();
}

void Skybox::drawSkybox(Digicam digicam, glm::mat4 projection)
 GL_DEPTH_BUFFER_BIT);

  // draw skybox as final
  glDepthFunc(GL_LEQUAL);  // change depth operate so depth check passes when values are equal to depth buffer's content material
 
  glUniformMatrix4fv(viewID, 1, GL_FALSE, &digicam.getView()[0][0]);
    glUniformMatrix4fv(projectionID, 1, GL_FALSE, &projection[0][0]); 
 
  // skybox dice
  glBindVertexArray(skyboxVAO);
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
  glDrawArrays(GL_TRIANGLES, 0, 36);
  glBindVertexArray(0);
  glDepthFunc(GL_LESS); // set depth operate again to default
  glUniform1ui(skyboxID, cubemapTexture);
  glGetError();




unsigned int Skybox::loadCubemap()
{
    unsigned int textureID;
    glGenTextures(1, &textureID);
    glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);

    int width, top, nrChannels;
    for (unsigned int i = 0; i < faces.dimension(); i++)
    {
        unsigned char *information = stbi_load(faces[i].c_str(), &width, &top, &nrChannels, 0);
        if (information)
        {
            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, top, 0, GL_RGB, GL_UNSIGNED_BYTE, information);
            stbi_image_free(information);
        }
        else
        {
            std::cout << "Cubemap texture did not load at path: " << faces[i] << std::endl;
            stbi_image_free(information);
        }
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

    return textureID;
}

I’m utilizing an M2 Macbook and I should not have a shader class like I’ve seen lots of people use, I implement my shaders the best way my lecturer has completed so. I hope I’ve offered sufficient and thanks upfront if anybody will help!

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *