summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2017-05-11 11:44:06 +0000
committerGreg Ercolano <erco@seriss.com>2017-05-11 11:44:06 +0000
commit039beaf26a54f07821f5e9306ec9369275fd1779 (patch)
tree706b2b4e1b6fd351705ea01a7dd1de8e9e1940b8 /src
parent39b2976f887e1dda102ad48ca045a09b89c70c27 (diff)
Added some example code to Fl_Gl_Window::draw() docs..
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12235 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Gl_Window.cxx40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx
index ac445e1d0..285f01729 100644
--- a/src/Fl_Gl_Window.cxx
+++ b/src/Fl_Gl_Window.cxx
@@ -342,7 +342,7 @@ void Fl_Gl_Window::draw_overlay() {}
#endif // HAVE_GL
- /** Draws the Fl_Gl_Window.
+/** Draws the Fl_Gl_Window.
You \e \b must subclass Fl_Gl_Window and provide an implementation for
draw(). You may also provide an implementation of draw_overlay()
if you want to draw into the overlay planes. You can avoid
@@ -356,6 +356,44 @@ void Fl_Gl_Window::draw_overlay() {}
If double-buffering is enabled in the window, the back and front
buffers are swapped after this function is completed.
+
+ The following pseudo-code shows how to use "if (!valid())"
+ to initialize the viewport:
+
+ \code
+ void mywindow::draw() {
+ if (!valid()) {
+ glViewport(0,0,pixel_w(),pixel_h());
+ glFrustum(...) or glOrtho(...)
+ ...other initialization...
+ }
+ if (!context_valid()) {
+ ...load textures, etc. ...
+ }
+ // clear screen
+ glClearColor(...);
+ glClear(...);
+ ... draw your geometry here ...
+ }
+ \endcode
+
+ Actual example code to clear screen to black and draw a 2D white "X":
+ \code
+ void mywindow::draw() {
+ if (!valid()) {
+ glLoadIdentity();
+ glViewport(0,0,w(),h());
+ glOrtho(-w(),w(),-h(),h(),-1,1);
+ }
+ // Clear screen
+ glClear(GL_COLOR_BUFFER_BIT);
+ // Draw white 'X'
+ glColor3f(1.0, 1.0, 1.0);
+ glBegin(GL_LINE_STRIP); glVertex2f(w(), h()); glVertex2f(-w(),-h()); glEnd();
+ glBegin(GL_LINE_STRIP); glVertex2f(w(),-h()); glVertex2f(-w(), h()); glEnd();
+ }
+ \endcode
+
*/
void Fl_Gl_Window::draw() {
#ifdef FL_CFG_GFX_OPENGL