如何使用 glew 将 opengl 代码移植到 iPhone 的 openGL ES 代码
我正在尝试将用 opengl 编写的 ogre 函数移植到 opengl ES,但该函数使用 glew.h 中的定义,并且我不知道如何移植此代码。
问题是GL_S(例如)没有声明,因为它是int glew.h,而我没有iPhone的glew.h。
这是代码:
void GLRenderSystem::_setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
const Frustum* frustum)
{
if (stage >= mFixedFunctionTextureUnits)
{
// Can't do this
return;
}
GLfloat M[16];
Matrix4 projectionBias;
// Default to no extra auto texture matrix
mUseAutoTextureMatrix = false;
GLfloat eyePlaneS[] = {1.0, 0.0, 0.0, 0.0};
GLfloat eyePlaneT[] = {0.0, 1.0, 0.0, 0.0};
GLfloat eyePlaneR[] = {0.0, 0.0, 1.0, 0.0};
GLfloat eyePlaneQ[] = {0.0, 0.0, 0.0, 1.0};
if (!activateGLTextureUnit(stage))
return;
switch( m )
{
case TEXCALC_NONE:
glDisable( GL_TEXTURE_GEN_S );
glDisable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
break;
case TEXCALC_ENVIRONMENT_MAP:
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
// Need to use a texture matrix to flip the spheremap
mUseAutoTextureMatrix = true;
memset(mAutoTextureMatrix, 0, sizeof(GLfloat)*16);
mAutoTextureMatrix[0] = mAutoTextureMatrix[10] = mAutoTextureMatrix[15] = 1.0f;
mAutoTextureMatrix[5] = -1.0f;
break;
case TEXCALC_ENVIRONMENT_MAP_PLANAR:
// XXX This doesn't seem right?!
ifdef GL_VERSION_1_3
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
else
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
endif
break;
case TEXCALC_ENVIRONMENT_MAP_REFLECTION:
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
// We need an extra texture matrix here
// This sets the texture matrix to be the inverse of the view matrix
mUseAutoTextureMatrix = true;
makeGLMatrix( M, mViewMatrix);
// Transpose 3x3 in order to invert matrix (rotation)
// Note that we need to invert the Z _before_ the rotation
// No idea why we have to invert the Z at all, but reflection is wrong without it
mAutoTextureMatrix[0] = M[0]; mAutoTextureMatrix[1] = M[4]; mAutoTextureMatrix[2] = -M[8];
mAutoTextureMatrix[4] = M[1]; mAutoTextureMatrix[5] = M[5]; mAutoTextureMatrix[6] = -M[9];
mAutoTextureMatrix[8] = M[2]; mAutoTextureMatrix[9] = M[6]; mAutoTextureMatrix[10] = -M[10];
mAutoTextureMatrix[3] = mAutoTextureMatrix[7] = mAutoTextureMatrix[11] = 0.0f;
mAutoTextureMatrix[12] = mAutoTextureMatrix[13] = mAutoTextureMatrix[14] = 0.0f;
mAutoTextureMatrix[15] = 1.0f;
break;
case TEXCALC_ENVIRONMENT_MAP_NORMAL:
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
break;
case TEXCALC_PROJECTIVE_TEXTURE:
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, eyePlaneS);
glTexGenfv(GL_T, GL_EYE_PLANE, eyePlaneT);
glTexGenfv(GL_R, GL_EYE_PLANE, eyePlaneR);
glTexGenfv(GL_Q, GL_EYE_PLANE, eyePlaneQ);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
mUseAutoTextureMatrix = true;
// Set scale and translation matrix for projective textures
projectionBias = Matrix4::CLIPSPACE2DTOIMAGESPACE;
projectionBias = projectionBias * frustum->getProjectionMatrix();
if(mTexProjRelative)
{
Matrix4 viewMatrix;
frustum->calcViewMatrixRelative(mTexProjRelativeOrigin, viewMatrix);
projectionBias = projectionBias * viewMatrix;
}
else
{
projectionBias = projectionBias * frustum->getViewMatrix();
}
projectionBias = projectionBias * mWorldMatrix;
makeGLMatrix(mAutoTextureMatrix, projectionBias);
break;
default:
break;
}
activateGLTextureUnit(0);
}
I'm trying to port a ogre function written in opengl to opengl ES, but this function uses defines from glew.h, and I have no idea how to port this code.
The problem si that GL_S (for example) is not declared, because is int glew.h, and i have not glew.h for iPhone.
This is the code:
void GLRenderSystem::_setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
const Frustum* frustum)
{
if (stage >= mFixedFunctionTextureUnits)
{
// Can't do this
return;
}
GLfloat M[16];
Matrix4 projectionBias;
// Default to no extra auto texture matrix
mUseAutoTextureMatrix = false;
GLfloat eyePlaneS[] = {1.0, 0.0, 0.0, 0.0};
GLfloat eyePlaneT[] = {0.0, 1.0, 0.0, 0.0};
GLfloat eyePlaneR[] = {0.0, 0.0, 1.0, 0.0};
GLfloat eyePlaneQ[] = {0.0, 0.0, 0.0, 1.0};
if (!activateGLTextureUnit(stage))
return;
switch( m )
{
case TEXCALC_NONE:
glDisable( GL_TEXTURE_GEN_S );
glDisable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
break;
case TEXCALC_ENVIRONMENT_MAP:
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
// Need to use a texture matrix to flip the spheremap
mUseAutoTextureMatrix = true;
memset(mAutoTextureMatrix, 0, sizeof(GLfloat)*16);
mAutoTextureMatrix[0] = mAutoTextureMatrix[10] = mAutoTextureMatrix[15] = 1.0f;
mAutoTextureMatrix[5] = -1.0f;
break;
case TEXCALC_ENVIRONMENT_MAP_PLANAR:
// XXX This doesn't seem right?!
ifdef GL_VERSION_1_3
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
else
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
endif
break;
case TEXCALC_ENVIRONMENT_MAP_REFLECTION:
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
// We need an extra texture matrix here
// This sets the texture matrix to be the inverse of the view matrix
mUseAutoTextureMatrix = true;
makeGLMatrix( M, mViewMatrix);
// Transpose 3x3 in order to invert matrix (rotation)
// Note that we need to invert the Z _before_ the rotation
// No idea why we have to invert the Z at all, but reflection is wrong without it
mAutoTextureMatrix[0] = M[0]; mAutoTextureMatrix[1] = M[4]; mAutoTextureMatrix[2] = -M[8];
mAutoTextureMatrix[4] = M[1]; mAutoTextureMatrix[5] = M[5]; mAutoTextureMatrix[6] = -M[9];
mAutoTextureMatrix[8] = M[2]; mAutoTextureMatrix[9] = M[6]; mAutoTextureMatrix[10] = -M[10];
mAutoTextureMatrix[3] = mAutoTextureMatrix[7] = mAutoTextureMatrix[11] = 0.0f;
mAutoTextureMatrix[12] = mAutoTextureMatrix[13] = mAutoTextureMatrix[14] = 0.0f;
mAutoTextureMatrix[15] = 1.0f;
break;
case TEXCALC_ENVIRONMENT_MAP_NORMAL:
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP );
glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
break;
case TEXCALC_PROJECTIVE_TEXTURE:
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, eyePlaneS);
glTexGenfv(GL_T, GL_EYE_PLANE, eyePlaneT);
glTexGenfv(GL_R, GL_EYE_PLANE, eyePlaneR);
glTexGenfv(GL_Q, GL_EYE_PLANE, eyePlaneQ);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
mUseAutoTextureMatrix = true;
// Set scale and translation matrix for projective textures
projectionBias = Matrix4::CLIPSPACE2DTOIMAGESPACE;
projectionBias = projectionBias * frustum->getProjectionMatrix();
if(mTexProjRelative)
{
Matrix4 viewMatrix;
frustum->calcViewMatrixRelative(mTexProjRelativeOrigin, viewMatrix);
projectionBias = projectionBias * viewMatrix;
}
else
{
projectionBias = projectionBias * frustum->getViewMatrix();
}
projectionBias = projectionBias * mWorldMatrix;
makeGLMatrix(mAutoTextureMatrix, projectionBias);
break;
default:
break;
}
activateGLTextureUnit(0);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenGL ES 1.X 没有纹理坐标生成 。
OpenGL ES 1.X doesn't have texture coordinate generation.