Revision: 78278
          http://sourceforge.net/p/brlcad/code/78278
Author:   starseeker
Date:     2021-02-19 00:44:32 +0000 (Fri, 19 Feb 2021)
Log Message:
-----------
Add a save image feature, demonstrate how to force an exact pixel size for the 
OpenGL window.

Modified Paths:
--------------
    brlcad/trunk/src/isst/isstgl.cpp
    brlcad/trunk/src/isst/isstgl.h
    brlcad/trunk/src/isst/main.cpp
    brlcad/trunk/src/isst/main_window.cpp
    brlcad/trunk/src/isst/main_window.h

Modified: brlcad/trunk/src/isst/isstgl.cpp
===================================================================
--- brlcad/trunk/src/isst/isstgl.cpp    2021-02-18 23:48:45 UTC (rev 78277)
+++ brlcad/trunk/src/isst/isstgl.cpp    2021-02-19 00:44:32 UTC (rev 78278)
@@ -105,17 +105,11 @@
     // Set up a QImage with the rendered output.  Note - sizeof(camera_tile_t)
     // offset copied from glTexSubImage2D setup in Tcl/Tk gui.  Without it, the
     // image is offset to the right in the OpenGL display.
-    QImage *image = new QImage(buffer_image.data + sizeof(camera_tile_t), 
camera.w, camera.h, QImage::Format_RGB888);
+    QImage image(buffer_image.data + sizeof(camera_tile_t), camera.w, 
camera.h, QImage::Format_RGB888);
 
     // Get the QImage version of the buffer displayed: 
https://stackoverflow.com/a/51666467
     QPainter painter(this);
-    painter.drawImage(this->rect(), *image);
-
-#if 0
-    // If we need to debug the above, we can write out an image
-    if (!image->save("file.png"))
-       printf("save failed!\n");
-#endif
+    painter.drawImage(this->rect(), image);
 }
 
 
@@ -180,6 +174,10 @@
 }
 
 
+void isstGL::save_image() {
+    QImage image = this->grabFramebuffer();
+    image.save("file.png");
+}
 
 // Local Variables:
 // tab-width: 8

Modified: brlcad/trunk/src/isst/isstgl.h
===================================================================
--- brlcad/trunk/src/isst/isstgl.h      2021-02-18 23:48:45 UTC (rev 78277)
+++ brlcad/trunk/src/isst/isstgl.h      2021-02-19 00:44:32 UTC (rev 78278)
@@ -19,8 +19,13 @@
  */
 /** @file isstgl.h
  *
- * Brief description
+ * OpenGL widget wrapper encoding the information specific to the
+ * TIE raytracing view.
  *
+ * TODO:  Look at f_knob, knob_rot, mged_vrot_syz, mged_rot, etc.
+ * to determine how MGED is doing its mouse x,y delta to view
+ * manipulation translation logic.
+ *
  */
 
 #ifndef ISSTGL_H
@@ -47,6 +52,8 @@
        struct render_camera_s camera;
        int resolution = 20;
 
+       void save_image();
+
        vect_t camera_pos_init;
        vect_t camera_focus_init;
 

Modified: brlcad/trunk/src/isst/main.cpp
===================================================================
--- brlcad/trunk/src/isst/main.cpp      2021-02-18 23:48:45 UTC (rev 78277)
+++ brlcad/trunk/src/isst/main.cpp      2021-02-19 00:44:32 UTC (rev 78278)
@@ -56,9 +56,24 @@
        app.load_g(filename, argc, (const char **)argv);
     }
 
+    // This is an illustration of how to force an exact size for
+    // the OpenGL canvas.  Useful when we need a framebuffer window
+    // to exactly match a specified size.
+    QSize cminsize = app.w.canvas->minimumSize();
+    QSize cmaxsize = app.w.canvas->maximumSize();
+    app.w.canvas->setMinimumSize(1100,800);
+    app.w.canvas->setMaximumSize(1100,800);
+    app.w.canvas->updateGeometry();
+
     // Draw the window
     app.w.show();
 
+    // Having forced the size we wanted, restore the original settings
+    // to allow for subsequent change (if it would have been allowed
+    // by the original settings.)
+    app.w.canvas->setMinimumSize(cminsize);
+    app.w.canvas->setMaximumSize(cmaxsize);
+
     return app.exec();
 }
 

Modified: brlcad/trunk/src/isst/main_window.cpp
===================================================================
--- brlcad/trunk/src/isst/main_window.cpp       2021-02-18 23:48:45 UTC (rev 
78277)
+++ brlcad/trunk/src/isst/main_window.cpp       2021-02-19 00:44:32 UTC (rev 
78278)
@@ -38,6 +38,10 @@
     connect(isst_open, &QAction::triggered, this, &ISST_MainWindow::open_file);
     file_menu->addAction(isst_open);
 
+    isst_save_image = new QAction("Save Image", this);
+    connect(isst_save_image, &QAction::triggered, this, 
&ISST_MainWindow::save_image);
+    file_menu->addAction(isst_save_image);
+
     isst_save_settings = new QAction("Save Settings", this);
     connect(isst_save_settings, &QAction::triggered, this, 
&ISST_MainWindow::write_settings);
     file_menu->addAction(isst_save_settings);
@@ -92,7 +96,13 @@
     settings.endGroup();
 }
 
+void ISST_MainWindow::save_image()
+{
+    canvas->save_image();
+}
 
+
+
 /*
  * Local Variables:
  * mode: C++

Modified: brlcad/trunk/src/isst/main_window.h
===================================================================
--- brlcad/trunk/src/isst/main_window.h 2021-02-18 23:48:45 UTC (rev 78277)
+++ brlcad/trunk/src/isst/main_window.h 2021-02-19 00:44:32 UTC (rev 78278)
@@ -51,10 +51,12 @@
     private slots:
        void open_file();
        void write_settings();
+       void save_image();
 
     private:
        QMenu *file_menu;
        QAction *isst_open;
+       QAction *isst_save_image;
        QAction *isst_save_settings;
        QAction *isst_exit;
 };

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to