Results 1 to 7 of 7

Thread: Weird flickering when rendering with lwjgl

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2015

    Question Weird flickering when rendering with lwjgl

    When i render some basic terrain with lwjgl and move the my mesh there are some weird artifacts, this only happens with windows 8 and a nvidia gpu.
    On my old macbook the exact same code (except for natives) works fine.

    I already tried to render on a texture but it didnt change.

    Has this something to do with my code or is it a bug with the nvidia drivers.

    fragment shader
    Code :
    #version 400core 
    in vec2 texCords;
    in vec3 surfaceNormal;
    in vec3 toLight;
    in vec3 toCamera;
    in vec3 position_out;
    in float distanceToCamera_out;
    uniform vec3 diffuseLightColor;
    uniform vec3 specularLightColor;
    out vec4 out_Color;
    void main(void){
    vec3 unitNormal = normalize(surfaceNormal);
    vec3 unitToLight = normalize(toLight);
    vec4 color = vec4(1,1,1,1);
    //diffuse light
    float diffuseFactor = max(dot(unitNormal, unitToLight),0);
    vec3 diffuse = diffuseLightColor * diffuseFactor;
    //specular light
    vec3 reflected = reflect(-unitToLight,unitNormal);
    float specularFactor = max(dot(reflected,normalize(toCamera)),0);
    specularFactor = pow(specularFactor,50); //dampening
    vec3 specular = specularLightColor * specularFactor;
    //final light
    vec3 finalLight = diffuse + specular;
    //final color
    out_Color = color * vec4(finalLight,1);

    render function
    Code :
    public void render(Entity entity) {
        TexturedModel texModel=entity.getModel();
        RawModel model=texModel.getModel();
        ModelTexture texture = texModel.getTexture();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getBaseId());
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, model.getVboiId());
        shader.loadTransformation(Maths.createTransformationMatrix(entity.getPosition(), entity.getRx(), entity.getRy(), entity.getRz(), entity.getScale()));
        GL11.glDrawElements(GL11.GL_TRIANGLES, model.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Quote Originally Posted by eeeeeeee View Post
    ...there are some weird artifacts
    Perhaps you could call out what weird artifacts you're referring to.

    There's no texture, but you're not reading any textures in your shader so that's not the artifact...

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2015
    Well with the artifacts i just meant those spots on the model where the color is too dark for just a few frames.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Ok. Guess I don't see that in your video. Might move your light so it's more orthogonal to the surface being shaded and retry. Everything I noticed was just normal diffuse lighting.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2015
    I tried the thing with the lighting but the flickering remains. So I uploaded a video where it can be seen a bit better.

    Anyways thanks for the help.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Ok, I think I see what you're talking about. It appears those might be tearing artifacts. That is, artifacts of the video card scanning out pieces of different different rendered video frames for display within the same scan-out frame.

    You need to enable VSync (i.e. Sync-to-VBlank) for your rendering. See:


    Basically, call {wgl,glX}SwapInterval(1) in your program, and check your driver control panel to ensure that it's not overriding the swap interval that your program specifies.

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2015
    So when I call Display.setSwapInterval(1) and turn off V-Sync in my graphics controlpanel the artifacts still remain. So im not sure if the lwjgl Display.setSwapInterval method is equivalent to the wgl method you mentioned above.

    Heres the method where I create my display

    public static void setUpDisplay(){
    ContextAttribs attribs = new ContextAttribs(3,2).withForwardCompatible(true).wi thProfileCore(true);
    try {
    Display.setDisplayMode(new DisplayMode(WIDTH,HEIGHT));
    Display.create(new PixelFormat(), attribs);
    } catch (LWJGLException e) {
    glViewport(0, 0, WIDTH, HEIGHT);

Similar Threads

  1. glDrawArrays not rendering -LWJGL
    By Plaigon in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-16-2017, 02:39 AM
  2. Weird lighting bug with software rendering
    By Don't Disturb in forum OpenGL: Windows
    Replies: 1
    Last Post: 01-30-2012, 04:20 AM
  3. Flickering "Box" with weird texture in center
    By f00dl3 in forum OpenGL: Windows
    Replies: 0
    Last Post: 05-26-2008, 08:29 PM
  4. Weird rendering problem in certain computers
    By Elias C. in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 11-29-2007, 05:54 AM
  5. Weird rendering behaviour
    By NTBone in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 04-14-2004, 09:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean