简体   繁体   English

有没有办法清除 LWJGL 的 memory 的颜色?

[英]Is there a way to clear the colour from the memory of LWJGL?

I am creating a 2D game where I am currently drawing on the screen, a quad filling the entire screen to have a blue background.我正在创建一个 2D 游戏,我目前正在屏幕上绘制,一个四边形填充整个屏幕以具有蓝色背景。 Then I am drawing a stone texture on top of it.然后我在它上面画一个石头纹理。 The issue is when the program draws the stone, it gives it a blue tint as it is using the colour from the sky quad.问题是当程序绘制石头时,它给它一个蓝色调,因为它使用了天空四边形的颜色。 I was wondering if there is a way to clear the colour from the memory of OpenGL / GLFW / LWJGL.我想知道是否有办法从 OpenGL / GLFW / LWJGL 的 memory 中清除颜色。 I am using Java 1.8 and LWJGL 3.2.3我正在使用 Java 1.8 和 LWJGL 3.2.3

Here is the code:这是代码:

private static void renderAir() {
        glfwMakeContextCurrent(InnocentDream.win);
        glBegin(GL_QUADS);
        glColor4f(0, 204 / 255f, 1, 1);
        glVertex2f(-256, 128);
        glColor4f(0, 204 / 255f, 1, 1);
        glVertex2f(256, 128);
        glColor4f(0, 108 / 255f, 250 / 255f, 1);
        glVertex2f(256, -128);
        glColor4f(0, 108 / 255f, 250 / 255f, 1);
        glVertex2f(-256, -128);
        glEnd();
}

I have the GLFW and GL11 classes as static imports.我将GLFWGL11类作为 static 导入。

public void renderTileAtPos(float x, float y) {
        float TILE_WIDTH = Tile.TILE_WIDTH / 2f;
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, texture.getTextureID());
        glBegin(GL_QUADS);
        glTexCoord2f(1, 0);
        glVertex2f(-TILE_WIDTH + x, TILE_WIDTH + y);
        glTexCoord2f(0, 0);
        glVertex2f(TILE_WIDTH + x, TILE_WIDTH + y);
        glTexCoord2f(0, 1);
        glVertex2f(TILE_WIDTH + x, -TILE_WIDTH + y);
        glTexCoord2f(1, 1);
        glVertex2f(-TILE_WIDTH + x, -TILE_WIDTH + y);
        glEnd();
        glDisable(GL_TEXTURE_2D);
}

And here is the tile rendering.这是瓷砖渲染。

glColor4f(1,1,1,1);

Throw that call either after your original sky code, or just before you render the stone.在原始天空代码之后或在渲染石头之前抛出该调用。

It's a good practice if using glColor() calls, to get in the habit of always calling glColor() before drawing anything, or to only call it once on initialisation and never call it again.如果使用glColor()调用,养成在绘制任何东西之前总是调用glColor()的习惯,或者只在初始化时调用它一次并且不再调用它,这是一个很好的做法。

There is no "remove the colour I just set" call.没有“删除我刚刚设置的颜色”调用。 The value of "glColor" is just one of those pieces of state that OpenGL hangs on to. “glColor”的值只是 OpenGL 所依赖的 state 的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM