Cubemap texcoords for skybox?

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.

The equivalent vertex shader code for that glTexGen setup is:

gl_TexCoord[0].s = dot(gl_Vertex, gl_ObjectPlaneS[0]);
gl_TexCoord[0].t = dot(gl_Vertex, gl_ObjectPlaneT[0]);
gl_TexCoord[0].p = dot(gl_Vertex, gl_ObjectPlaneR[0]);
gl_TexCoord[0].q = dot(gl_Vertex, gl_ObjectPlaneQ[0]);

Thanks.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.