【发布时间】:2016-06-29 19:37:40
【问题描述】:
更新 1
您可以看到在 FrameBuffer 上绘制的 LibGDX 纹理,与直接在 SpriteBatcher 上绘制的纹理相比,SpriteBatcher 上的纹理比原始纹理更暗。
左边是原图,比手机 1080x1920 屏幕小 50%。
中间部分直接从SpriteBatch上的TextureRegion绘制,并水平镜像,以便更好地与左右图像进行比较。它有点失真,但我启用了线性过滤,正如您在代码中看到的那样:
texture = new Texture("texture.png");
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
image = new TextureRegion(texture, 0, 0, 1024, 1024);
batcher.begin();
batcher.draw(image, 0, 0, screenWidth, screenHeight);
batcher.end();
右边部分是先在FrameBuffer上绘制TextureRegion,然后在SpriteBatch上绘制,如下代码:
texture = new Texture("texture.png");
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
image = new TextureRegion(texture, 0, 0, 1024, 1024);
pixmap = new FrameBuffer(Pixmap.Format.RGBA8888, screenWidth, screenHeight, false);
pixmapregion = new TextureRegion(pixmap.getColorBufferTexture(), screenWidth, screenHeight);
pixmap.begin();
batcher.begin();
batcher.draw(image, 0, 0, screenWidth, screenHeight);
batcher.end();
pixmap.end();
batcher.begin();
batcher.draw(pixmapregion , 0, 0, screenWidth, screenHeight);
batcher.end();
如您所见,它比直接从纹理绘制的图像暗一点。而且当我用着色器绘制它时,与用着色器绘制的纹理相比,结果是一团糟。
所以真正的问题是 FrameBuffer 对与它混淆的纹理做了什么,所以它不能与着色器一起使用。而且我需要先在像素图上绘制它,这样我才能混合两个透明的帧缓冲区。一直以来我都认为问题出在着色器上,我花了 3 天时间才找到问题所在,所以如果有人可以帮助我,我将不胜感激! :)
注意:我尝试在 FrameBuffer 上绘图时启用混合,首先使用 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);但没有任何区别。
更新 2
看起来我应该在 FrameBuffer 上绘制时设置一种 GL 混合,在绘制 FrameBuffer 时设置第二种混合,但我还不能得到正确的组合......
老问题
左图是在 Photoshop 中制作的,具有 alpha 透明度,但我设置了黑色背景,以便更好地查看。右图是安卓屏幕的屏幕截图。这是我的代码,我先在像素图上绘制纹理,然后在屏幕上绘制像素图,纹理质量很差,alpha 通道非常失真,如您所见。
texture = new Texture("drop-blue.png");
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
image = new TextureRegion(texture, 0, 0, 1024, 1024);
pixmap = new FrameBuffer(Pixmap.Format.RGBA8888, screenWidth, screenHeight, false);
pixmapregion = new TextureRegion(pixmap.getColorBufferTexture(), screenWidth, screenHeight);
pixmap.begin();
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batcher.begin();
batcher.draw(image, screenWidth/2 - 512, screenHeight/2 - 512, 1024, 1024);
batcher.end();
pixmap.end();
batcher.begin();
batcher.draw(pixmapregion, 0, 0, screenWidth, screenHeight);
batcher.end();
【问题讨论】:
-
图片在哪里?
-
对不起,我忘记添加链接了...
-
您的图像是 RGBA8888 格式吗?试试 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);和 spritebatch.enableBlending(); spritebatch.setBlendFunction(gl.BLEND_SRC_ALPHA,gl.BLEND_ONE_MINUS_SRC_ALPHA);
-
是的,在 Photoshop 中,我将网络图像保存为 24 位并检查了透明度,据我所知,这应该是 RGBA8888。我也尝试启用混合并设置混合功能,但没有成功,同样的事情再次发生......:/
标签: android opengl-es libgdx alpha