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