LWJGL Forum

Programming => Bug Reports / RFE => Topic started by: jakethesnake on August 30, 2015, 08:33:35

Title: default framebuffer modification, stencil problems
Post by: jakethesnake on August 30, 2015, 08:33:35
Hi, I'm having some trouble with my default FB.

First of all, I'm having trouble setting its bitdepths. I do:

       glfwWindowHint(GLFW_RED_BITS, 8);
       glfwWindowHint(GLFW_GREEN_BITS, 8);
       glfwWindowHint(GLFW_BLUE_BITS, 8);
       glfwWindowHint(GLFW_ALPHA_BITS, 8);
       glfwWindowHint(GLFW_DEPTH_BITS, 8);
       glfwWindowHint(GLFW_STENCIL_BITS, 8);

But that doesn't change a thing, no matter what I set, before or after I've created the window.

Also glGetInteger yields:

FB stencil Bits: 1147955063
FB Red Bits: 1147955063
FB Green Bits: 1147955063
FB Blue Bits: 1147955063
FB Alpha Bits: 1147955063

Once the window is created. After 1 swapbuffer, it yields:

FB stencil Bits: 4
FB Red Bits: 4
FB Green Bits: 4
FB Blue Bits: 4
FB Alpha Bits: 4

This is very strange indeed. What I'd really like is to skip the hints and have access to this function:

glfwOpenWindow(FB specification)
http://www.glfw.org/GLFWReference27.pdf

The problem is that I'm trying to blit an FBO's stencil buffer to the default FB and am having no success. I can't really debug it either, since I don't know anything about the default FB's stencil buffer. The only thing that's really strange is that if I do a glGetInteger() for the stencil bits, before I do the blit, I get no error. (But it still doesn't work).
Title: Re: default framebuffer modification, stencil problems
Post by: spasi on August 31, 2015, 10:24:45
Also glGetInteger yields:

FB stencil Bits: 1147955063
FB Red Bits: 1147955063
FB Green Bits: 1147955063
FB Blue Bits: 1147955063
FB Alpha Bits: 1147955063

Once the window is created. After 1 swapbuffer, it yields:

FB stencil Bits: 4
FB Red Bits: 4
FB Green Bits: 4
FB Blue Bits: 4
FB Alpha Bits: 4

Sounds like the first time you call glGetInteger, it fails and there should be an OpenGL error. The weird value you see is probably whatever happens to be in the buffer that was supposed to receive the GetInteger value. Please use glGetError or an OpenGL debug callback to verify this.

If that doesn't help, please share your init code.

What I'd really like is to skip the hints and have access to this function:

glfwOpenWindow(FB specification)
http://www.glfw.org/GLFWReference27.pdf

That pdf is for GLFW 2.7, a very old version. LWJGL comes with GLFW 3.1 bindings, which has a very different API.
Title: Re: default framebuffer modification, stencil problems
Post by: jakethesnake on September 01, 2015, 06:25:00
Yes, indeed, I'm getting GL_INVALID_ENUM on checks. This shouldn't be so, right?

glfw init:

   void create(Core core, SETTINGS sett){
         if (isCreated){
          throw new RuntimeException(Context.class + " has Already been created!");
       }
         
       if (sett.getScale() != 1 && sett.getScale()% 2 != 0)
          throw new RuntimeException("scale must be a power of two!");
       
       scale = sett.getScale();
       nativeWidth = sett.getNativeWidth();
       nativeHeight = sett.getNativeHeight();
       displayWidth = sett.getDisplayWidth();
       displayHeight = sett.getDisplayHeight();
       trippleBuff = sett.getTripleBuffering();
       
       glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));
       if ( glfwInit() != GL11.GL_TRUE )
             throw new IllegalStateException("Unable to initialize GLFW");
       
       //window hints
       glfwDefaultWindowHints();
       glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE);
       glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE);
       glfwWindowHint(GLFW_DECORATED, GL11.GL_TRUE);
       glfwWindowHint(GLFW_FOCUSED, GL11.GL_FALSE);
       glfwWindowHint(GLFW_AUTO_ICONIFY, GL11.GL_FALSE);
       glfwWindowHint(GLFW_FLOATING, GL11.GL_FALSE);
       
       
       //FB hints
       glfwWindowHint(GLFW_RED_BITS, 8);
       glfwWindowHint(GLFW_GREEN_BITS, 8);
       glfwWindowHint(GLFW_BLUE_BITS, 8);
       glfwWindowHint(GLFW_ALPHA_BITS, 8);
       glfwWindowHint(GLFW_DEPTH_BITS, 8);
       glfwWindowHint(GLFW_STENCIL_BITS, 8);
       
       //other hints
       glfwWindowHint(GLFW_SAMPLES, 0);
       glfwWindowHint(GLFW_REFRESH_RATE, GLFW_DONT_CARE);
       glfwWindowHint(GLFW_STEREO, GL11.GL_FALSE);
       glfwWindowHint(GLFW_SRGB_CAPABLE,GL11.GL_FALSE);
       glfwWindowHint(GLFW_DOUBLE_BUFFER, GL11.GL_TRUE);
       glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
       glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
       glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
       glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, GLFW_NO_ROBUSTNESS);
       glfwWindowHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, GLFW_ANY_RELEASE_BEHAVIOR);
       glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
       glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL11.GL_TRUE);
       glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);

       
       setDisplayModes();
       
          window = glfwCreateWindow(
                sett.getDisplayWidth(), sett.getDisplayHeight(),
             sett.getWindowName(),
             sett.getFullScreen(fullScreenModes) ? glfwGetPrimaryMonitor() : NULL, NULL);
          
       if ( window == NULL ){
          throw new RuntimeException("Failed to create the GLFW window");
       }
       
       //get real width and height
       checkDimensions(sett);

       // Make the OpenGL context current
        glfwMakeContextCurrent(window);
       
        // creates the ContextCapabilities instance and makes the OpenGL
        // bindings available for use.
        GLContext.createFromCurrent();
       
       glfwSwapInterval(sett.getVSynch() ? 1 : 0);
       
        GlManager.init(sett.getNativeWidth(), sett.getNativeHeight());
       
       renderer = new Renderer(sett.getRenderMode());
       input = new Input(core, window, sett);
       
        soundManager = new SoundManager();
       
        isCreated = true;
       
        printout(sett);
       
    }

