I am attempting to render a skybox onto level geometry objects. I am having difficulty with the texture mapping coordinates for the cube. Basically the tex coord should just be the vector between the camera positions and vertex positions, both in global space.
vert:
void main(void) {
gl_Position = ftransform();
gl_TexCoord[0].xyz = ???;
gl_FrontColor=gl_Color;
}
frag:
uniform samplerCube cubemap;
void main(void) {
gl_FragColor = textureCube(cubemap,gl_TexCoord[0].xyz) * gl_Color;
}
I actually just want something that duplicates this FFP code, but in GLSL:
glenable GL_TEXTURE_GEN_S
glenable GL_TEXTURE_GEN_T
glenable GL_TEXTURE_GEN_R
glTexGeni GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR
glTexGeni GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR
glTexGeni GL_R,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR
gltexgenfv GL_S,GL_OBJECT_PLANE,[1.0,0.0,0.0,-camera.mat.grid[3,0]]
gltexgenfv GL_T,GL_OBJECT_PLANE,[0.0,1.0,0.0,-camera.mat.grid[3,1]]
gltexgenfv GL_R,GL_OBJECT_PLANE,[0.0,0.0,1.0,-camera.mat.grid[3,2]]
Thanks in advance.