How to get/set the width and height of the default

2019-04-10 03:31发布

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?

1条回答
做自己的国王
2楼-- · 2019-04-10 04:18

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];
查看更多
登录 后发表回答