From 039beaf26a54f07821f5e9306ec9369275fd1779 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Thu, 11 May 2017 11:44:06 +0000 Subject: [PATCH] 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 --- src/Fl_Gl_Window.cxx | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) 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