FLTK logo

[master] da66e21 - Support of FLTK widgets in OpenGL 3 windows - cont'd. This commit allows to switch between FL_DOUBLE / FL_SINGLE modes in widget-containing GL3 windows. Demo program examples/OpenGL3test is modified to show FLTK widgets even if the platform does not support OpenGL 3.

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] da66e21 - Support of FLTK widgets in OpenGL 3 windows - cont'd. This commit allows to switch between FL_DOUBLE / FL_SINGLE modes in widget-containing GL3 windows. Demo program examples/OpenGL3test is modified to show FLTK widgets even if the platform does not support OpenGL 3. "ManoloFLTK" Sep 29, 2022  
 
commit da66e21e1d5826639da2b8d3bd5ccd27920a4aad
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Thu Sep 29 09:39:21 2022 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Thu Sep 29 09:39:21 2022 +0200

    Support of FLTK widgets in OpenGL 3 windows - cont'd.
    This commit allows to switch between FL_DOUBLE / FL_SINGLE modes
    in widget-containing GL3 windows.
    Demo program examples/OpenGL3test is modified to show FLTK widgets
    even if the platform does not support OpenGL 3.

 FL/gl.h                                         |  1 +
 examples/OpenGL3test.cxx                        | 22 ++++++++++++++--------
 src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx |  1 -
 src/gl_draw.cxx                                 | 14 +++++++++-----
 4 files changed, 24 insertions(+), 14 deletions(-)

diff --git FL/gl.h FL/gl.h
index 4579be2..a30d2ea 100644
--- FL/gl.h
+++ FL/gl.h
@@ -91,6 +91,7 @@ FL_EXPORT void gl_draw(const char*, int x, int y, int w, int h, Fl_Align);
 FL_EXPORT void gl_measure(const char*, int& x, int& y);
 FL_EXPORT void gl_texture_pile_height(int max);
 FL_EXPORT int  gl_texture_pile_height();
+FL_EXPORT void gl_texture_reset();
 
 FL_EXPORT void gl_draw_image(const uchar *, int x,int y,int w,int h, int d=3, int ld=0);
 
diff --git examples/OpenGL3test.cxx examples/OpenGL3test.cxx
index 40d0bf7..d9216c4 100644
--- examples/OpenGL3test.cxx
+++ examples/OpenGL3test.cxx
@@ -30,7 +30,7 @@
 #  endif
 #  include <GL/glew.h>
 #endif
-
+#include <FL/gl.h> // for gl_texture_reset()
 
 void add_output(const char *format, ...);
 
@@ -50,8 +50,7 @@ public:
     gl_version_major = 0;
   }
   void draw(void) {
-    if (gl_version_major < 3) return;
-    if (!shaderProgram) {
+    if (gl_version_major >= 3 && !shaderProgram) {
       GLuint  vs;
       GLuint  fs;
       int Mslv, mslv; // major and minor version numbers of the shading language
@@ -135,9 +134,11 @@ public:
     }
     glClearColor(0.08, 0.8, 0.8, 1.0);
     glClear(GL_COLOR_BUFFER_BIT);
-    GLfloat p[]={0,0};
-    glUniform2fv(positionUniform, 1, (const GLfloat *)&p);
-    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+    if (shaderProgram) {
+      GLfloat p[]={0,0};
+      glUniform2fv(positionUniform, 1, (const GLfloat *)&p);
+      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+    }
     Fl_Gl_Window::draw(); // Draw FLTK child widgets.
   }
   virtual int handle(int event) {
@@ -158,7 +159,12 @@ public:
       const uchar *glv = glGetString(GL_VERSION);
       add_output("GL_VERSION=%s\n", glv);
       sscanf((const char *)glv, "%d", &gl_version_major);
-      if (gl_version_major < 3) add_output("\nThis platform does not support OpenGL V3\n\n");
+      if (gl_version_major < 3) {
+        add_output("\nThis platform does not support OpenGL V3 :\n"
+                   "FLTK widgets will appear but the programmed "
+                   "rendering pipeline will not run.\n");
+        mode(mode() & !FL_OPENGL3);
+      }
       redraw();
     }
 
@@ -181,7 +187,7 @@ public:
     }
     return retval;
   }
-  void reset(void) { shaderProgram = 0; }
+  void reset(void) { shaderProgram = 0; gl_texture_reset(); }
 };
 
 
diff --git src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
index bb4c53d..3ee281b 100644
--- src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
+++ src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
@@ -27,7 +27,6 @@
 #include <FL/Fl_Image_Surface.H>
 #include <dlfcn.h>
 
-extern void gl_texture_reset();
 
 #ifdef __OBJC__
 @class NSOpenGLPixelFormat;
diff --git src/gl_draw.cxx src/gl_draw.cxx
index 3104f16..b786b83 100644
--- src/gl_draw.cxx
+++ src/gl_draw.cxx
@@ -319,11 +319,6 @@ int gl_texture_fifo::already_known(const char *str, int n)
 
 static gl_texture_fifo *gl_fifo = NULL; // points to the texture pile class instance
 
-void gl_texture_reset()
-{
-  if (gl_fifo) gl_texture_pile_height(gl_texture_pile_height());
-}
-
 
 // Cross-platform implementation of the texture mechanism for text rendering
 // using textures with the alpha channel only.
@@ -465,6 +460,15 @@ int gl_texture_pile_height(void)
   return gl_fifo->size();
 }
 
+/** To call after GL operations that may invalidate textures used to draw text in GL scenes
+ (e.g., switch between FL_DOUBLE / FL_SINGLE modes).
+ */
+void gl_texture_reset()
+{
+  if (gl_fifo) gl_texture_pile_height(gl_texture_pile_height());
+}
+
+
 /**
  Changes the maximum height of the pile of pre-computed string textures
 
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.