Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Weird flickering when rendering with lwjgl

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2015
    Posts
    4

    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.

    https://www.youtube.com/watch?v=_Jae2Zf7IkQ

    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);
     
    //temporary
    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();
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getBaseId());
     
        GL30.glBindVertexArray(model.getVaoId());
     
        GL20.glEnableVertexAttribArray(0);
        GL20.glEnableVertexAttribArray(1);
        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);
        GL20.glDisableVertexAttribArray(0);
        GL20.glDisableVertexAttribArray(1);
        GL30.glBindVertexArray(0);
    }

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,223
    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
    Posts
    4
    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 Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,223
    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
    Posts
    4
    I tried the thing with the lighting but the flickering remains. So I uploaded a video where it can be seen a bit better.

    https://www.youtube.com/watch?v=xgQK-KLI_6U

    Anyways thanks for the help.

  6. #6
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,223
    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:

    * https://www.opengl.org/wiki/Swap_Interval

    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
    Posts
    4
    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.setTitle("Test");
    Display.create(new PixelFormat(), attribs);
    Display.setSwapInterval(1);
    } catch (LWJGLException e) {
    e.printStackTrace();
    }
    glViewport(0, 0, WIDTH, HEIGHT);
    glEnable(GL_DEPTH_TEST);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •