A window may also have a canvas for rendering. Each window can only have one canvas. Canvas defines all window specific rendering properties for the window, such as double buffering, bit maps and so on.
To create a window with a double buffered canvas, call:
subwin = R3New(R3CLID_WINDOW, R3WA_CanvasClass, R3CLID_OPENGL, R3WA_CanvasFlags, R3WACF_TRUECOLOR | R3WACF_DOUBLEBUFFER, R3TAG_END);
This creates a double buffered OpenGL canvas for the window.
Each canvas defines one or more draw port. Drawports act as a thread specific handles to the canvas. By default one drawport is created, for the main thread.
The application (the main thread) can render to the window by calling:
// fetch the default draw port R3GetAttrs(window, R3WA_DrawPort, &dc, R3TAG_END); // draw something R3DoA2(dc, R3DCM_LINE, &p0, &p1);
It is also possible to create several threads, which can all render to a single window simultaneously. However, each thread must create a private drawport to the canvas by calling
R3GetAttrs(window, R3WA_Canvas, &canvas, R3TAG_END); // create a drawport for the current thread thread_dc = R3SendMsgA(canvas, R3CM_NEWDRAWCONTEXT, NULL);
It is also possible to copy an existing draw port. This way you don't have to set all the rendering options for the copy.
// fetch the canvas and the main thread's draw port R3GetAttrs(window, R3WA_Canvas, &canvas, R3WA_DrawPort, &dc, R3TAG_END); // create a drawport for the current thread thread_dc = R3DoA(canvas, R3CM_COPYDRAWCONTEXT, dc);
![]() |
Important |
---|---|
Only the thread that called R3CM_COPYDRAWCONTEXT or R3CM_NEWDRAWCONTEXT can use the created draw port! |
Note for class implementors: If you create windows that are not double buffered, you must still call R3DCM_SWAPBUFFERS. Mac OS X version depends on it!