在 Android OpenGL ES 1.1 中乘以纹理

发布于 2025-01-02 23:11:42 字数 173 浏览 2 评论 0原文

我正在尝试在 Android 上学习 OpenGL,作为我的学习项目的一部分,我想让纹理的一部分变得透明。为了实现这一点,我得到了一个全白色的纹理,并且在我想要透明度的地方将 Alpha 通道设置为透明。我的计划是将其与我想要显示的纹理相乘,但我对缩写的函数名称和整数常量有点困惑。

有没有简单但完整的纹理乘法示例?

I'm trying to learn OpenGL on Android and as part of my learning project I want to make part of a texture transparent. To accomplish that I've got a texture that's all white with the alpha channel set to transparent where I want the transparency. My plan was to multiply this against the texture I want to display, but I'm a little boggled by the abbreviated function names and integer constants.

Any simple but complete examples with texture multiplication out there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2025-01-09 23:11:42

编辑:我的错,我刚刚看到您正在寻找 gl 1.0 示例

看起来您正在寻找多纹理示例: http://code.google.com/p/opengles-book-sa​​mples/source/browse/trunk/Android/Ch10_MultiTexture/src/com/openglesbook/multitexture/MultiTextureRenderer.java?r=45< /a>

这是一个 opengl es 2.0 示例。当您阅读代码时,您会发现纹理的实际混合是在片段着色器中完成的。

编辑2:我找不到 opengl-es 1.1 示例,但我有一些旧的 opengl 2.0 代码。它是用c/c++编写的,所以你必须自己将它转换为java。

我查阅了 GLES 1.1 规范,似乎它支持我的代码中的关键功能:glActiveTexture、glMultiTexCoord 和 glTexEnvi,所以这可能会帮助您入门...

glActiveTextureARB( GL_TEXTURE0_ARB );
glBindTexture( GL_TEXTURE_2D, KdMapIndex );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glActiveTextureARB( GL_TEXTURE1_ARB );
glBindTexture(GL_TEXTURE_2D, KaMapIndex);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);

glBegin(GL_TRIANGLES);
for (face = faces.begin(); face != faces.end(); face++)
{
    CVector3f normal;
    CVector2f texture0, texture1, texture2;
    CVector3f vertex0, vertex1, vertex2;

    normal.x = data.normals[face->nIndex[0]-1].x;
    normal.y = data.normals[face->nIndex[1]-1].y;
    normal.z = data.normals[face->nIndex[2]-1].z;
    normal.normalize();

    texture0 = data.texcoords[face->tIndex[0]-1];
    texture1 = data.texcoords[face->tIndex[1]-1];
    texture2 = data.texcoords[face->tIndex[2]-1];

    vertex0 = data.vertices[face->vIndex[0]-1];
    vertex1 = data.vertices[face->vIndex[1]-1];
    vertex2 = data.vertices[face->vIndex[2]-1];

    glNormal3f(normal.x, normal.y, normal.z);       // Face normal

    glMultiTexCoord2fARB( GL_TEXTURE0_ARB, texture0.x, texture0.y ); // texcoord 0
    glMultiTexCoord2fARB( GL_TEXTURE1_ARB, texture0.x, texture0.y );        
    glVertex3f(vertex0.x, vertex0.y, vertex0.z);    // vertex 0

    glMultiTexCoord2fARB( GL_TEXTURE0_ARB, texture1.x, texture1.y ); // texcoord 1
    glMultiTexCoord2fARB( GL_TEXTURE1_ARB, texture1.x, texture1.y );    
    glVertex3f(vertex1.x, vertex1.y, vertex1.z);    // vertex 1

    glMultiTexCoord2fARB( GL_TEXTURE0_ARB, texture2.x, texture2.y ); // texcoord 2
    glMultiTexCoord2fARB( GL_TEXTURE1_ARB, texture2.x, texture2.y );    
    glVertex3f(vertex2.x, vertex2.y, vertex2.z);    // vertex 2
}
glEnd();

EDIT: my bad, I just saw that you're looking for an gl 1.0 example

Looks like you're looking for a multi-texture example: http://code.google.com/p/opengles-book-samples/source/browse/trunk/Android/Ch10_MultiTexture/src/com/openglesbook/multitexture/MultiTextureRenderer.java?r=45

It's an opengl es 2.0 example. When you read the code, you'll see that the actual blending of the texture is done is in the fragmentshader.

EDIT 2 : I couldn't find a opengl-es 1.1 example, but I have some old opengl 2.0 code lying around. It's in c/c++, so you'll have to convert it to java yourself.

I looked up the GLES 1.1 spec, and it seems it supports the key functions from my code: glActiveTexture, glMultiTexCoord and glTexEnvi, so this may help get you started...

glActiveTextureARB( GL_TEXTURE0_ARB );
glBindTexture( GL_TEXTURE_2D, KdMapIndex );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glActiveTextureARB( GL_TEXTURE1_ARB );
glBindTexture(GL_TEXTURE_2D, KaMapIndex);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);

glBegin(GL_TRIANGLES);
for (face = faces.begin(); face != faces.end(); face++)
{
    CVector3f normal;
    CVector2f texture0, texture1, texture2;
    CVector3f vertex0, vertex1, vertex2;

    normal.x = data.normals[face->nIndex[0]-1].x;
    normal.y = data.normals[face->nIndex[1]-1].y;
    normal.z = data.normals[face->nIndex[2]-1].z;
    normal.normalize();

    texture0 = data.texcoords[face->tIndex[0]-1];
    texture1 = data.texcoords[face->tIndex[1]-1];
    texture2 = data.texcoords[face->tIndex[2]-1];

    vertex0 = data.vertices[face->vIndex[0]-1];
    vertex1 = data.vertices[face->vIndex[1]-1];
    vertex2 = data.vertices[face->vIndex[2]-1];

    glNormal3f(normal.x, normal.y, normal.z);       // Face normal

    glMultiTexCoord2fARB( GL_TEXTURE0_ARB, texture0.x, texture0.y ); // texcoord 0
    glMultiTexCoord2fARB( GL_TEXTURE1_ARB, texture0.x, texture0.y );        
    glVertex3f(vertex0.x, vertex0.y, vertex0.z);    // vertex 0

    glMultiTexCoord2fARB( GL_TEXTURE0_ARB, texture1.x, texture1.y ); // texcoord 1
    glMultiTexCoord2fARB( GL_TEXTURE1_ARB, texture1.x, texture1.y );    
    glVertex3f(vertex1.x, vertex1.y, vertex1.z);    // vertex 1

    glMultiTexCoord2fARB( GL_TEXTURE0_ARB, texture2.x, texture2.y ); // texcoord 2
    glMultiTexCoord2fARB( GL_TEXTURE1_ARB, texture2.x, texture2.y );    
    glVertex3f(vertex2.x, vertex2.y, vertex2.z);    // vertex 2
}
glEnd();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文