How to get/set the width and height of the default framebuffer?
Asked Answered
L

1

7

I want to know the dimension of my default frame buffer. I read setting view port to a particular value does not affect/set the dimensions of frame buffer. Are there any GL calls for this?

Lola answered 21/4, 2015 at 6:51 Comment(1)
It's the size of the window usually.Mello
C
10

You can't set the size of the default framebuffer with OpenGL calls. It is the size of the window, which is controlled by the window system interface (e.g. EGL on Android). If you want to control it, this has to happen as part of the initial window/surface/context setup, where the details are platform dependent.

I'm not aware of a call that specifically gets the size of the default framebuffer. But you can easily get it indirectly. Both the default values of the viewport and the scissor rectangle correspond to the size of the window. So if you get any of those before modifying them, it will give you the size of the window.

From section 2.12.1 "Controlling the Viewport" in the spec:

In the initial state, w and h are set to the width and height, respectively, of the window into which the GL is to do its rendering.

From section 4.1.2 "Scissor Test" in the spec:

In the initial state left = bottom = 0; width and height are determined by the size of the GL window.

So you can get the default framebuffer size with either:

GLint dims[4] = {0};
glGetIntegerv(GL_VIEWPORT, dims);
GLint fbWidth = dims[2];
GLint fbHeight = dims[3];

or:

GLint dims[4] = {0};
glGetIntegerv(GL_SCISSOR_BOX, dims);
GLint fbWidth = dims[2];
GLint fbHeight = dims[3];
Cognition answered 21/4, 2015 at 15:33 Comment(1)
I get all four zeros from glGetIntegerv, why is that? My window is actually 640*480.Booker

© 2022 - 2024 — McMap. All rights reserved.