OpenGL、GL_MODULATE 和多重纹理
我已经成功绘制了一个多纹理多边形,但不幸的是,整个纹理区域仅使用了重叠纹理的第一个像素。
以下是纹理(GL_TEXTURE0 和 GL_TEXTURE1):
结果是这样的:
仅位于顶部正在使用中。我尝试在顶部仅使用 1x1 蓝色像素,并且使用蓝色叠加得到相同的结果。
我的代码:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisableClientState(GL_COLOR_ARRAY);
const CGPoint vertices[] = {
ccp(0,0),
ccp(100,0),
ccp(0,100),
ccp(100,100),
};
// This will flip the image for us as well
const CGPoint coordinates[] = {
ccp(0,1),
ccp(1,1),
ccp(0,0),
ccp(1,0),
};
// Config multitextures
glClientActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, icon.name);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glEnable(GL_TEXTURE_2D);
glClientActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, overlay.name);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glEnable(GL_TEXTURE_2D);
GLubyte points = 4;
// Draw the square
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, points);
// Revert back
glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
// glClientActiveTexture(GL_TEXTURE0); // breaks multitexturing
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
这是一个 OpenGL 问题,但感兴趣的人可以在这里找到 iOS 项目: http://dl.dropbox.com/u/33811812/cocos2d/OpenGLTest.zip
编辑: 摘自红皮书:
如果您使用多重纹理并使用 glTexCoord*(),则您正在设置 第一个纹理单元的纹理坐标。换句话说, 使用 glTexCoord*() 相当于使用 glMultiTexCoord* (GL_TEXTURE0,...)
有关如何传递坐标数组的任何提示? OpenGL ES 1.1 不支持 glBegin() 等。
I have successfully drawn a multi-textured polygon but unfortunately only the first pixel of the overlaying texture is being used across the entire texture area.
Here are the textures (GL_TEXTURE0 and GL_TEXTURE1):
The result is this:
Only the red pixel at the top is being used. I've tried with just a 1x1 blue pixel up the top and I get the same result with blue overlay.
My code:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisableClientState(GL_COLOR_ARRAY);
const CGPoint vertices[] = {
ccp(0,0),
ccp(100,0),
ccp(0,100),
ccp(100,100),
};
// This will flip the image for us as well
const CGPoint coordinates[] = {
ccp(0,1),
ccp(1,1),
ccp(0,0),
ccp(1,0),
};
// Config multitextures
glClientActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, icon.name);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glEnable(GL_TEXTURE_2D);
glClientActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, overlay.name);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glEnable(GL_TEXTURE_2D);
GLubyte points = 4;
// Draw the square
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, points);
// Revert back
glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
// glClientActiveTexture(GL_TEXTURE0); // breaks multitexturing
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
This is an OpenGL problem, but the iOS project is available here for those interested: http://dl.dropbox.com/u/33811812/cocos2d/OpenGLTest.zip
EDIT:
From the Red Book:
If you are multitexturing and you use glTexCoord*(), you are setting
the texture coordinates for the first texture unit. In other words,
using glTexCoord*() is equivalent to using glMultiTexCoord*
(GL_TEXTURE0,...)
Any hints as to how to pass an array of coordinates? OpenGL ES 1.1 doesn't support glBegin() etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后!解决方案是我必须做三件事:
这是代码有效:
结果:
Finally! The solution was that I had to do three things:
Here's the code that works:
And the result: