openGL之API学习(二零一)glTexGen
Posted hankern
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openGL之API学习(二零一)glTexGen相关的知识,希望对你有一定的参考价值。
用来计算纹理坐标。
opengl es 3.2和opengl 4.5都不再支持此函数,不知道具体从哪个版本开始不支持的。(This article describes legacy OpenGL APIs that have been removed from core OpenGL 3.1 and above (they are only deprecated in OpenGL 3.0). It is recommended that you not use this functionality in your programs. Consider using the OpenGL Shading Language instead. Mathematics of glTexGen - OpenGL Wikihttps://www.khronos.org/opengl/wiki/Mathematics_of_glTexGen)
void glTexGenf(GLenum coord, GLenum pname, GLfloat param);
void glTexGenfv(GLenum coord, GLenum pname, GLfloat *param);第一个参数指定了纹理坐标轴,可以是GL_S,GL_T,GL_R或GL_Q。第二个参数必须是GL_TEXTURE_SPHERE,GL_OBJECT_PLANE或GL_EYE_PLANE.最后一个参数设置纹理生成的方法或模式。glTexGen也有相应的GLint和GLdouble模式。
参数coord必须是GL_S、GL_T、GL_R或GL_Q
pname参数为GL_TEXTURE_GEN_MODE、GL_OBJECT_PLANE或GL_EYE_PLANE,
如果是GL_TEXTURE_GEN_MODE,param就是个整数,即GL_OBJECT_PLANE,GL_EYE_PLANE,GL_SPHERE_MAP,GL_REFLECTION,GL_NORMAL_MAP之一;
如果pname取其他可能的值,param就是指向数组的指针。
GL_OBJECT_LINEAR
g = p1 xo + p2 yo + p3 zo + p4 wo
glTexGen(GL_S, GL_OBJECT_LINEAR, ps0,ps1,ps2,ps3)
glTexGen(GL_T, GL_OBJECT_LINEAR, pt0,pt1,pt2,pt3)
和如下是等价的
vec4 sPlane = vec4(ps0,ps1,ps2,ps3);
vec4 tPlane = vec4(pt0,pt1,pt2,pt3);
kOutBaseTCoord.s = dot(vec4(POSITION, 1.0), sPlane);
kOutBaseTCoord.t = dot(vec4(POSITION, 1.0), tPlane);
GL_EYE_LINEAR
myEyePlane_S = VectorTimesMatrix(myPlane_S, InverseModelviewMatrix);
myEyePlane_T = VectorTimesMatrix(myPlane_T, InverseModelviewMatrix);
// Now that we have myEyePlane_S and myEyePlane_T...
for(i = 0; i < total; i++)
myEyeVertex = MatrixTimesVector(ModelviewMatrix, myVertex[i]);
myTexCoord[i].s = dot4D(myEyeVertex, myEyePlane_S);
myTexCoord[i].t = dot4D(myEyeVertex, myEyePlane_T);
GL_SPHERE_MAP
for(i = 0; i < total; i++)
myEyeVertex = MatrixTimesVector(ModelviewMatrix, myVertex[i]);
myEyeVertex = Normalize(myEyeVertex);
myEyeNormal = VectorTimesMatrix(myNormal[i], InverseModelviewMatrix);
reflectionVector = myEyeVertex - myEyeNormal * 2.0 * dot3D(myEyeVertex, myEyeNormal);
reflectionVector.z += 1.0;
m = 1.0 / (2.0 * sqrt(dot3D(reflectionVector, reflectionVector)));
// I am emphasizing that we write to s and t. Used to sample a 2D texture.
myTexCoord[i].s = reflectionVector.x * m + 0.5;
myTexCoord[i].t = reflectionVector.y * m + 0.5;
GL_REFLECTION_MAP
for(i = 0; i < total; i++)
myEyeVertex = MatrixTimesVector(ModelviewMatrix, myVertex[i]);
myEyeVertex = Normalize(myEyeVertex);
myEyeNormal = VectorTimesMatrix(myNormal[i], InverseModelviewMatrix);
dotResult = 2.0 * dot3D(myEyeVertex, myEyeNormal);
// I am emphasizing that we write to s and t and r. Used to sample a cubemap.
myTexCoord[i].s = myEyeVertex.x - myEyeNormal.x * dotResult;
myTexCoord[i].t = myEyeVertex.y - myEyeNormal.y * dotResult;
myTexCoord[i].r = myEyeVertex.z - myEyeNormal.z * dotResult;
以上是关于openGL之API学习(二零一)glTexGen的主要内容,如果未能解决你的问题,请参考以下文章
openGL之API学习(二零六)glClientActiveTexture
openGL之API学习(二零七)glTexCoordPointer
openGL之API学习(二零二)glsl的smooth flat