OpenGL and 2.9.2 Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Scorcher24
Earned some good credits
Earned some good credits
Posts: 128
Joined: Sat Sep 25, 2004 9:11 pm
Location: Nuremberg, Germany
Contact:

OpenGL and 2.9.2

Post by Scorcher24 »

Was there any significant change?
I don't get the context working.

I have tried this minimal sample:

Code: Select all

#include <wx/wx.h>
#include <wx/glcanvas.h>

class wxMyCanvas : public wxGLCanvas
{
public:
    wxMyCanvas(wxWindow* parent, int* attribList)
        : wxGLCanvas(parent, -1, attribList, wxDefaultPosition, wxSize(800,600))
    {}

    virtual ~wxMyCanvas()
    {
        delete m_context;
    }

    void MyInit()
    {
        m_context = new wxGLContext(this);
    }

    void PaintIt(wxPaintEvent& e)
    {
        //wxPaintDC(this);
        Render();
    }

    void Idle(wxIdleEvent& e)
    {
        Render();
        e.RequestMore(true);
    }

    void Render()
    {
        //this->SetCurrent(*m_context);
        glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
        //glFinish();
        this->SwapBuffers();
    }

    void dumpOpenGLInfo()
    {
        // OpenGL
        char* gl_ven    = (char*)glGetString(GL_VENDOR);
        char* gl_ver    = (char*)glGetString(GL_VERSION);
        char* gl_render = (char*)glGetString(GL_RENDERER);

        wxString s;
        s.Printf("Version: %s", gl_ver);
        wxMessageBox(s);
    }

private:
    wxGLContext* m_context;
    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(wxMyCanvas, wxGLCanvas)
    EVT_PAINT(wxMyCanvas::PaintIt)
    EVT_IDLE(wxMyCanvas::Idle)
END_EVENT_TABLE()


class Application : public wxApp
{
public:
    virtual bool OnInit()
    {
        wxFrame* frame = new wxFrame(NULL, -1, "wxGLTest", wxDefaultPosition, wxSize(800,600));
        wxMyCanvas* canvas = new wxMyCanvas(frame, NULL);
        canvas->MyInit();
        canvas->dumpOpenGLInfo();
        frame->Show();
        SetTopWindow(frame);
        return true;
    }
};

IMPLEMENT_APP(Application);
The context remains white.
Is this me or is this broken in 2.9.2?
Can anyone test it please?
glGetString(GL_VERSION) remains NULL....
I have tried it with and without the commented sections, sticking to this sample:
http://wiki.wxwidgets.org/WxGLCanvas
OS: Windows 7 Ultimate 64bit
IDE: VC++ 2008 Professional
WX: 2.9.2
My Projects
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: OpenGL and 2.9.2

Post by doublemax »

Please try with one of the OpenGL samples that come with wxWidgets.
Use the source, Luke!
schmmichael
Experienced Solver
Experienced Solver
Posts: 96
Joined: Fri Jan 19, 2007 10:38 am
Location: Switzerland

Re: OpenGL and 2.9.2

Post by schmmichael »

Hi,

I'm using a trunk version, about 1 week before the official release of 2.9.2.
I didn't get any change in the behaviour of the openGL part since 2.9.1

What happens if you try your sample?

Michael
Scorcher24
Earned some good credits
Earned some good credits
Posts: 128
Joined: Sat Sep 25, 2004 9:11 pm
Location: Nuremberg, Germany
Contact:

Re: OpenGL and 2.9.2

Post by Scorcher24 »

The samples work.
But not my code.
I made this self-made minimal sample, because I had problems with my own context. See my other Thread.
I really don't understand whats wrong.
OS: Windows 7 Ultimate 64bit
IDE: VC++ 2008 Professional
WX: 2.9.2
My Projects
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: OpenGL and 2.9.2

Post by Auria »

Comparing with http://wiki.wxwidgets.org/WxGLCanvas#wxGLCanvas_sample , maybe you lack a call to SetCurrent
"Keyboard not detected. Press F1 to continue"
-- Windows
Scorcher24
Earned some good credits
Earned some good credits
Posts: 128
Joined: Sat Sep 25, 2004 9:11 pm
Location: Nuremberg, Germany
Contact:

Re: OpenGL and 2.9.2

Post by Scorcher24 »

It is in void Render(). I tried it with and without this call.
OS: Windows 7 Ultimate 64bit
IDE: VC++ 2008 Professional
WX: 2.9.2
My Projects
schmmichael
Experienced Solver
Experienced Solver
Posts: 96
Joined: Fri Jan 19, 2007 10:38 am
Location: Switzerland

Re: OpenGL and 2.9.2

Post by schmmichael »

Hi,

I had the same problems during my first steps with opengl.

Now I'm doing it on the following way: (it's taken from a sample ...)