opengl init:

   static void init(int viewPortWidth, int viewPortHeight){
      
      GLContext.createFromCurrent();
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      
      glEnable(GL_BLEND);
      setBlendNormal();
      glDisable(GL_DEPTH_TEST);
      glEnable(GL_STENCIL_TEST);
      glClearStencil(~0);
      setViewPort(viewPortWidth, viewPortHeight);
      System.out.println("---OPEN_GL---");
      System.out.println("FB stencil Bits: " + glGetInteger(GL_STENCIL_BITS));
      System.out.println("FB Red Bits: " + glGetInteger(GL_RED_BITS));
      System.out.println("FB Green Bits: " + glGetInteger(GL_GREEN_BITS));
      System.out.println("FB Blue Bits: " + glGetInteger(GL_BLUE_BITS));
      System.out.println("FB Alpha Bits: " + glGetInteger(GL_ALPHA_BITS));
      System.out.println("OpenGL Version: " + glGetString(GL_VERSION));
      System.out.println("glRenderer: " + glGetString(GL_VENDOR) + ", " + glGetString(GL_RENDERER));
      ContextCapabilities c = org.lwjgl.opengl.GLContext.createFromCurrent().getCapabilities();
      System.out.println("Supported Shader Attributes: " + glGetInteger(GL20.GL_MAX_VERTEX_ATTRIBS));
      System.out.println("Supported Shader Uniforms: " + glGetInteger(GL20.GL_MAX_FRAGMENT_UNIFORM_COMPONENTS));
      if (!c.GL_ARB_shader_objects && c.GL_ARB_vertex_shader && c.GL_ARB_fragment_shader)
                 throw new IllegalStateException("shaders arent Supported. Get openGl 2.0 or later!");
   }
Title: Re: default framebuffer modification, stencil problems
Post by: spasi on September 01, 2015, 09:03:50
This is correct behavior because you have set:

Code: [Select]
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
and you're getting a forward compatible context. Context framebuffer size queries have been deprecated in the core profile. The correct code is:

Code: [Select]
System.out.println("FB stencil Bits: " + glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE));
System.out.println("FB Red Bits: " + glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_FRONT, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE));
System.out.println("FB Green Bits: " + glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_FRONT, GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE));
System.out.println("FB Blue Bits: " + glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_FRONT, GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE));
System.out.println("FB Alpha Bits: " + glGetFramebufferAttachmentParameteri(GL_FRAMEBUFFER, GL_FRONT, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE));
Title: Re: default framebuffer modification, stencil problems
Post by: jakethesnake on September 01, 2015, 12:34:44
Thank you