[英]Textures and background blending a little
So I am making a simple opengl/SDL project for my university assignment.所以我正在为我的大学作业制作一个简单的 opengl/SDL 项目。
Basically a very simple game with a character moving across the screen.基本上是一个非常简单的游戏,角色在屏幕上移动。
I am almost done but I've encountered a problem.我快完成了,但我遇到了一个问题。
So when I load textures etc, they sort of blend together and "shine" through each other.因此,当我加载纹理等时,它们会混合在一起并相互“闪耀”。
Here's an example:下面是一个例子:
Left - Red background color glClearColor(1.0f, 0.0f, 0.0f, 0.0f);左 - 红色背景色 glClearColor(1.0f, 0.0f, 0.0f, 0.0f); Middle - Green background color中 - 绿色背景色
Right - Black background右 - 黑色背景
As you can see, the background is affecting textures in front of it which I really don't like.正如你所看到的,背景影响了它前面的纹理,我真的不喜欢。
The black background is alright-ish (makes my textures a bit darker) and I could live with it but as you can see, with black background we can see a little bit of the texture behind vader through him.黑色背景很好(使我的纹理更暗),我可以接受它,但正如你所看到的,黑色背景我们可以通过他看到维达背后的一点纹理。
It's the most noticeable around his shoulders.最明显的是他的肩膀。 Id rather keep the textures completely opaque and maintain colours as they are.我宁愿保持纹理完全不透明并保持颜色原样。
To remove alpha channel I am using要删除我正在使用的 alpha 通道
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
but I feel like this isn't the best way to do it since it blends all the textures together as well.但我觉得这不是最好的方法,因为它也将所有纹理混合在一起。
Is there a way to keep the image completely opaque while maintaining the alpha channel so there's no stuff around it?有没有办法在保持 alpha 通道的同时保持图像完全不透明,这样它周围就没有东西了?
Okay I've fixed it.好的,我已经修好了。 It turned out that I had a piece of code in the shader that blend everything.原来,我在着色器中有一段代码可以混合所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.