LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Illari on August 05, 2019, 02:43:00

Title: Does LWJGL3 support creating a windowless OpenGL context?
Post by: Illari on August 05, 2019, 02:43:00
Hi,

I heard that you have to create a context without ever creating a window if you want to render to a Framebuffer Object larger than the screen size. Otherwise the contents of the Framebuffer Object get cropped by the window size, which can't be larger than the screen. This happens even if the window is hidden. There doesn't seem to be a sensible workaround to this besides not creating a window in the first place in any of the Stackoverflow answers on the topic.

Thanks for your time.
Title: Re: Does LWJGL3 support creating a windowless OpenGL context?
Post by: spasi on August 05, 2019, 08:01:45
Hey Illari,

You can create a hidden GLFW window and use its OpenGL context to render to a framebuffer object (https://www.khronos.org/opengl/wiki/Framebuffer_Object) of arbitrary size.
Title: Re: Does LWJGL3 support creating a windowless OpenGL context?
Post by: Illari on August 06, 2019, 17:56:57
Hi,

I edited the post to clarify that the image still gets cropped even if the window is hidden. Looks like I might need to draw it in pieces and move them afterwards.

Well unless there's a solution besides this one it's something to be aware of.
Title: Re: Does LWJGL3 support creating a windowless OpenGL context?
Post by: KaiHH on August 06, 2019, 18:18:16
As @spasi said, you need to create a Framebuffer Object and not render to the default (window-provided) framebuffer object 0. You need to create and bind a separate Framebuffer Object which you render to.
Title: Re: Does LWJGL3 support creating a windowless OpenGL context?
Post by: Illari on August 07, 2019, 03:17:25
That's what I did. Perhaps it's only on some systems?


glGenFramebuffers(fbuffer);
int framebuffer = fbuffer.get(0);

glBindFramebuffer(GL_DRAW_BUFFER, framebuffer);
Integer[] size = drawnauha(-1);
int w = size[0], h = size[1];
glBindBuffer(GL_RENDERBUFFER, buffer.get(1));
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32F, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, buffer.get(1));
glViewport(0, 0, w, h);