Derived From:BView
Mix-in Classes:None
Declared In:opengl/GLView.h
Class Overview

Constructor and Destructor


BGLView(BRect frame,
        const char* name,
        int32 resizingMode,
        int32 flags,
        int32 type);

Initializes the view, then creates a new OpenGL drawing context and attaches it to the view. The type argument specifies the OpenGL type specification for the view:



Use RGB graphics instead of indexed color (8-bit). This is the default if neither BGL_RGB nor BGL_INDEX is specified.


Use indexed color (8-bit graphics). Not currently supported.


Use single-buffering; all rendering is done directly to the display. This is not currently supported by the BeOS implementation of OpenGL. This is the default if neither BGL_SINGLE nor BGL_DOUBLE is specified.


Use double-buffered graphics. All rendering is done to an offscreen buffer and only becomes visible when the SwapBuffers() function is called.


Requests that the view have an accumulation buffer.


Requests that the view's color buffer include an alpha component.


Requests that the view have a depth buffer.


Requests that the view have a stencil buffer.


virtual ~BGLView();

Disposes of the OpenGL context for the view.

Member Functions


virtual void ~BGLView();

Calls the inherited version of AttachedToWindow() and sets the view color to B_TRANSPARENT_32_BIT (this improves performance by preventing the Application Server from erasing the view, since OpenGL takes over responsibility for drawing into the view).

CopyPixelsIn(), CopyPixelsOut()

status_t CopyPixelsIn(BBitmapsource,
                      BPoint dest);
status_t CopyPixelsOut(BPoint source,

These functions copy pixel data into and out of the OpenGL draw buffer for the context.

CopyPixelsIn() copies the entire contents of the source BBitmap into the OpenGL context, offset such that the top-left corner of the BBitmap is drawn at the point dest in the OpenGL buffer.

CopyPixelsOut() copies from the OpenGL draw buffer into the specified BBitmap. The area copied is the size of the dest bitmap and contains all data from the specified source point to the bottom-right corner of the buffer.


If the source is larger than the destination, it's clipped at the bottom and right edges to fit; no scaling is performed Also, the OpenGL context and the BBitmap must be in the same color space.

Return CodeDescription


The data was copied without error.


The current draw buffer is not valid, or the destination buffer's width or height is less than or equal to zero.


The source and destination are in different color spaces.


void DirectConnected(direct_buffer_info* directInfo);

If the BGLView is in a BDirectWindow, you should call this from your BDirectWindow::DirectConnected() function to let OpenGL update the window properly.


virtual void Draw(BRect updateRect);

Refreshes the contents of the BGLView by copying the frontbuffer to the screen.

If the view's color space is eight bits deep and the GL_DITHER OpenGL option is enabled, the display is dithered.



Returns a pointer to an embedded view that encompasses the current OpenGL drawing buffer, as defined by OpenGL, for the BGLView. If the view is single-buffered, this will be the frontbuffer, and if the view is double-buffered, the embedded view will encompass the backbuffer.


EmbeddedView() returns NULL if, for any reason, BView functions can't be used in the GL buffer. Starting with BeOS R4, this function always returns NULL, as the new, high-performance implementation of OpenGL does not support tinkering with the view.


void EnableDirectMode(bool enabled);

Call this function to tell the BGLView whether or not it should render in direct mode. If you're using a BDirectWindow and want video refreshes to be done through the direct window method, pass true for enabled. If you don't want to use the direct window method, pass false.


virtual void ErrorCallback(GLenum errorCode);

Called when an OpenGL error occurs. By default, this function invokes the debugger with an error message reading "GL: Error code $xxxx." You can (and probably should) reimplement this function to cope with errors more gracefully.


virtual void FrameResized(float width,
                          float height);

Calls the inherited version of FrameResized(), releases tables that need to be recalculated, and resizes the OpenGL buffers.

You can augment this function to perform other necessary tasks, such as adjusting your BGLView's coordinate system.

LockGL(), UnlockGL()

void LockGL();void UnlockGL();

These functions lock and unlock the OpenGL context. You must lock the context before issuing any OpenGL commands, and unlock it when you're done—this is how OpenGL knows which context the drawing commands are intended for, since OpenGL itself isn't encapsulated within the BGLView class. For example:

LockGL();            /* lock the OpenGL context
glEnable(GL_DITHER); /* turn on dithering support */

Failing to lock and unlock the context appropriately will result in unpredictable behavior and may cause your application to crash.


void SwapBuffers(); void SwapBuffers(bool vSync);

Swaps the front buffer and back buffer, then redraws the contents of the BGLView.

This function has no effect if the view is single-buffered.

If vSync is specified and is true, the swap is synchronized with vertical blanking.

Creative Commons License
Legal Notice
This work is licensed under a Creative Commons Attribution-Non commercial-No Derivative Works 3.0 License.