具有不同 uv 坐标的 OpenGL ES 1 多重纹理
我需要使用多重纹理渲染一个对象,但同一对象的两个纹理具有不同的 uv 坐标。一张是法线贴图,另一张是光照贴图。
请提供与此相关的任何有用材料。
I need to render an object using multi-texturing but both the textures have different uv coordinates for same object. One is normal map and other one is light map.
Please provide any useful material regarding this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 OpenGL ES 2 中,无论如何你都会使用着色器。因此,您可以完全自由地使用您喜欢的任何纹理坐标。只需为第二个纹理坐标对引入一个附加属性,并将其委托给片段着色器,像往常一样:
并且在片段着色器中使用相应的坐标来访问纹理:
当然,您需要向这个新属性提供数据(使用
glVertexAttribPointer
)。但如果这一切对您来说听起来很陌生,那么您应该更深入地研究 GLSL 着色器,或者实际使用 OpenGL ES 1。在这种情况下,您应该重新标记您的问题,我将更新我的答案。编辑:根据您对 OpenGL ES 1 的更新,情况略有不同。我假设您已经知道如何使用单个纹理并为此指定纹理坐标,否则您应该在深入研究多重纹理之前从那里开始。
使用
glActiveTexture(GL_TEXTUREi)
你可以激活第i个纹理单元。以下所有与纹理状态相关的操作仅涉及第 i 个纹理单元(例如glBindTexture
,还有glTexEnv
和gl(En/Dis)able(GL_TEXTURE_2D)< /代码>)。
为了指定纹理坐标,您仍然使用
glTexCoordPointer
函数,就像单个纹理一样,但是使用glCientActiveTexture(GL_TEXTUREi)
您可以选择以下调用的纹理单元:>glTexCoordPointer
和glEnableClientAttrib(GL_TEXTURE_COORD_ARRAY)
参考。所以它会是这样的:
我在第一个纹理之前设置第二个纹理的参数的原因只是为了在设置它们之后我们最终会激活纹理单元 0。我想我已经看到驱动程序在绘图时出现问题,并且除单元 0 之外的另一个单元处于活动状态。最后留下或多或少干净的状态总是一个好主意,这意味着默认纹理单元(
GL_TEXTURE0
)处于活动状态,否则不关心多重纹理的代码可能会问题。编辑:如果您使用立即模式 (
glBegin/glEnd
) 而不是顶点数组,那么您当然不会使用glTexCoordPointer
。当然,在这种情况下,您也不需要glClientAttribTexture
。您只需将glMultiTexCoord(GL_TEXTUREi, ...)
与适当的纹理单元 (GL_TEXTURE0
,GL_TEXTURE1
, ...) 结合使用,而不是glTexCoord(...)
。但如果我没被告知的话,OpenGL ES 无论如何都没有即时模式。In OpenGL ES 2 you use shaders anyway. So you're completely free to use whatever texture coordinates you like. Just introduce an additional attribute for the second texture cooridnate pair and delegate this to the fragment shader, as usual:
And in the fragment shader use the respective coordinates to access the textures:
And of course you need to provide data to this new attribute (using
glVertexAttribPointer
). But if all this sounds very alien to you, then you should either delve a little deeper into GLSL shaders or you actually use OpenGL ES 1. In this case you should retag your question and I will update my answer.EDIT: According to your update for OpenGL ES 1 the situation is a bit different. I assume you already know how to use a single texture and specify texture coordinates for this, otherwise you should start there before delving into multi-texturing.
With
glActiveTexture(GL_TEXTUREi)
you can activate the ith texture unit. All following operations related to texture state only refer to the ith texture unit (likeglBindTexture
, but alsoglTexEnv
andgl(En/Dis)able(GL_TEXTURE_2D)
).For specifying the texture coordinates you still use the
glTexCoordPointer
function, as with single texturing, but withglCientActiveTexture(GL_TEXTUREi)
you can select the texture unit to which following calls toglTexCoordPointer
andglEnableClientAttrib(GL_TEXTURE_COORD_ARRAY)
refer.So it would be something like:
The reason I set the parameters for the second texture before the first texture is only so that after setting them we end up with texture unit 0 active. I think I have already seen drivers making problems when drawing and another unit than unit 0 was active. And it's always a good idea to leave a more or less clean state at the end, which means the default texture unit (
GL_TEXTURE0
) active, as otherwise code that doesn't care about multi-texturing could get problems.EDIT: If you use immediate mode (
glBegin/glEnd
) instead of vertex arrays, then you don't useglTexCoordPointer
, of course. In this case you also don't needglClientAttribTexture
, of course. You just need to useglMultiTexCoord(GL_TEXTUREi, ...)
with the appropriate texture unit (GL_TEXTURE0
,GL_TEXTURE1
, ...) instead ofglTexCoord(...)
. But if I'm informed correctly, OpenGL ES doesn't have immediate mode, anyway.