Canvas:

Code: Select all

/*!
 * Constructor
 */
OpenGLCanvas::OpenGLCanvas(wxWindow *parent)
    : wxGLCanvas(parent, wxID_ANY, NULL ,/* attribs */
                 wxDefaultPosition, wxDefaultSize,wxFULL_REPAINT_ON_RESIZE)
{

	//
    // With perspective OpenGL graphics, the wxFULL_REPAINT_ON_RESIZE style
    // flag should always be set, because even making the canvas smaller should
    // be followed by a paint event that updates the entire canvas with new
    // viewport settings.
	//
	oGLContext_ = NULL;//new OpenGLContext(this,this->GetSize());

}// OpenGLCanvas::OpenGLCanvas

Code: Select all

/*!
 * Returns a valid context for an OpenGL context
 */
OpenGLContext& OpenGLCanvas::getContext(OpenGLCanvas *canvas)
{

    if ( !oGLContext_ )
    {
    	//
        // Create the OpenGL context for the first window which needs it:
        // subsequently created windows will all share the same context.
    	//
    	oGLContext_ = new OpenGLContext(canvas,this->GetClientSize());
    }

    oGLContext_->SetCurrent(*canvas);

    return *oGLContext_;
}// OpenGLContext& OpenGLCanvas::getContext(...

Code: Select all

/*!
 * onPaint is used if we resize the vis::basic::2D frame
 */
void OpenGLCanvas::onPaint(wxPaintEvent& WXUNUSED(event))
{
	//
	// This is required even though dc is not used otherwise.
	//
	std::cout << "OnPaintEvent\n";
	wxPaintDC dc(this);

	OpenGLContext& ct = getContext(this);
	ct.setClientSize(this->GetClientSize());

	if (plotType_.compare("line")==0){
		std::cout << "Plottype line chosen\n";
	    ct.plot(x_,y_);

	}else {
		if (plotType_.compare("plot")==0 )
			; // nothing to do because this plottype doesn't exist till now!
		else{

			if (plotType_.compare("perfplot")==0 )
				ct.perfPlot(y_);
				//getContext(this).perfPlot(y_);
			else
				std::cout << "openGLCanvas.cpp: onPaint: The chosen plot type is not available\n";
		}
	}

    SwapBuffers();

}// void OpenGLCanvas::onPaint(...
And the context constuctor looks like this:

Code: Select all

/*!
 * Constructor
 */
OpenGLContext::OpenGLContext(OpenGLCanvas *canvas, wxSize clientSize)
             : wxGLContext(canvas)
{
	//
	// Init pointers
	//
	title_ = new Title();

	//
	// Set some member variables
	//
	cs_.x = clientSize.x;
	cs_.y = clientSize.y;

	this->defaultValues();

	//
	// Bind the context to the canvas
	//
	SetCurrent(*canvas);

    //
    // Check for errors in the OpenGL code
    //
    CheckGLError();

#ifdef __WXMSW__
    pFont = new FTPolygonFont("C:\\WINDOWS\\Fonts\\ARIAL.TTF");
#else
    ///\todo check for a general version how to search the fonts on a linux system ..
    pFont = new FTPolygonFont("/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf");
#endif
}// OpenGLContext::OpenGLContext(...
I hope you can figure out the code you need.

Michael
Scorcher24
Earned some good credits
Earned some good credits
Posts: 128
Joined: Sat Sep 25, 2004 9:11 pm
Location: Nuremberg, Germany
Contact:

Re: OpenGL and 2.9.2

Post by Scorcher24 »

Wasn't able to solve it.. solved my main problem though with my own OpenGL control, but I can't get this one to work. I don't know why this happens :D.
Anyway, solved my main problem.
OS: Windows 7 Ultimate 64bit
IDE: VC++ 2008 Professional
WX: 2.9.2
My Projects
Post Reply