wxWidget 2.8 et la nouvelle façon d'utiliser Opengl
Bonjour,
Depuis wxWidget 2.7.x et +, l'utilisation d'Opengl se fait en peu différement et j'esseye de l'utiliser mais je n'y arrive pas trop bien.
Voici mon code:
main.h :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <wx/wx.h>
#include <wx/glcanvas.h>
class myGLCanvas : public wxGLCanvas
{
public:
myGLCanvas(wxFrame *);
private:
wxGLContext *glContext;
void onIdle(wxIdleEvent &);
DECLARE_EVENT_TABLE()
};
class myFrameMain : public wxFrame
{
public:
myFrameMain();
private:
myGLCanvas *glCanvas;
wxGLContext *glContext;
};
class Ini : public wxApp
{
public:
virtual bool OnInit();
};
DECLARE_APP(Ini); |
main.cpp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| //Compilation : g++ `wx-config --cxxflags` `wx-config --libs core,base --gl-libs` main.cpp
#include "main.h"
using namespace std;
myFrameMain::myFrameMain() : wxFrame(NULL, -1, "test", wxPoint(-1, -1), wxSize(1024,790), wxDEFAULT_FRAME_STYLE)
{
glCanvas = new myGLCanvas(this);
glContext = new wxGLContext(glCanvas);
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(glCanvas, 1, wxALL|wxEXPAND, 0);
this->SetSizer(sizer);
}
myGLCanvas::myGLCanvas(wxFrame *parent) : wxGLCanvas(parent, glContext, -1, wxPoint(0,0))
{
this->glContext = glContext;
parent->Show();
}
void myGLCanvas::onIdle(wxIdleEvent &event)
{
SetCurrent(*glContext);
//ou encore : glContext->SetCurrent(*this);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(-0.9, -0.5);
glVertex2f(-0.1, -0.5);
glVertex2f(-0.5, 0.5);
glEnd();
SwapBuffers();
event.RequestMore();
}
IMPLEMENT_APP(Ini);
bool Ini::OnInit(void)
{
myFrameMain *frame = new myFrameMain();
frame->Show(TRUE);
return true;
}
BEGIN_EVENT_TABLE(myGLCanvas, wxGLCanvas)
EVT_IDLE(myGLCanvas::onIdle)
END_EVENT_TABLE() |
Dans la documentation ( http://www.wxwidgets.org/manuals/2.8...xglcanvas.html ), ils disent que l'ont peut utiliser soit wxGLCanvas::SetCurrent ou soit wxGLContext::SetCurrent (si j'ai bien compris leur phrase en anglais, lol)
J'ai donc esseyé les 2 solutions et j'ai toujours une erreur de segmentation à cette ligne.
Merci d'avance...