Use wxGLAttributes instead of int[] in cube OpenGL sample
This is slightly more readable. Also test for stereo support before trying to create a window using it.
This commit is contained in:
parent
30e79481a8
commit
be1807f29b
2 changed files with 26 additions and 20 deletions
|
|
@ -309,29 +309,27 @@ wxBEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
|||
EVT_TIMER(SpinTimer, TestGLCanvas::OnSpinTimer)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, int *attribList)
|
||||
TestGLCanvas::TestGLCanvas(wxWindow *parent, bool useStereo)
|
||||
// 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.
|
||||
: wxGLCanvas(parent, wxID_ANY, attribList,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxFULL_REPAINT_ON_RESIZE),
|
||||
m_xangle(30.0),
|
||||
: m_xangle(30.0),
|
||||
m_yangle(30.0),
|
||||
m_spinTimer(this,SpinTimer),
|
||||
m_useStereo(false),
|
||||
m_useStereo(useStereo),
|
||||
m_stereoWarningAlreadyDisplayed(false)
|
||||
{
|
||||
if ( attribList )
|
||||
wxGLAttributes attribs = wxGLAttributes().Defaults();
|
||||
if ( useStereo )
|
||||
attribs.Stereo();
|
||||
attribs.EndList();
|
||||
|
||||
if ( !wxGLCanvas::Create(parent, attribs, wxID_ANY,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxFULL_REPAINT_ON_RESIZE) )
|
||||
{
|
||||
int i = 0;
|
||||
while ( attribList[i] != 0 )
|
||||
{
|
||||
if ( attribList[i] == WX_GL_STEREO )
|
||||
m_useStereo = true;
|
||||
++i;
|
||||
}
|
||||
wxLogError("Creating OpenGL window failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -458,9 +456,7 @@ wxEND_EVENT_TABLE()
|
|||
MyFrame::MyFrame( bool stereoWindow )
|
||||
: wxFrame(nullptr, wxID_ANY, "wxWidgets OpenGL Cube Sample")
|
||||
{
|
||||
int stereoAttribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_STEREO, 0 };
|
||||
|
||||
new TestGLCanvas(this, stereoWindow ? stereoAttribList : nullptr);
|
||||
new TestGLCanvas(this, stereoWindow);
|
||||
|
||||
SetIcon(wxICON(sample));
|
||||
|
||||
|
|
@ -481,7 +477,8 @@ MyFrame::MyFrame( bool stereoWindow )
|
|||
Show();
|
||||
|
||||
// test IsDisplaySupported() function:
|
||||
static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
||||
wxGLAttributes attribs;
|
||||
attribs.RGBA().DoubleBuffer().EndList();
|
||||
wxLogStatus("Double-buffered display %s supported",
|
||||
wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
||||
|
||||
|
|
@ -508,5 +505,14 @@ void MyFrame::OnNewWindow( wxCommandEvent& WXUNUSED(event) )
|
|||
|
||||
void MyFrame::OnNewStereoWindow( wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
new MyFrame(true);
|
||||
wxGLAttributes attribs;
|
||||
attribs.RGBA().DoubleBuffer().Stereo().EndList();
|
||||
if ( wxGLCanvas::IsDisplaySupported(attribs) )
|
||||
{
|
||||
new MyFrame(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogError("Stereo not supported by OpenGL on this system, sorry.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ private:
|
|||
class TestGLCanvas : public wxGLCanvas
|
||||
{
|
||||
public:
|
||||
TestGLCanvas(wxWindow *parent, int *attribList = nullptr);
|
||||
TestGLCanvas(wxWindow *parent, bool useStereo);
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue