Android,为什么我的前景图像的颜色在 openGL ES 中发生变化?

发布于 2024-12-28 07:54:58 字数 1397 浏览 2 评论 0原文

在我的应用程序中,我使用 openGL ES。 我想在屏幕上显示两个图像。第一个用作背景(PNG 格式,32 位,1280*800),第二个用作前景(PNG 格式,32 位,64*512)。

我可以在屏幕上显示两个图像,但我不知道为什么前景图像的颜色发生了变化!这个问题的图片是: 在此处输入图像描述 而手的本来颜色是棕色的。在下图中,我禁用了背景图像,因此我们只能看到图像中具有原始颜色的手。 在此处输入图像描述

请指导我问题是什么以及为什么颜色发生变化? 非常感谢

========== 更新:

代码的某些部分:

@Override
    public void onDrawFrame(GL10 gl) {

        try {
            Thread.sleep(ATEngine.GAME_THREAD_FPS_SLEEP);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

        setBackground(gl);
        setHand(gl);

        //All other game drawing will be called here
        gl.glEnable(GL10.GL_BLEND); 
        gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
    }

setHand方法是:

private void setHand(GL10 gl){ 
         gl.glMatrixMode(GL10.GL_MODELVIEW); 
         gl.glLoadIdentity(); 
         gl.glPushMatrix(); 
         gl.glScalef(.1f, .7f, 1f); 
         gl.glTranslatef(4.5f, 0f, 0f);

         gl.glMatrixMode(GL10.GL_TEXTURE); 
         gl.glLoadIdentity(); 
         gl.glTranslatef( 0.0f, 0.0f, 0.0f);  

         hand.draw(gl); 
         gl.glPopMatrix();   
         gl.glLoadIdentity(); 
     }

In my application I'm using openGL ES.
I want to show two images in the screen. The first acts as backgroung (PNG format, 32 bit, 1280*800) and second one is foreground (PNG format, 32 bit, 64*512).

I can show both image in the screen but i don't know why the color of foreground image is changed!!! the picture of this problem is:
enter image description here
While, the original color of hand is brown. in the following image i disabled background image, so we see just the hand with its original color in image.
enter image description here

please guide me what is the problem and why the color is changed?
Thanks a lot

==========
Update:

some part of code:

@Override
    public void onDrawFrame(GL10 gl) {

        try {
            Thread.sleep(ATEngine.GAME_THREAD_FPS_SLEEP);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

        setBackground(gl);
        setHand(gl);

        //All other game drawing will be called here
        gl.glEnable(GL10.GL_BLEND); 
        gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
    }

and setHand methode is:

private void setHand(GL10 gl){ 
         gl.glMatrixMode(GL10.GL_MODELVIEW); 
         gl.glLoadIdentity(); 
         gl.glPushMatrix(); 
         gl.glScalef(.1f, .7f, 1f); 
         gl.glTranslatef(4.5f, 0f, 0f);

         gl.glMatrixMode(GL10.GL_TEXTURE); 
         gl.glLoadIdentity(); 
         gl.glTranslatef( 0.0f, 0.0f, 0.0f);  

         hand.draw(gl); 
         gl.glPopMatrix();   
         gl.glLoadIdentity(); 
     }

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

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

发布评论

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

评论(1

心意如水 2025-01-04 07:54:58

在 onDrawFrame() 函数中,我用以下行更改了最后一行。问题已解决:)

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

有关更多信息,请参阅我的参考:http://www. swiftless.com/tutorials/opengl/blending.html

在此处输入图像描述

in onDrawFrame() function I changed last line with following line. the problem solved :)

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

for more information, please see my reference: http://www.swiftless.com/tutorials/opengl/blending.html

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文