When I have two wxGLCanvas's with one parent wxFrame they don't show up until I resize, or move the window. Then they both show up fine.
EDIT: Additionally this problem exists if I create a wxFrame with a wxButton and wxGLCanvas in it.
On the other hand if I have only a single wxGLCanvas it shows up and starts drawing immediately just fine. For some reason it also set's the glViewport and resizes itself to the size of the parent wxFrame even though I may have set an explicit size for it (this isn't really a problem though).
The drawing code is in the idle event handler, so one thing that I thought to check for is whether it's not getting called initially when the app starts up. To my surprise it is, so that doesn't seem to be the problem.
Obviously what I'd like to have happen is for the wxGLCanvas's to start drawing right when the app starts.
What am I missing?
I'm on a mac 10.4.10, with wx 2.8.7 insstalled and I passed configure "--with-opengl --enable-debug"
heres my code:
main.cpp:
Code: Select all
#include "main.hpp"
IMPLEMENT_APP(App)
bool App::OnInit() {
Frame *frame = new Frame(NULL, wxID_ANY, wxString("Typing Mentr"), wxDefaultPosition, wxSize(300, 300));
frame->Show();
SetTopWindow(frame);
return 1;
}
Frame::Frame(wxWindow *rParent, wxWindowID rId, const wxString &rTitle, const wxPoint &rPos, const wxSize &rSize, long rStyle, const wxString &rName) : wxFrame(rParent, rId, rTitle, rPos, rSize, rStyle, rName) {
int attributeList[] = {
WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0
};
glCanvas = new wxGLCanvas(this, wxID_ANY, wxPoint(0, 0), wxSize(100, 100), 0, wxString("GLCanvas"), attributeList);
glCanvas2 = new wxGLCanvas(this, wxID_ANY, wxPoint(100, 100), wxSize(100, 100), 0, wxString("GLCanvas"), attributeList);
glContext = glCanvas->GetContext();
glContext2 = glCanvas2->GetContext();
glCanvas->Show();
glCanvas2->Show();
}
void Frame::on_close(wxCloseEvent &rEvent) {
Destroy();
}
void Frame::on_idle(wxIdleEvent &rEvent) {
float red, blue, green;
red = blue = green = 0.5;
wxBell(); //This makes some noise, so I know that it IS getting an initial idle event that the opengl drawing code depends on.
glCanvas->SetCurrent();
glViewport(0, 0, glCanvas->GetSize().GetWidth(), glCanvas->GetSize().GetHeight());
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(red, blue, green);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
glCanvas->SwapBuffers();
glCanvas2->SetCurrent();
glViewport(0, 0, glCanvas2->GetSize().GetWidth(), glCanvas2->GetSize().GetHeight());
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(red, blue, green);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
glCanvas2->SwapBuffers();
rEvent.RequestMore();
}
Code: Select all
#ifndef INC__MAIN_HPP__
#define INC__MAIN_HPP__
#include "wx/wx.h"
#include "wx/glcanvas.h"
class App : public wxApp {
public:
bool OnInit();
};
DECLARE_APP(App)
class Frame : public wxFrame {
public:
Frame(wxWindow *rParent, wxWindowID rId, const wxString &rTitle, const wxPoint &rPos = wxDefaultPosition, const wxSize &rSize = wxDefaultSize, long rStyle = wxDEFAULT_FRAME_STYLE, const wxString &rName = "frame");
void on_close(wxCloseEvent &rEvent);
void on_idle(wxIdleEvent &rEvent);
wxGLCanvas *glCanvas;
wxGLCanvas *glCanvas2;
wxGLContext *glContext;
wxGLContext *glContext2;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(Frame, wxFrame)
EVT_CLOSE(Frame::on_close)
EVT_IDLE(Frame::on_idle)
END_EVENT_TABLE()
#endif
Code: Select all
#include "main.hpp"
IMPLEMENT_APP(App)
bool App::OnInit() {
Frame *frame = new Frame(NULL, wxID_ANY, wxString("Typing Mentr"), wxDefaultPosition, wxSize(300, 300));
frame->Show();
SetTopWindow(frame);
return 1;
}
Frame::Frame(wxWindow *rParent, wxWindowID rId, const wxString &rTitle, const wxPoint &rPos, const wxSize &rSize, long rStyle, const wxString &rName) : wxFrame(rParent, rId, rTitle, rPos, rSize, rStyle, rName) {
int attributeList[] = {
WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0
};
glCanvas = new wxGLCanvas(this, wxID_ANY, wxPoint(0, 0), wxSize(100, 100), 0, wxString("GLCanvas"), attributeList);
//glCanvas2 = new wxGLCanvas(this, wxID_ANY, wxPoint(100, 100), wxSize(100, 100), 0, wxString("GLCanvas"), attributeList);
glContext = glCanvas->GetContext();
//glContext2 = glCanvas2->GetContext();
glCanvas->Show();
//glCanvas2->Show();
}
void Frame::on_close(wxCloseEvent &rEvent) {
Destroy();
}
void Frame::on_idle(wxIdleEvent &rEvent) {
float red, blue, green;
red = blue = green = 0.5;
wxBell(); //This makes some noise, so I know that it IS getting an initial idle event that the opengl drawing code depends on.
glCanvas->SetCurrent();
glViewport(0, 0, glCanvas->GetSize().GetWidth(), glCanvas->GetSize().GetHeight());
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(red, blue, green);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
glCanvas->SwapBuffers();
/*glCanvas2->SetCurrent();
glViewport(0, 0, glCanvas2->GetSize().GetWidth(), glCanvas2->GetSize().GetHeight());
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(red, blue, green);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
glCanvas2->SwapBuffers();*/
rEvent.RequestMore();
}