Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » [BUG] GL canvas gone missing...
[BUG] GL canvas gone missing... [message #50428] Sun, 28 October 2018 06:30 Go to next message
ptkacz is currently offline  ptkacz
Messages: 89
Registered: March 2017
Member
Below is a simple application where a U++ program displays a main window with a popup context menu. When right clicking on the application window, a popup context menu displays listing the option, "Show GL Dialog". Upon selection of the, "Show GL Dialog" menu item, a dialog window displays with the title, "GL Dialog" and a black background.

When minimizing the main window, both main window and dialog minimize. When selecting the application within the task bar, both main window and dialog window are re-displayed upon the desktop window.

Now if one closes the dialog window and then relaunches the dialog window with the right context menu option (i.e. "Show GL Dialog"), the GL Dialog window re-displays, but the GL canvas no longer displays, just a blank grey area.

Just an update, I've added the virtual method Paint() (i.e. virtual void Paint(Draw& w) { canvasGL.GLPaint(); }) to the DialogGL class, but this just results in a screen shot under where the dialog window is launched, displaying within the dialog window. In addition, I've also attempted to set the size of the GL canvas view port, but with no luck either. It's strange that initially when the dialog window is launched, the canvas is properly sized and displayed, but when the dialog window is closed, it doesn't come back.

Why is this so? How does one get the GL canvas to re-display?

Example U++ App:
index.php?t=getfile&id=5683&private=0


GLPlay2.lay layout file:
LAYOUT(GLPlay2Layout, 200, 100)
END_LAYOUT

LAYOUT(GLDialogLayout, 400, 200)
END_LAYOUT


main.cpp:
#include <CtrlLib/CtrlLib.h>
#include <GLDraw/GLDraw.h>
#include <GLCtrl/GLCtrl.h>
using namespace Upp;


#define LAYOUTFILE <GLPlay2/GLPlay2.lay>
#include <CtrlCore/lay.h>


struct CanvasGL : GLCtrl {
    typedef CanvasGL CLASSNAME;

    virtual void GLPaint() {
        StdView();

         glLoadIdentity();
        glShadeModel(GL_SMOOTH);
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // glClearDepth(1.0f);
    }

    virtual void GLResize(int w, int h) {
        glViewport(0, 0, (GLsizei)w, (GLsizei)h);
    }
};



struct DialogGL : public WithGLDialogLayout<TopWindow> {
    typedef DialogGL CLASSNAME;

    DialogGL() {
        CtrlLayout(*this, "GL Dialog");
        Size sz = GetSize();
        canvasGL.SetRect(0, 0, sz.cx-1, sz.cy-1);
        Add(canvasGL);
    }

    void open() {
        if(!IsOpen()) {
            Open();
        }
    }

    void close() {
        if(IsOpen()) {
            Close();
        }
    }

private:
    CanvasGL canvasGL;
};



class GLPlay2 : public WithGLPlay2Layout<TopWindow> {
public:
    typedef GLPlay2 CLASSNAME;

    GLPlay2() {
        CtrlLayout(*this, "Main App Window");
        dialogGL = new DialogGL();
    }

    ~GLPlay2() {
        delete dialogGL;
    }

    void RightDown(Point, dword) {
        MenuBar::Execute(
            [=](Bar& bar) {
                bar.Add("Show GL Dialog", [=] { displayDialog(); });
            }
        );
    }

    void displayDialog() {
        dialogGL->open();
    }


private:
    DialogGL* dialogGL;
};


GUI_APP_MAIN
{
    GLPlay2().Run();
}

  • Attachment: SimpleApp.png
    (Size: 47.75KB, Downloaded 381 times)

[Updated on: Sun, 04 November 2018 20:08]

Report message to a moderator

Re: [BUG] GL canvas gone missing... [message #50507 is a reply to message #50428] Mon, 12 November 2018 11:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hi, what U++ version are you using?

Accidentally, GLCtrl right now is under intense development... In fact, I am afraid that in GTK, it does not compile...

I hope to fix that this week and will check this issue in the process.

Mirek
Re: [BUG] GL canvas gone missing... [message #50508 is a reply to message #50507] Mon, 12 November 2018 11:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
P.S.: Layout is not requirement for top-level windows. If you do not need layout, as in this example, just derive from "public TopWindow"
Re: [BUG] GL canvas gone missing... [message #50526 is a reply to message #50507] Tue, 13 November 2018 01:31 Go to previous messageGo to next message
ptkacz is currently offline  ptkacz
Messages: 89
Registered: March 2017
Member
Thank's Merik!

I'm making use of the following version, upp-x11-src-11873.

I'll give just deriving from "public TopWindow" a try.

With the exception of the canvas gone missing, Klugier assisted me with getting OpenGL working a while back. Because of the following issue, I have to modify a couple of lines of code before building U++, in order to get OpenGL working.

Looking forward to any update!


Peter

[Updated on: Tue, 13 November 2018 01:44]

Report message to a moderator

Re: [BUG] GL canvas gone missing... [message #50611 is a reply to message #50526] Mon, 26 November 2018 11:51 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
ptkacz wrote on Tue, 13 November 2018 01:31

Looking forward to any update!


Peter


So after fixing GTK GLCtrl, I have tried your code and found that the problem was something else.

It is a bad idea to do layout in DialogGL::DialogGL - at that point, GetSize is likely to return something odd. The best here is to use SizePos.

Fixed code:

struct CanvasGL : GLCtrl {
    typedef CanvasGL CLASSNAME;

    virtual void GLPaint() {
        StdView();

        glLoadIdentity();
        glShadeModel(GL_SMOOTH);
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // glClearDepth(1.0f);
    }
};

struct DialogGL : public TopWindow {
    typedef DialogGL CLASSNAME;

    DialogGL() {
        Add(canvasGL.SizePos());
    }

    void open() {
        if(!IsOpen()) {
            Open();
        }
    }

    void close() {
        if(IsOpen()) {
            Close();
        }
    }

private:
    CanvasGL canvasGL;
};

Previous Topic: Automatic Build Methods setup - Does it find MinGW?
Next Topic: TopWindow Run on Background
Goto Forum:
  


Current Time: Thu Mar 28 13:39:37 CET 2024

Total time taken to generate the page: 0.01742 seconds