5
\$\begingroup\$

I am sorry if this is trivial, but I got into OpenGL just very very recently.

I am trying to render skybox (with cubemaps) and this is what I have done:

  • Created a VBO with vertices positions (36 of them +- 10.0f, +- 10.0f, +-10.0f ). Using gDebugger I know the data are loaded correctly.

    glGenBuffers(1, &cubeMap.positionBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, cubeMap.positionBuffer);
    glBufferData(GL_ARRAY_BUFFER, 3*36*sizeof(float), &cubePoints[0], GL_STATIC_DRAW);
    
  • I create a texture, bound to GL_TEXTURE_CUBE_MAP, and load (using stbi) each face image to the right side. Again gDebugger tells me that the texture is loaded correctly as it shows with all the faces in the right place.

    glGenTextures(1, &textureID);
    glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
    glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    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);
    
    --- for each image (looping through faces with index i) --- 
    data = stbi_load_from_file(file,&width,&height,&comp,0);
    // determine format based on comp 
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, &data[0]);
    
  • In my draw loop I draw the cube map as:

    glEnableVertexAttribArray(0);
    
    cubeMapProgram.use();  
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_CUBE_MAP, textureID );
    setUniform1i("cubeTexture",0); // my wrapper on the glUniform (it is tested)
    
    glBindBuffer(GL_ARRAY_BUFFER, cubeMap.positionBuffer); // the VBO previously filled
    vertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
    
    glm::mat4 pvMatrix = perspectiveMatrix * viewMatrix; // They are fine
    setUniformMatrix4fv("pvMatrix", 1, &(pvMatrix[0][0]));
    
    glDepthMask(GL_FALSE);
    glDrawArrays(GL_TRIANGLES, 0, 36);
    glDepthMask(GL_TRUE);
    

Where the shader program cubeMapProgram is very simple:

vertex shader

#version 330

layout(location=0) in vec3 aVP;
uniform mat4 pvMatrix;
out vec3 vUV;

void main(void){
    gl_Position = pvMatrix * vec4(aVP,1.0);
    vUV = aVP;
}

fragment shader

#version 330

in vec3 vUV;
out vec4 color;
uniform samplerCube cubeTexture;


void main(void){
    color = texture(cubeTexture, vUV);
}

All I got with this is a black screen. Again according to gDebugger the right VBO is correctly filled and bound when drawing and the cubeMap is loaded correctly. Am I missing something completely stupid?

Thank you

\$\endgroup\$
  • \$\begingroup\$ Did you provide texture coordinates for your cube? for debugging purposes set the shader to output fixed color if it appears on screen then there is sth wrong with texturing, if you didnt see anything there is a bigger issue in your code. \$\endgroup\$ – concept3d Oct 1 '14 at 10:54
  • \$\begingroup\$ Yup I tried with a fixed white, still nothing showing. Do you think the issue may be somewhere else? \$\endgroup\$ – gufranc Oct 1 '14 at 11:03
  • \$\begingroup\$ Did you provide texture coordinates for your cube? \$\endgroup\$ – concept3d Oct 1 '14 at 11:33
  • \$\begingroup\$ I derive them from vertex positions \$\endgroup\$ – gufranc Oct 1 '14 at 13:35
  • 1
    \$\begingroup\$ Check for openGL errors. \$\endgroup\$ – concept3d Oct 1 '14 at 13:37
1
\$\begingroup\$

I didn't see any call to SwapBuffers after your draw commands. That's definitely a problem that will cause a blank screen.

As long as there are no OpenGL errors, it's the only problem.

\$\endgroup\$
-1
\$\begingroup\$

I use XNA, so even looking at GL code makes my head hurt. On top of that, your variable names do not indicate anything obvious. How does "aVP" represent a worldCoordinate? Anyway...

I can't tell if you've done this in the posted code, or elsewhere:
Since you are inside the skybox, all of its triangles are counter-clockwise from the camera's perspective so you probably need to reverse culling when rendering it; leave everything else the same and/or put it back like you had it.

\$\endgroup\$
  • 2
    \$\begingroup\$ This answer addresses the question too indirectly, and rants too much. The culling may be relevant, but since it's speculative it is more suitable as a comment. \$\endgroup\$ – Seth Battin Mar 9 '15 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.