hecato
July 5th, 2007, 02:39 AM
This is a sample Im constructing, then dont ask me from which site I get it, thought the base is from the wxWiki http://www.wxwidgets.org/wiki/index.php/WxGLCanvas
I will see the samples from wx but they are some what large because the kb and mice interaction.
Warning this code is the cause for at less 2 manual resets of my computer. :S
In fact the freeze come when doing resizing of the window with the mouse... dont try it hard or you will be freezed and sure CTRL+ALT+DEL or SUPR dosent work, only manual reset is OK.
http://rafb.net/p/kknBvL87.html
#include "wx/wx.h"
#include "wx/glcanvas.h"
#ifndef WIN32
#include <unistd.h> // FIXME: ¿esto sirve en WIN32?
#endif
class MyApp: public wxApp
{
virtual bool OnInit();
void Render();
wxFrame *frame;
wxGLCanvas * MyGLCanvas;
public:
void Pinta(wxPaintEvent& event);
protected:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(MyApp, wxApp)
EVT_PAINT (MyApp::Pinta)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)
void MyApp::Pinta(wxPaintEvent& WXUNUSED(event)){
Render();
}
bool MyApp::OnInit()
{
frame = new wxFrame((wxFrame *)NULL, -1, _T("Hello GL World"), wxPoint(50,50), wxSize(200,200));
MyGLCanvas = new wxGLCanvas(frame, -1, wxPoint(0,0), wxSize(200,200), wxSUNKEN_BORDER, _T("some text"));
frame->Show(TRUE);
Render();
return TRUE;
}
void MyApp::Render()
{
MyGLCanvas->SetCurrent();
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, (GLint)200, (GLint)200);
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glColor3f(0.4, 0.5, 0.4);
glVertex2f(0.0, -0.8);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.1, 0.1);
glVertex2f(-0.1, 0.1);
glVertex2f(-0.1, -0.1);
glVertex2f(0.1, -0.1);
glEnd();
glFlush();
}
I will see the samples from wx but they are some what large because the kb and mice interaction.
Warning this code is the cause for at less 2 manual resets of my computer. :S
In fact the freeze come when doing resizing of the window with the mouse... dont try it hard or you will be freezed and sure CTRL+ALT+DEL or SUPR dosent work, only manual reset is OK.
http://rafb.net/p/kknBvL87.html
#include "wx/wx.h"
#include "wx/glcanvas.h"
#ifndef WIN32
#include <unistd.h> // FIXME: ¿esto sirve en WIN32?
#endif
class MyApp: public wxApp
{
virtual bool OnInit();
void Render();
wxFrame *frame;
wxGLCanvas * MyGLCanvas;
public:
void Pinta(wxPaintEvent& event);
protected:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(MyApp, wxApp)
EVT_PAINT (MyApp::Pinta)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)
void MyApp::Pinta(wxPaintEvent& WXUNUSED(event)){
Render();
}
bool MyApp::OnInit()
{
frame = new wxFrame((wxFrame *)NULL, -1, _T("Hello GL World"), wxPoint(50,50), wxSize(200,200));
MyGLCanvas = new wxGLCanvas(frame, -1, wxPoint(0,0), wxSize(200,200), wxSUNKEN_BORDER, _T("some text"));
frame->Show(TRUE);
Render();
return TRUE;
}
void MyApp::Render()
{
MyGLCanvas->SetCurrent();
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, (GLint)200, (GLint)200);
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glColor3f(0.4, 0.5, 0.4);
glVertex2f(0.0, -0.8);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.1, 0.1);
glVertex2f(-0.1, 0.1);
glVertex2f(-0.1, -0.1);
glVertex2f(0.1, -0.1);
glEnd();
glFlush();
}