I am trying to display a cube with 6 bitmaps in order to achieve the skybox effect. My problem is that one texture is displayed on each face of the cube. I checked gDEBugger, in cubic texture memory I only have one image (since I am trying to load six images).
Code coded texture:
bool Texture::LoadCubicTexture(vector<string> filenameTable) { glGenTextures(1,&texID); glBindTexture(GL_TEXTURE_CUBE_MAP,texID); 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_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); int i = 0; vector<string>::iterator vsit;
VS:
#version 330 core in vec3 vVertexPos; in vec3 vertexUV; out vec3 vCoords; uniform mat4 MVP; void main() { vCoords = normalize(vertexUV); gl_Position = MVP * vec4(vVertexPos,1.0); }
FS:
#version 330 core in vec3 vCoords; uniform samplerCube cube; out vec4 vFragColor; void main() { vFragColor = texture(cube, vCoords); }
Obj file:
# Blender v2.62 (sub 0) OBJ File: 'skybox.blend'
My questions:
- Are the methods that I use in this code look normal?
- How do textures compare for a cube (in GL_TEXTURE_CUBE_MAP texture) when there are only 2 UVs? (I mean overall.)
- Is it possible to use automatic UV generation in this situation (I have to make a lot of changes in the shader)?
- Can anyone suggest me where I can find the problem? (with some probability; buffers, shaders, grids, just a suggestion)?
[Edit]: I tried hard-coded vertices and uv in a separate source file, and I have the same problem - one texture for all faces of the cube. Hard-coded data seems correct:
#include "TestCube.h" vector<vec3> GetTestCubeVertices() { vector<vec3> vrtx; const float xd = 1.0f; const float yd = 1.0f; const float zd = 1.0f; const float testCubeVertices[] = { -xd, -yd, zd, xd, -yd, zd, -xd, yd, zd, // ABE xd, -yd, zd, -xd, yd, zd, xd, yd, zd, // BEF xd, -yd, zd, xd, -yd, -zd, xd, yd, zd, // BCF xd, -yd, -zd, xd, yd, zd, xd, yd, -zd, // CFG xd, -yd, -zd, -xd, -yd, -zd, xd, yd, -zd, // CDG -xd, -yd, -zd, xd, yd, -zd, -xd, yd, -zd, // DGH -xd, -yd, -zd, -xd, -yd, zd, -xd, yd, -zd, // DAH -xd, -yd, zd, -xd, yd, -zd, -xd, yd, zd, // AHE -xd, yd, zd, xd, yd, zd, -xd, yd, -zd, // EFH xd, yd, zd, -xd, yd, -zd, xd, yd, -zd, // FHG xd, -yd, zd, -xd, -yd, zd, xd, -yd, -zd, // BAC -xd, -yd, zd, xd, -yd, -zd, -xd, -yd, -zd, // ACD }; for(int i=0;i<108;i=i+3) vrtx.push_back(vec3(testCubeVertices[i],testCubeVertices[i+1],testCubeVertices[i+2])); return vrtx; } vector<vec2> GetTestCubeUVs() { vector<vec2> uv; const float testCubeUV[] = { 0,0, 1,0, 0,1, // ABE 1,0, 0,1, 1,1, // BEF 0,0, 1,0, 0,1, // BCF 1,0, 0,1, 1,1, // CFG 0,0, 1,0, 0,1, // CDG 1,0, 0,1, 1,1, // DGH 0,0, 1,0, 0,1, // DAH 1,0, 0,1, 1,1, // AHE 0,0, 1,0, 0,1, // EFH 1,0, 0,1, 1,1, // FHG 0,0, 1,0, 0,1, // BAC 1,0, 0,1, 1,1, // ACD }; for(int i=0;i<72;i=i+2) uv.push_back(vec2(testCubeUV[i],testCubeUV[i+1])); return uv; }
Two more elementary questions, I have an OpenGL call:
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);
- I understand that OpenGL automatically processes the r coordinate, because to have information in the constant GL_TEXTURE_CUBE_MAP_POSITIVE_X for glTexImage2D ()?
- Is there any modification of the r coordinate in Vertex Shader?
The results screen below will appear (writing to the depth buffer is disabled and no settings are specified, but this is not my problem now):

I noticed that the duplicated texture is the fifth loaded texture (GL_TEXTURE_CUBE_MAP_POSITIVE_Z).

[LAST EDIT.]: There was a problem with the UV coordinates in Skybox VS (the r coordinate has one value), Skybox VS should be as shown below:
void main() { vCoords = normalize(vVertexPos); gl_Position = MVP * vec4(vVertexPos,1.0); }
There were several issues with Skybox technology, but they were not the subject of this stream. Solvable.