LWJGL纹理混合不起作用

时间:2013-03-22 15:28:31

标签: java opengl textures lwjgl alphablending

我正在尝试绘制渐变,然后在其上绘制透明纹理。

这是我现在正在使用的代码:

GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);

// Draw the gradient
GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glColor4f(1F, 1F, 1F, 0F);
    GL11.glVertex3f(0, 0, 0.0f);
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glColor4f(0F, 1F, 1F, 0F);
    GL11.glVertex3f(0 + gameWidth, 0, 0.0f);
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glColor4f(0F, 0F, 1F, 0F);
    GL11.glVertex3f(0 + gameWidth, 0 + gameHeight, 0.0f);
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glColor4f(1F, 0F, 1F, 0F);
    GL11.glVertex3f(0, 0 + gameHeight, 0.0f);
GL11.glEnd();
GL11.glColor4f(1F, 1F, 1F, 0F);

GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);

TexLoader.loadTex("/example.png"); // Loads and binds the texture, also enables GL_TEXTURE_2D
GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex3f(parX, parY, 0.0f);
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glVertex3f(parX + parWidth, parY, 0.0f);
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glVertex3f(parX + parWidth, parY + parHeight, 0.0f);
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glVertex3f(parX, parY + parHeight, 0.0f);
GL11.glEnd();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);

然而,它不是绘制纹理并隐藏透明像素,而是绘制白色四边形。

我做错了什么?

0 个答案:

没有答案