[英]OpenGL- GLKit: transparent objects and texturing
My project is an IOS app using OpenGL 2.0 with the GLKit. 我的项目是使用OpenGL 2.0和GLKit的IOS应用程序。 In a nutshell, i have a texture of star with a transparent background that i would like to apply on a square. 简而言之,我有一个透明背景的星星纹理,我想在广场上应用。 The desired end result would be seeing a star; 期望的最终结果是看到一颗星; not a star on a square. 不是广场上的明星。
My current issue is that when i apply the texture on the square , i see a star with a colored square defined by its material color variables. 我当前的问题是,当我在正方形上应用纹理时,我看到一个由其材质颜色变量定义的彩色正方形的星。 What i would like is seeing only the star and having the rest of the square transparent. 我想要的只是看到明星并让方块的其余部分透明。
The code is as follow: 代码如下:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[effectTmp prepareToDraw];
glEnableVertexAttribArray(GLKVertexAttribPosition);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(ColoredVertexData3D), &vertexDataTexture[0].vertex);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, sizeof(ColoredVertexData3D), &vertexDataTexture[0].normal);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(ColoredVertexData3D), &vertexDataTexture[0].color);
glDrawArrays(GL_TRIANGLES, 0, [drawObjectTmp getSizeFromVertexIndicesArray]);
glDisableVertexAttribArray(GLKVertexAttribPosition);
glDisableVertexAttribArray(GLKVertexAttribTexCoord0);
glDisableVertexAttribArray(GLKVertexAttribNormal);
glDisable(GL_BLEND);
And the envMode is set to GLKTextureEnvModeDecal as below: 并且envMode设置为GLKTextureEnvModeDecal,如下所示:
effect.texture2d0.envMode = GLKTextureEnvModeDecal; effect.texture2d0.envMode = GLKTextureEnvModeDecal;
Probably there is a big elephant in the corridor i am not seeing; 可能在我看不到的走廊里有一头大象; and any help or pointer would be welcomed to help to see the star with its transparent square. 欢迎任何帮助或指针,以帮助看到它的透明方块明星。
Cheers, Stéphane 干杯,Stéphane
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.