Sam
Sam

Reputation: 65

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

    }

}

Upvotes: 0

Views: 233

Answers (1)

BDL
BDL

Reputation: 22177

The color set by setInitialBackground is just the initial background color. At the moment where the OpenGL rendering starts this color is replaced by the content OpenGL draws. If you want to set the background color while OpenGL is rendering I suggest to do this with glClearColor and glClear.

In addition: The documentation says:

red - - color value between 0 - 1

green - - color value between 0 - 1

blue - - color value between 0 - 1

But you supply a value of 200 which is out of range here.

Upvotes: 2

Related Questions