简体   繁体   English

为什么我的OpenGL显示器上的背景颜色不改变?

[英]Why won't my background color change on my OpenGL Display?

This is my code and on line 10 I put Display.setInitialBackground(200, 100, 56); 这是我的代码,在第10行,我将Display.setInitialBackground(200, 100, 56); however it just flashes on the screen 但是它只是在屏幕上闪烁

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class Window {

    public static void createWindow(int width, int height, String title) {

        Display.setTitle(title);
        Display.setInitialBackground(200, 100, 56);

        try {

            Display.setDisplayMode(new DisplayMode(width, height));
            Display.create();

        } catch (LWJGLException e) {

            e.printStackTrace();

        }

    }

    public static void render() {
        Display.update();
    }

    public static boolean isCloseRequested() {
        return Display.isCloseRequested();
    }

    public static int getWidth() {
        return Display.getWidth();
    }

    public static int getHeight() {
        return Display.getHeight();
    }

    public static String getTitle() {
        return Display.getTitle();
    }

}

This is a 2nd Class I have however with no errors 这是我没有的第二课

public class Main {

    public static final int WIDTH = 800;
    public static final int HEIGHT = 600;
    public static final String TITLE = "Virtual World";

    public Main() {

    }

    public void start() {
        run();
    }

    public void stop() {

    }

    public void run() {

        while(!Window.isCloseRequested()) {
            render();
        }

    }

    public void render() {
        Window.render();
    }

    public void cleanUp() {

    }

    public static void main(String[] args) {

        Window.createWindow(WIDTH, HEIGHT, TITLE);

        Main game = new Main();

        game.start();

    }

}

The color set by setInitialBackground is just the initial background color. setInitialBackground设置的颜色只是初始背景色。 At the moment where the OpenGL rendering starts this color is replaced by the content OpenGL draws. 在OpenGL渲染开始时,此颜色将替换为OpenGL绘制的内容。 If you want to set the background color while OpenGL is rendering I suggest to do this with glClearColor and glClear . 如果要在OpenGL渲染时设置背景色,建议使用glClearColorglClear

In addition: The documentation says: 另外:文档说:

red - - color value between 0 - 1 红色--颜色值介于0-1之间

green - - color value between 0 - 1 绿色--颜色值介于0-1之间

blue - - color value between 0 - 1 蓝色-颜色值介于0-1之间

But you supply a value of 200 which is out of range here. 但是您提供的值200超出了此处的范围。

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

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