Generate a skybox with openGL 4

Hi,

I need to create à skyBox with a version of OpenGL later than 3.3. I have tried to make ofxCubeMap and ofxSkyBox work with this version to no avail. Is there a simple way to make a skybox or to use cube mapping?

Alternatively I tried making this tutorial works with ofImages but I couldn’t: Cube Maps: Skyboxes and Environment Mapping - Anton’s OpenGL 4 Tutorials (antongerdelan.net)

Any help would be greatly appreciated.

Hi @ludovi1

What are the errors you are getting from ofxCubeMap?

Another reference

ofCubeMap is being integrated into OF and can be tested with the OF nightly builds ( at the bottom of the downloads page).
It only implements an equi rect texture to cube map, but might be helpful as a reference.

Thanks for the reference, ill get into it.

For ofxCubemaps, drawing a skybox with the function drawSkybox breaks the camera and give out the message: [warning] ofMatrixStack: clearStacks(): found 1extra modelview matrices on the stack, did you forget to pop somewhere?

Ive been trying to make the skybox following the OpenGL tutorial provided by @NickHardeman , but once again I fail to draw a skybox. Here’s my code if anyone can tell me what I’m doing wrong.

void Renderer::setup()
{
ofEnableDepthTest();

shader.load("skybox");
vecImage.push_back("earth.jpg");
vecImage.push_back("earth.jpg");
vecImage.push_back("earth.jpg");
vecImage.push_back("earth.jpg");
vecImage.push_back("earth.jpg");
vecImage.push_back("earth.jpg");
cubemapTexture = cubemap(vecImage);

}

void Renderer::draw()
{
camera.begin();

glDepthMask(GL_FALSE);
shader.begin();
// ... set view and projection matrix
glBindVertexArray(vao);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
glDrawArrays(GL_TRIANGLES, 0, 36);
glDepthMask(GL_TRUE);
shader.end();
camera.end();

}

unsigned int Renderer::loadCubemap(vectorstd::string faces)
{
unsigned int textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);

int width, height, nrChannels;
for (unsigned int i = 0; i < faces.size(); i++)
{
    unsigned char* data = stbi_load(faces[i].c_str(), &width, &height, &nrChannels, 0);
    if (data)
    {
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
            0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data
        );
        stbi_image_free(data);
    }
    else
    {
        std::cout << "Cubemap tex failed to load at path: " << faces[i] << std::endl;
        stbi_image_free(data);
    }
}
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;

}

void Renderer::makeSkyboxCube()
{
float points[] = {
-10.0f, 10.0f, -10.0f,
-10.0f, -10.0f, -10.0f,
10.0f, -10.0f, -10.0f,
10.0f, -10.0f, -10.0f,
10.0f, 10.0f, -10.0f,
-10.0f, 10.0f, -10.0f,

-10.0f, -10.0f, 10.0f,
-10.0f, -10.0f, -10.0f,
-10.0f, 10.0f, -10.0f,
-10.0f, 10.0f, -10.0f,
-10.0f, 10.0f, 10.0f,
-10.0f, -10.0f, 10.0f,

10.0f, -10.0f, -10.0f,
10.0f, -10.0f, 10.0f,
10.0f, 10.0f, 10.0f,
10.0f, 10.0f, 10.0f,
10.0f, 10.0f, -10.0f,
10.0f, -10.0f, -10.0f,

-10.0f, -10.0f, 10.0f,
-10.0f, 10.0f, 10.0f,
10.0f, 10.0f, 10.0f,
10.0f, 10.0f, 10.0f,
10.0f, -10.0f, 10.0f,
-10.0f, -10.0f, 10.0f,

-10.0f, 10.0f, -10.0f,
10.0f, 10.0f, -10.0f,
10.0f, 10.0f, 10.0f,
10.0f, 10.0f, 10.0f,
-10.0f, 10.0f, 10.0f,
-10.0f, 10.0f, -10.0f,

-10.0f, -10.0f, -10.0f,
-10.0f, -10.0f, 10.0f,
10.0f, -10.0f, -10.0f,
10.0f, -10.0f, -10.0f,
-10.0f, -10.0f, 10.0f,
10.0f, -10.0f, 10.0f
};

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 3 * 36 * sizeof(float), &points, GL_STATIC_DRAW);

glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);

}

I also recieve two error while running the program.
[ error ] ofAppGLFWWindow: 65544: WGL: Failed to make context current: The requested transformation operation is not supported.
[ error ] ofAppGLFWWindow: 65544: WGL: Failed to make context current: The handle is invalid.