diff --git a/Projects/CodeBlocks/SleepyHead.depend b/Projects/CodeBlocks/SleepyHead.depend index 8b32f168..8f1edfff 100644 --- a/Projects/CodeBlocks/SleepyHead.depend +++ b/Projects/CodeBlocks/SleepyHead.depend @@ -8300,7 +8300,7 @@ "tinyxml/tinyxml.h" -1308302313 /home/mark/projects/git/sleepyhead/src/graphs/graph.h +1308311237 /home/mark/projects/git/sleepyhead/src/graphs/graph.h "gl_pbuffer.h" @@ -8309,7 +8309,7 @@ 1308026543 D -1308306194 /home/mark/projects/git/sleepyhead/src/version.h +1308326231 /home/mark/projects/git/sleepyhead/src/version.h 1308003040 ent of cb2ab33... Linux wx2.8 & wx2.9 builds fixed @@ -8341,7 +8341,7 @@ "preferences.h" "tinyxml/tinyxml.h" -1308271319 source:/home/mark/projects/git/sleepyhead/src/SleepyHeadMain.cpp +1308313128 source:/home/mark/projects/git/sleepyhead/src/SleepyHeadMain.cpp "wx_pch.h" "version.h" @@ -8362,7 +8362,7 @@ "sleeplib/profiles.h" "sleeplib/machine_loader.h" -1308304488 source:/home/mark/projects/git/sleepyhead/src/graphs/graph.cpp +1308313179 source:/home/mark/projects/git/sleepyhead/src/graphs/graph.cpp "freetype-gl/font-manager.h" "freetype-gl/texture-font.h" "graph.h" @@ -11062,7 +11062,7 @@ "freetype-gl/vector.h" -1308306186 /home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.h +1308311222 /home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.h @@ -11072,10 +11072,13 @@ + -1308304655 source:/home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.cpp +1308314362 source:/home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.cpp "gl_pbuffer.h" + + 1305166122 /opt/mingw/usr/i686-pc-mingw32/include/wx-2.8/wx/treectrl.h "wx/defs.h" diff --git a/Projects/CodeBlocks/SleepyHead.layout b/Projects/CodeBlocks/SleepyHead.layout index 1fb83e66..3a5be89a 100644 --- a/Projects/CodeBlocks/SleepyHead.layout +++ b/Projects/CodeBlocks/SleepyHead.layout @@ -16,13 +16,13 @@ - - + + - + - + @@ -58,7 +58,7 @@ - + diff --git a/src/SleepyHeadMain.cpp b/src/SleepyHeadMain.cpp index e181bf62..f1e9b548 100644 --- a/src/SleepyHeadMain.cpp +++ b/src/SleepyHeadMain.cpp @@ -1,19 +1,19 @@ -/*************************************************************** - * Name: SleepyHeadMain.cpp - * Purpose: Code for Application Frame - * Author: Mark Watkins (jedimark64@users.sourceforge.net) - * Created: 2011-05-20 - * Copyright: Mark Watkins (http://sourceforge.net/projects/sleepyhead/) - * License: GPL - **************************************************************/ - -#ifdef WX_PRECOMP -#include "wx_pch.h" -#endif - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif //__BORLANDC__ +/*************************************************************** + * Name: SleepyHeadMain.cpp + * Purpose: Code for Application Frame + * Author: Mark Watkins (jedimark64@users.sourceforge.net) + * Created: 2011-05-20 + * Copyright: Mark Watkins (http://sourceforge.net/projects/sleepyhead/) + * License: GPL + **************************************************************/ + +#ifdef WX_PRECOMP +#include "wx_pch.h" +#endif + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif //__BORLANDC__ #include "version.h" #include @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -44,38 +44,38 @@ wxProgressDialog *loader_progress; -//helper functions -enum wxbuildinfoformat { +//helper functions +enum wxbuildinfoformat { short_f, long_f }; -wxString wxbuildinfo(wxbuildinfoformat format) -{ - wxString wxbuild(wxVERSION_STRING); - - if (format == long_f ) - { -#if defined(__WXMSW__) - wxbuild << _T("-Windows"); -#elif defined(__WXMAC__) - wxbuild << _T("-Mac"); -#elif defined(__UNIX__) - wxbuild << _T("-Linux"); -#endif - -#if wxUSE_UNICODE - wxbuild << _T("-Unicode build"); -#else - wxbuild << _T("-ANSI build"); -#endif // wxUSE_UNICODE - } - - return wxbuild; -} +wxString wxbuildinfo(wxbuildinfoformat format) +{ + wxString wxbuild(wxVERSION_STRING); + + if (format == long_f ) + { +#if defined(__WXMSW__) + wxbuild << _T("-Windows"); +#elif defined(__WXMAC__) + wxbuild << _T("-Mac"); +#elif defined(__UNIX__) + wxbuild << _T("-Linux"); +#endif + +#if wxUSE_UNICODE + wxbuild << _T("-Unicode build"); +#else + wxbuild << _T("-ANSI build"); +#endif // wxUSE_UNICODE + } + + return wxbuild; +} const long profile_version=0; - -SleepyHeadFrame::SleepyHeadFrame(wxFrame *frame) - : GUIFrame(frame) + +SleepyHeadFrame::SleepyHeadFrame(wxFrame *frame) + : GUIFrame(frame) { //GraphInit(); // Don't do this here: The first gGraphWindow must do it. @@ -120,14 +120,14 @@ SleepyHeadFrame::SleepyHeadFrame(wxFrame *frame) OnViewMenuDaily(dummy); // Daily Page this->Connect(wxID_ANY, wxEVT_DO_SCREENSHOT, wxCommandEventHandler(SleepyHeadFrame::DoScreenshot)); - -#if wxUSE_STATUSBAR - //statusBar->SetStatusText(_("Hello!"), 0); - statusBar->SetStatusText(wxbuildinfo(long_f), 1); -#endif -} - -SleepyHeadFrame::~SleepyHeadFrame() + +#if wxUSE_STATUSBAR + //statusBar->SetStatusText(_("Hello!"), 0); + statusBar->SetStatusText(wxbuildinfo(long_f), 1); +#endif +} + +SleepyHeadFrame::~SleepyHeadFrame() { GraphDone(); } @@ -164,9 +164,9 @@ void SleepyHeadFrame::UpdateProfiles() i++; } } - -void SleepyHeadFrame::OnClose(wxCloseEvent &event) -{ + +void SleepyHeadFrame::OnClose(wxCloseEvent &event) +{ int idx=main_auinotebook->GetPageIndex(daily); if (idx!=wxNOT_FOUND) { daily->Close(); @@ -187,12 +187,12 @@ void SleepyHeadFrame::OnClose(wxCloseEvent &event) } this->Disconnect(wxID_ANY, wxEVT_DO_SCREENSHOT, wxCommandEventHandler(SleepyHeadFrame::DoScreenshot)); - Destroy(); -} - -void SleepyHeadFrame::OnQuit(wxCommandEvent &event) -{ - Destroy(); + Destroy(); +} + +void SleepyHeadFrame::OnQuit(wxCommandEvent &event) +{ + Destroy(); } void SleepyHeadFrame::OnFullscreen(wxCommandEvent& event) { @@ -248,7 +248,7 @@ void SleepyHeadFrame::DoScreenshot( wxCommandEvent &event ) r.height += j.height; #endif -#if defined(__WXMAC__) +#if defined(__WXMAC__) wxMessageBox(wxT("Sorry.. Screenshots don't work on your platform.\n\nPlease use your Mac's screenshot capability instead."),wxT("Naughty Apple!"),wxICON_EXCLAMATION,this); #else wxScreenDC sdc; @@ -294,8 +294,8 @@ void SleepyHeadFrame::OnAntiAliasing( wxCommandEvent& event ) Refresh(); } - -void SleepyHeadFrame::OnAbout(wxCommandEvent &event) + +void SleepyHeadFrame::OnAbout(wxCommandEvent &event) { // wxAboutBox is fairly useless. wxString day=wxString(AutoVersion::_DATE,wxConvUTF8); @@ -602,7 +602,7 @@ void Summary::OnEndDateChanged( wxDateEvent& event ) RefreshData(); } -void Summary::OnClose(wxCloseEvent &event) +void Summary::OnClose(wxCloseEvent &event) { Destroy(); } @@ -825,7 +825,6 @@ Daily::Daily(wxWindow *win,Profile *p) gwSizer->Add(SPO2,1,wxEXPAND); - gwSizer->Layout(); //fgSizer->Add(G_AHI,1,wxEXPAND); //fgSizer->Add(TAP,1,wxEXPAND); //fgSizer->Add(TAP_IAP,1,wxEXPAND); @@ -839,7 +838,10 @@ Daily::Daily(wxWindow *win,Profile *p) //EVT_SCROLLWIN_THUMBTRACK(Daily::OnWinScroll) //this->Connect(GraphWindow->GetId(),wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEventHandler(Daily::OnWinScroll)); - Refresh(); // Important. Don't change the order of the next two lines. + Refresh(true); // Important. Don't change the order of the next two lines. + Update(); +// gwSizer->Layout(); + ResetDate(); } @@ -874,7 +876,7 @@ void Daily::OnWinScroll(wxScrollWinEvent &event) wxLogMessage(wxT("OnWinScroll")); Update(); } -void Daily::OnClose(wxCloseEvent &event) +void Daily::OnClose(wxCloseEvent &event) { Destroy(); } @@ -1270,7 +1272,7 @@ void Daily::OnSelectSession( wxCommandEvent& event ) } } -///usr/local/bin/upx ./bin/Windows/SleepyHead +///usr/local/bin/upx ./bin/Windows/SleepyHead void Daily::OnCalendarDay( wxCalendarEvent& event ) { diff --git a/src/graphs/gl_pbuffer.cpp b/src/graphs/gl_pbuffer.cpp index 15ebc27e..8d00351c 100644 --- a/src/graphs/gl_pbuffer.cpp +++ b/src/graphs/gl_pbuffer.cpp @@ -5,8 +5,20 @@ Author: Mark Watkins License: GPL */ #include "gl_pbuffer.h" - +#include #include +#include + +long roundup2(long v) +{ + int j; + for (int i=4;i<32;i++) { // min size 16x16.. probably a usless size. + j=1 << i; + if (j >= v) break; + } + return j; +} + pBuffer::pBuffer() { @@ -18,23 +30,129 @@ pBuffer::pBuffer(int width, int height) pBuffer::~pBuffer() { } +wxBitmap *pBuffer::Snapshot(int width, int height) +{ + glDrawBuffer(GL_BACK_LEFT); + + void* pixels = malloc(3 * width * height); // must use malloc + glReadBuffer(GL_BACK_LEFT); + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + // Put the image into a wxImage + wxImage image(width, height, true); + image.SetData((unsigned char*) pixels); + image = image.Mirror(false); + wxBitmap *bmp=new wxBitmap(image); + return bmp; +} + + +FBO::FBO(int width, int height) +:pBuffer() +{ + //wxGLContext a((wxGLCanvas *)NULL,(wxGLContext *)NULL); + int m=MAX(width,height); + //int j=roundup2(m) << 2; + m_width=width; //roundup2(width) << 2; + m_height=height; //roundup2(height) << 2; + + glGenFramebuffersEXT(1, &fbo); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + + // create texture to render to. + glGenTextures(1, &img); + glBindTexture(GL_TEXTURE_2D, img); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0); + + + m_depth_buffer=true; + m_color_buffer=true; //false; + + if (m_depth_buffer) { + glGenRenderbuffersEXT(1, &depthbuffer); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_width, m_height); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer); + } + + if (m_color_buffer) { + glGenRenderbuffersEXT(1, &colorbuffer); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorbuffer); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, m_width, m_height); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, colorbuffer); + } + + GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + //if (status!=GL_FRAMEBUFFER_COMPLETE_EXT) { + GLenum err = glGetError(); + if (err!=GL_NO_ERROR) { + wxString a((char *)gluErrorString(status),wxConvUTF8); + throw GLException(wxT("glCheckFramebufferStatusEXT failed")+a); + } + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + +} + + +FBO::~FBO() +{ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glDeleteFramebuffersEXT(1, &fbo); + if (m_depth_buffer) + glDeleteRenderbuffersEXT(1, &depthbuffer); + if (m_color_buffer) + glDeleteRenderbuffersEXT(1, &colorbuffer); +} +void FBO::UseBuffer(bool b) +{ + if (b) { + // glBindTexture(GL_TEXTURE_2D, img); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + } else { + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + } +} +wxBitmap *FBO::Snapshot(int width,int height) +{ + //width=m_width; + //height=m_height; + glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); + + void* pixels = malloc(3 * width * height); // must use malloc + glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + + // Put the image into a wxImage + wxImage image(width, height, true); + image.SetData((unsigned char*) pixels); + image = image.Mirror(false); + wxBitmap *bmp=new wxBitmap(image); + return bmp; +} + #if defined(__WXMSW__) #if !defined(wglGetExtensionsStringARB) - PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = NULL; - - // WGL_ARB_pbuffer - PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB = NULL; - PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB = NULL; - PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB = NULL; - PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB = NULL; - PFNWGLQUERYPBUFFERARBPROC wglQueryPbufferARB = NULL; - - // WGL_ARB_pixel_format - PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = NULL; - PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB = NULL; + PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = NULL; + + // WGL_ARB_pbuffer + PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB = NULL; + PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB = NULL; + PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB = NULL; + PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB = NULL; + PFNWGLQUERYPBUFFERARBPROC wglQueryPbufferARB = NULL; + + // WGL_ARB_pixel_format + PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = NULL; + PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB = NULL; PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = NULL; #endif @@ -182,50 +300,50 @@ bool pBufferWGL::InitGLStuff() { // Technically don't need this wrangling with glewInit being actually called now.... - //wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); - char *ext = NULL; - - if (wglGetExtensionsStringARB) - ext = (char*)wglGetExtensionsStringARB( wglGetCurrentDC() ); + //wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); + char *ext = NULL; + + if (wglGetExtensionsStringARB) + ext = (char*)wglGetExtensionsStringARB( wglGetCurrentDC() ); else { wxLogError(wxT("Unable to get address for wglGetExtensionsStringARB!")); - return false; + return false; } - if (strstr(ext, "WGL_ARB_pbuffer" ) == NULL) { + if (strstr(ext, "WGL_ARB_pbuffer" ) == NULL) { wxLogError(wxT("WGL_ARB_pbuffer extension was not found")); - return false; - } else { - //wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB"); - //wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB"); - //wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB"); - //wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB"); - //wglQueryPbufferARB = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB"); - - if (!wglCreatePbufferARB || !wglGetPbufferDCARB || !wglReleasePbufferDCARB || + return false; + } else { + //wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB"); + //wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB"); + //wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB"); + //wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB"); + //wglQueryPbufferARB = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB"); + + if (!wglCreatePbufferARB || !wglGetPbufferDCARB || !wglReleasePbufferDCARB || !wglDestroyPbufferARB || !wglQueryPbufferARB) { wxLogError(wxT("One or more WGL_ARB_pbuffer functions were not found")); - return false; - } - } - - // WGL_ARB_pixel_format + return false; + } + } + + // WGL_ARB_pixel_format if (strstr( ext, "WGL_ARB_pixel_format" ) == NULL) { - wxLogError(wxT("WGL_ARB_pixel_format extension was not found")); - return false; - } else { - wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB"); - wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribfvARB"); - wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); - - if (!wglGetExtensionsStringARB || !wglCreatePbufferARB || !wglGetPbufferDCARB) { + wxLogError(wxT("WGL_ARB_pixel_format extension was not found")); + return false; + } else { + wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB"); + wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribfvARB"); + wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); + + if (!wglGetExtensionsStringARB || !wglCreatePbufferARB || !wglGetPbufferDCARB) { wxLogError(wxT("One or more WGL_ARB_pixel_format functions were not found")); - return false; - } - } + return false; + } + } - return true; + return true; } diff --git a/src/graphs/gl_pbuffer.h b/src/graphs/gl_pbuffer.h index abc839c3..aa6fa277 100644 --- a/src/graphs/gl_pbuffer.h +++ b/src/graphs/gl_pbuffer.h @@ -39,9 +39,12 @@ License: GPL #include #endif -#define MIN(a,b) (a + +long roundup2(long v); class GLException { public: @@ -56,12 +59,30 @@ public: pBuffer(int width, int height); virtual ~pBuffer(); virtual void UseBuffer(bool b) {}; - + int Width() { return m_width; }; + int Height() { return m_height; }; + virtual wxBitmap *Snapshot(int width, int height); protected: int m_width; int m_height; }; +class FBO:public pBuffer +{ +public: + FBO(int width, int height); + virtual ~FBO(); + virtual void UseBuffer(bool b); + virtual wxBitmap *Snapshot(int width, int height); +protected: + GLuint depthbuffer,colorbuffer; + GLuint img; + GLuint fbo; + bool m_depth_buffer; + bool m_color_buffer; + +}; + #if defined(__WXMSW__) class pBufferWGL:public pBuffer { diff --git a/src/graphs/graph.cpp b/src/graphs/graph.cpp index 7ffb2d2a..d6ee0683 100644 --- a/src/graphs/graph.cpp +++ b/src/graphs/graph.cpp @@ -23,7 +23,7 @@ License: GPL #include "sleeplib/profiles.h" -#include "graphs/freesans.h" +#include "graphs/freesans.h" // Remember to compress this.. //#include @@ -1002,108 +1002,48 @@ pBuffer *pbuffer=NULL; wxBitmap * gGraphWindow::RenderBitmap(int width,int height) { - // I can't get FBO buffers to work properly - // Fonts screw up and the first read is corrupted. - // pBuffers are faster anyway.. - - // shared_context->SetCurrent(*this); - /*GLuint fbo; - glGenFramebuffersEXT(1, &fbo); - - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); - - GLuint depthbuffer,colorbuffer; - //glGenRenderbuffersEXT(1, &depthbuffer); - glGenRenderbuffersEXT(1, &colorbuffer); - - //glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer); - //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height); - - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorbuffer); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height); - - - //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, colorbuffer); - - - GLuint img; - glGenTextures(1, &img); - glBindTexture(GL_TEXTURE_2D, img); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - - - - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0); - - GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - - //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); */ - - - + wxBitmap *bmp; if (!pbuffer) { try { + wxSize res=wxGetDisplaySize(); + pbuffer=new FBO(res.GetWidth(),res.GetHeight()); + /* #if defined(__WXMSW__) pbuffer=new pBufferWGL(width,height); #elif defined(__WXMAC__) || defined(__WXDARWIN__) - pbuffer=new pBufferAGL(width,height); + throw GLException(wxT("Macintrash")); + //pbuffer=new pBufferAGL(width,height); #elif defined(__UNIX__) pbuffer=new pBufferGLX(width,height); #endif +*/ } catch(GLException e) { // Should log already if failed.. + wxLogDebug(wxT("pBuffers not implemented or functional on this platform.. Trying FBO")); + pbuffer=NULL; + } + } + if (!pbuffer) { + try { + pbuffer=new FBO(width,height); + } catch(GLException e) { + wxLogError(wxT("No offscreen rendering capabilities detected on this machine.")); pbuffer=NULL; return NULL; } } - - - if (pbuffer) { pbuffer->UseBuffer(true); - } - // Move this bitmap code to pBuffer + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + // Can't use font's in multiple contexts + Render(width,height); - // glClearColor(1,1,0,1); - //glClear(GL_COLOR_BUFFER_BIT); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - //glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); - // Can't use font's in multiple contexts - Render(width,height); + bmp=pbuffer->Snapshot(width,height); + glFlush(); + pbuffer->UseBuffer(false); + } else bmp=NULL; - //glDrawBuffer(GL_BACK_LEFT); - -// GLubyte* src = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); - -// glBindTexture(GL_TEXTURE_2D, img); - void* pixels = malloc(3 * width * height); // must use malloc - //glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); - - //glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); - //glReadBuffer(GL_FRONT); - //glReadBuffer(GL_BACK_LEFT ); - //glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); - - // Put the image into a wxImage - wxImage image(width, height, true); - image.SetData((unsigned char*) pixels); - image = image.Mirror(false); - glFlush(); - - wxBitmap *bmp=new wxBitmap(image); - - - // glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); -// glDeleteFramebuffersEXT(1, &fbo); - //glDeleteRenderbuffersEXT(1, &depthbuffer); - if (pbuffer) { - //delete pbuffer; - } return bmp; } @@ -1180,7 +1120,7 @@ void gGraphWindow::OnPaint(wxPaintEvent& event) SwapBuffers(); // Dump to screen. - //event.Skip(); + event.Skip(); } void gGraphWindow::OnSize(wxSizeEvent& event) { @@ -1673,8 +1613,8 @@ void gYAxis::Plot(gGraphWindow &w,float scrx,float scry) glColor4ub(linecol1.Red(),linecol1.Green(),linecol1.Blue(),linecol1.Alpha()); glLineWidth(1); - for (double i=miny+(min_ytick/2.0); ilabelW) labelW=x; + for (double i=miny; i<=maxy; i+=min_ytick) { + ty=(i - miny) * ymult; + fd=Format(i); // Override this as a function. + GetTextExtent(fd,x,y); + if (x>labelW) labelW=x; h=start_py+ty; - DrawText(fd,start_px-8-x,h - (y / 2)); + DrawText(fd,start_px-8-x,h - (y / 2)); vertarray[vertcnt++]=start_px-4; vertarray[vertcnt++]=h; @@ -2816,7 +2756,7 @@ void TAPData::Reload(Day *day) int lastval=0,val; int field=0; - + for (vector::iterator s=day->begin();s!=day->end();s++) { if ((*s)->events.find(code)==(*s)->events.end()) continue; first=true; diff --git a/src/graphs/graph.h b/src/graphs/graph.h index 335ba26b..3a8b46dd 100644 --- a/src/graphs/graph.h +++ b/src/graphs/graph.h @@ -30,8 +30,8 @@ extern wxColor *wxLIGHT_YELLOW; extern wxColor *wxDARK_GREEN; extern wxColor *wxDARK_GREY; -#define MIN(a,b) (a