1

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

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

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);

但是,它没有绘制纹理并隐藏透明像素,而是绘制了一个白色四边形。

我究竟做错了什么?

4

0 回答 0