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?
width is the width of the FrameBuffer in pixels. height is the height of the FrameBuffer in pixels. format specifies the type of pixel used in the FrameBuffer; permissible values are listed under Constants below. These set the number of bits used to encode a color value and the layout of these bits in buffer.
A Framebuffer is a collection of buffers that can be used as the destination for rendering. OpenGL has two kinds of framebuffers: the Default Framebuffer, which is provided by the OpenGL Context; and user-created framebuffers called Framebuffer Objects (FBOs).
First thing to do is to create an actual framebuffer object and bind it, this is all relatively straightforward: unsigned int framebuffer; glGenFramebuffers (1, &framebuffer); glBindFramebuffer (GL_FRAMEBUFFER, framebuffer); Next we create a texture image that we attach as a color attachment to the framebuffer.
The front buffer is what the screen displays, while the back buffer is where you render to until the frame is complete.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With