Question

I am messing around with the LWJGL library and have tried to display a screen, it displays fine in every sense except for a screen glitch as illustrated below. This glitch happens every time I display a screen. I have included only the lwjgl.jar as a referenced library and have linked it to the 'linux' natives folder. I am running the Ubuntu 13.10 OS and have installed 'freeglut' for the opengl.

enter image description here

Here is the code that I am using to display the screen.

public Main()
{
    try
    {
        Display.setDisplayMode(new DisplayMode(640, 480));
        Display.create();
    }
    catch(LWJGLException ex)
    {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

    while(!Display.isCloseRequested())
    {
        Display.update();
        Display.sync(60);
    }

    Display.destroy();
}

Can anyone tell me what is causing this issue?

Was it helpful?

Solution

You have to clear the color buffer every update:

glClearColor(0f, 0f, 0f, 0f);
glClear(GL_COLOR_BUFFER_BIT);

EDIT: To clarify: the color buffer (and depth buffer if you're working with 3D) MUST BE CLEARED every frame before the Display updates. If it is not cleared, it will be filled with random data (hence the checkerboarding and foobar.)

OTHER TIPS

Clear the screen first before Display.update();

Use glClear(GL_COLOUR_BUFFER_BIT); to clear the colour buffer. If you use the depth buffer, you may also want to set it to GL_COLOUR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. You can use glClearColour() to set the colour the screen will clear, with the 3 inputs being red, green, and blue, and the last one being the alpha colour (not needed, just set to 1 if you have to).

Note: I am english. Replace colour with color.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top