简体   繁体   English

在Android OpenGL ES 1.1中相乘纹理

[英]Multiply textures in Android OpenGL ES 1.1

I'm trying to learn OpenGL on Android and as part of my learning project I want to make part of a texture transparent. 我正在尝试在Android上学习OpenGL,作为学习项目的一部分,我想使纹理的一部分透明。 To accomplish that I've got a texture that's all white with the alpha channel set to transparent where I want the transparency. 为了实现这一点,我获得了全白色的纹理,并且在需要透明度的地方将Alpha通道设置为透明。 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? 有没有简单而完整的示例,其中包含纹理乘法?

EDIT: my bad, I just saw that you're looking for an gl 1.0 example 编辑:我不好,我只是看到您正在寻找gl 1.0示例

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

It's an opengl es 2.0 example. 这是一个opengl es 2.0示例。 When you read the code, you'll see that the actual blending of the texture is done is in the fragmentshader. 阅读代码时,您会看到纹理的实际混合是在fragmentshader中完成的。

EDIT 2 : I couldn't find a opengl-es 1.1 example, but I have some old opengl 2.0 code lying around. 编辑2:我找不到一个opengl-es 1.1示例,但是我周围有一些旧的opengl 2.0代码。 It's in c/c++, so you'll have to convert it to java yourself. 它在c / c ++中,因此您必须自己将其转换为Java。

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... 我查看了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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM