我试图通过以下方式将两个图像混合在一起:
应将图像1绘制为基本图像。图像2应该被绘制在图像1的上方。任何图像2都是不透明的,它应该替换图像1的内容(不是混合,而是覆盖那里的内容)。只要图像2透明,图像1就应该显示出来。我尝试使用以下代码执行此操作,但显然我在混合时做错了。
gl.glEnable(GL.GL_BLEND);
if (iconTexture1 != null)
{
gl.glEnable(GL.GL_TEXTURE_2D);
iconTexture1.bind();
double red = (double) fillColor.getRed() / 255.0;
double green = (double) fillColor.getGreen() / 255.0;
double blue = (double) fillColor.getBlue() / 255.0;
gl.glColor4d(red, green, blue, this.getOpacity());
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
TextureCoords texCoords = iconTexture1.getImageTexCoords();
gl.glScaled(width, height, 1d);
dc.drawUnitQuad(texCoords);
}
if (iconTexture2 != null)
{
gl.glEnable(GL.GL_TEXTURE_2D);
iconTexture2.bind();
// image2 is all white, so color it here
gl.glColor4d(1d, 0d, 0d, 1d);
// TODO: What blend function should I be using here to allow image 2 to overwrite what is already there?
TextureCoords texCoords = iconTexture2.getImageTexCoords();
gl.glScaled(width, height, 1d);
dc.drawUnitQuad(texCoords);
}
任何有助于使这项工作正常的帮助将不胜感激。感谢。
杰夫
答案 0 :(得分:2)
可能存在一些问题:
使用似乎不起作用的OpenGL的一个好方法是消除所有复杂性,然后一点一点地添加它。纹理是你最复杂的部分 - 留下直到最后。