graphs/gl_pbuffer.cpp & graphs/gl_pbuffer.h addition

This commit is contained in:
Mark Watkins 2011-06-15 10:28:39 +10:00
parent 70b7030b6f
commit a49a05e598
6 changed files with 470 additions and 253 deletions

View File

@ -8240,7 +8240,7 @@
<wx/datectrl.h>
<wx/dateevt.h>
1308079880 source:/home/mark/projects/git/sleepyhead/src/SleepyHeadApp.cpp
1308095988 source:/home/mark/projects/git/sleepyhead/src/SleepyHeadApp.cpp
"wx_pch.h"
<iostream>
<wx/log.h>
@ -8300,19 +8300,16 @@
<map>
"tinyxml/tinyxml.h"
1308044762 /home/mark/projects/git/sleepyhead/src/graphs/graph.h
<OpenGL/gl.h>
<AGL/agl.h>
<GL/glew.h>
<GL/wglew.h>
<wx/dcgraph.h>
1308097501 /home/mark/projects/git/sleepyhead/src/graphs/graph.h
"gl_pbuffer.h"
<wx/glcanvas.h>
<wx/geometry.h>
<sleeplib/machine.h>
<list>
1308026543 D
1308081125 /home/mark/projects/git/sleepyhead/src/version.h
1308097644 /home/mark/projects/git/sleepyhead/src/version.h
1308003040 ent of cb2ab33... Linux wx2.8 & wx2.9 builds fixed
<wx/dcbuffer.h>
@ -8344,7 +8341,7 @@
"preferences.h"
"tinyxml/tinyxml.h"
1308031975 source:/home/mark/projects/git/sleepyhead/src/SleepyHeadMain.cpp
1308088585 source:/home/mark/projects/git/sleepyhead/src/SleepyHeadMain.cpp
"wx_pch.h"
"version.h"
<wx/app.h>
@ -8364,18 +8361,19 @@
"sleeplib/profiles.h"
"sleeplib/machine_loader.h"
1308080954 source:/home/mark/projects/git/sleepyhead/src/graphs/graph.cpp
<wx/dcbuffer.h>
1308097644 source:/home/mark/projects/git/sleepyhead/src/graphs/graph.cpp
"freetype-gl/font-manager.h"
"freetype-gl/texture-font.h"
"graph.h"
<wx/settings.h>
<wx/graphics.h>
<wx/image.h>
<wx/bitmap.h>
<wx/dcbuffer.h>
<wx/log.h>
<math.h>
"sleeplib/profiles.h"
"freesans.c"
"graph.h"
"freetype-gl/font-manager.h"
"freetype-gl/texture-font.h"
1308010945 >
@ -11061,3 +11059,15 @@
<string.h>
"freetype-gl/vector.h"
1308097228 /home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.h
<wx/log.h>
<GL/glew.h>
<GL/wglew.h>
<OpenGL/gl.h>
<AGL/agl.h>
<GL/glx.h>
1308097442 source:/home/mark/projects/git/sleepyhead/src/graphs/gl_pbuffer.cpp
"gl_pbuffer.h"
<wx/utils.h>

284
src/graphs/gl_pbuffer.cpp Normal file
View File

@ -0,0 +1,284 @@
#include "gl_pbuffer.h"
#include <wx/utils.h>
pBuffer::pBuffer()
{
}
pBuffer::pBuffer(int width, int height)
:m_width(width),m_height(height)
{
}
pBuffer::~pBuffer()
{
}
#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;
PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = NULL;
#endif */
pBufferWGL::pBufferWGL(int width, int height)
:m_texture(0)
{
hGlRc=0;
hBuffer=0;
hdc=0;
saveHdc=0;
saveHglrc=0;
if (!InitGLStuff()) {
throw GLException(wxT("Could not Init GL Stuff"));
}
// Adjust to square power of 2
int ms=MAX(width,height);
int j;
for (int i=4;i<32;i++) { // min size 16x16.. probably a usless size.
j=1 << i;
if (j >= ms) break;
}
assert (j>=ms); // I seriously doubt this will ever happen ;)
// WGL only supports square pBuffers
m_width=j;
m_height=j;
wxLogMessage(wxString::Format(wxT("Adjusting pBuffer width and height to %ix%i"),j,j));
// Create Texture
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 4, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// Get the context to work with (must be valid, will die otherwise)
saveHdc = wglGetCurrentDC();
saveHglrc = wglGetCurrentContext();
int pixelFormats;
int intAttrs[32] ={
WGL_RED_BITS_ARB,8,
WGL_GREEN_BITS_ARB,8,
WGL_BLUE_BITS_ARB,8,
WGL_ALPHA_BITS_ARB,8,
WGL_DRAW_TO_PBUFFER_ARB, GL_TRUE,
WGL_BIND_TO_TEXTURE_RGBA_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
WGL_DOUBLE_BUFFER_ARB,GL_FALSE,
0
}; // 0 terminate the list
unsigned int numFormats = 0;
wxLogError(wxT("Foo2"));
if (!wglChoosePixelFormatARB) {
throw GLException(wxT("No wglChoosePixelFormatARB available"));
}
if (!wglChoosePixelFormatARB( saveHdc, intAttrs, NULL, 1, &pixelFormats, &numFormats)) {
throw GLException(wxT("WGL: pbuffer creation error: Couldn't find a suitable pixel format."));
}
if (numFormats==0) {
throw GLException(wxT("WGL: pbuffer creation error: numFormats==0"));
}
const int attributes[]= {
WGL_TEXTURE_FORMAT_ARB,
WGL_TEXTURE_RGBA_ARB, // p-buffer will have RBA texture format
WGL_TEXTURE_TARGET_ARB,
WGL_TEXTURE_2D_ARB,
0
}; // Of texture target will be GL_TEXTURE_2D
//wglCreatePbufferARB(hDC, pixelFormats, pbwidth, pbheight, attributes);
hBuffer=wglCreatePbufferARB(saveHdc, pixelFormats, m_width, m_height, attributes );
if (!hBuffer) {
throw GLException(wxT("wglCreatePbufferARB failure"));
}
hdc=wglGetPbufferDCARB( hBuffer );
if (!hdc) {
throw GLException(wxT("wglGetPbufferDCARB failure"));
}
hGlRc=wglCreateContext(hdc);
if (!hGlRc) {
throw GLException(wxT("wglCreateContext failure"));
}
//printf("PBuffer size: %d x %d\n",w,h);
int w,h;
wglQueryPbufferARB(hBuffer, WGL_PBUFFER_WIDTH_ARB, &w);
wglQueryPbufferARB(hBuffer, WGL_PBUFFER_HEIGHT_ARB, &h);
// compare w & h to m_width & m_height.
wxLogError(wxT("Foo7"));
wglMakeCurrent(hdc,hGlRc);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // enable transparency
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
// switch back to the screen context
wglMakeCurrent(saveHdc, saveHglrc);
// So we can share the main context
wglShareLists(saveHglrc, hGlRc);
// Jump back to pBuffer ready for rendering
//wglMakeCurrent(hdc, hGlRc);
}
pBufferWGL::~pBufferWGL()
{
if (hGlRc) wglDeleteContext(hGlRc);
if (hBuffer) wglReleasePbufferDCARB(hBuffer, hdc);
if (hBuffer) wglDestroyPbufferARB(hBuffer);
}
void pBufferWGL::UseBuffer(bool b)
{
if (b) {
wglMakeCurrent(hdc, hGlRc);
} else {
wglMakeCurrent(saveHdc, saveHglrc);
}
}
bool pBufferWGL::InitGLStuff()
{
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 true;
}
#elif defined(__UNIX__) && !defined(__WXMAC__)
GLXContext real_shared_context=NULL;
pBufferGLX::pBufferGLX(int width, int height)
:pBuffer()
{
m_width=width;
m_height=height;
int attrib[]={
GLX_PBUFFER_WIDTH,m_width,
GLX_PBUFFER_HEIGHT,m_height,
GLX_PRESERVED_CONTENTS, True
};
pBuffer=0;
m_context=0,m_shared=0;
int ret;
display=NULL;
GLXFBConfig *fbc=NULL;
/*#if wxCHECK_VERSION(2,9,0)
display=wxGetX11Display();
fbc = GetGLXFBConfig(); // wxGLCanvas call
fbc = &fbc[0];
pBuffer=glXCreatePbuffer(display, fbc[0], attrib );
#else */
display=(Display *)wxGetDisplay();
int doubleBufferAttributess[] = {
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DOUBLEBUFFER, True,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
None
};
fbc=glXChooseFBConfig(display, DefaultScreen(display), doubleBufferAttributess, &ret);
pBuffer=glXCreatePbuffer(display, *fbc, attrib );
//#endif
if (pBuffer == 0) {
wxLogError(wxT("pBuffer not availble"));
}
// This function is not in WX sourcecode yet :(
//shared=shared_context->GetGLXContext();
if (real_shared_context) m_shared=real_shared_context; // Only available after redraw.. :(
else {
// First render screws up unless we do this..
m_shared=m_context= glXCreateNewContext(display,*fbc,GLX_RGBA_TYPE, NULL, True);
}
if (m_shared == 0) {
wxLogError(wxT("Context not availble"));
}
//#if !wxCHECK_VERSION(2,9,0)
XFree(fbc);
//#endif
glXMakeCurrent(display,pBuffer,m_shared);
//UseBuffer(true);
}
pBufferGLX::~pBufferGLX()
{
if (m_context) glXDestroyContext(display,m_context); // Destroy the context only if we created it..
if (pBuffer) glXDestroyPbuffer(display, pBuffer);
}
void pBufferGLX::UseBuffer(bool b)
{
if (b) {
if (glXMakeCurrent(display,pBuffer,m_shared)!=True) {
wxLogError(wxT("Couldn't make pBuffer current"));
}
} else {
// to be honest.. i'm not sure yet.. wx stupidly keeps the needed variables private
}
}
#elif defined(__DARWIN__) || defined(__WXMAC__)
#endif

102
src/graphs/gl_pbuffer.h Normal file
View File

@ -0,0 +1,102 @@
#ifndef GL_PBUFFER_H
#define GL_PBUFFER_H
#define GL_GLEXT_PROTOTYPES
#undef Yield
#include <wx/log.h>
#if defined(__WXMSW__) // windows gl extensions
#define GLEW_STATIC
#define WGL_WGLEXT_PROTOTYPES
#include <GL/glew.h>
#include <GL/wglew.h>
//#include <GL/gl.h>
#elif defined(__DARWIN__)
#include <OpenGL/gl.h>
#include <AGL/agl.h>
#elif defined(__UNIX__)
#include <GL/glx.h>
#endif
#define MIN(a,b) (a<b) ? a : b;
#define MAX(a,b) (a<b) ? b : a;
class GLException {
public:
GLException(wxString s=wxT("Lazy Programmer forgot to specify error")) { wxLogError(wxT("GLException: ")+s); };
};
class pBuffer {
public:
pBuffer();
pBuffer(int width, int height);
virtual ~pBuffer();
virtual void UseBuffer(bool b) {};
protected:
int m_width;
int m_height;
};
#if defined(__WXMSW__)
class pBufferWGL:public pBuffer
{
public:
pBufferWGL(int width, int height);
virtual ~pBufferWGL();
virtual void UseBuffer(bool b);
protected:
bool InitGLStuff();
unsigned int m_texture;
HDC saveHdc;
HGLRC saveHglrc;
HPBUFFERARB hBuffer;
HDC hdc;
HGLRC hGlRc;
};
#elif defined(__UNIX__) && !defined(__WXMAC__)
// No way around having to do this.
// Until wx provides access to the data we need
extern GLXContext real_shared_context;
class pBufferGLX:public pBuffer
{
public:
pBufferGLX(int width, int height);
virtual ~pBufferGLX();
virtual void UseBuffer(bool b);
protected:
Display *display;
GLXPbuffer pBuffer;
GLXContext m_context;
GLXContext m_shared;
};
#elif defined(__DARWIN__) || defined(__WXMAC__)
class pBufferAGL:public pBuffer
{
public:
pBufferAGL(int width, int height){};
virtual ~pBufferAGL(){};
virtual void UseBuffer(bool b){};
protected:
virtual bool InitGLStuff(){};
};
#endif
#endif // GL_PBUFFER_H

View File

@ -5,30 +5,33 @@ Author: Mark Watkins <jedimark64@users.sourceforge.net>
License: LGPL
*/
#include "freetype-gl/font-manager.h"
#include "freetype-gl/texture-font.h"
#include "graph.h"
#include <wx/dcbuffer.h>
//#include <wx/glcanvas.h>
#include <wx/settings.h>
#include <wx/graphics.h>
#include <wx/image.h>
#include <wx/bitmap.h>
#include <wx/dcbuffer.h>
#include <wx/log.h>
#include <math.h>
#include "sleeplib/profiles.h"
#include "freesans.c"
#include "graph.h"
#include "freetype-gl/font-manager.h"
#include "freetype-gl/texture-font.h"
//#include <wx/dcbuffer.h>
#if !wxUSE_GLCANVAS
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the wx library"
#endif
extern pBuffer *buffer;
#if !wxCHECK_VERSION(2,9,0)
wxColor zwxYELLOW=wxColor(0xb0,0xb0,0x40,0xff);
@ -53,8 +56,6 @@ wxColor *wxDARK_GREY=&zwxDARK_GREY;
bool gfont_init=false;
wxGLContext *shared_context=NULL;
FontManager *font_manager;
TextureFont *zfont=NULL;
VertexBuffer *vbuffer=NULL;
@ -104,7 +105,7 @@ void GetTextExtent(wxString text, float & width, float & height, TextureFont *fo
TextureGlyph *glyph;
height=width=0;
for (int i=0;i<text.Length();i++) {
for (unsigned i=0;i<text.Length();i++) {
glyph=font->GetGlyph((wchar_t)text[i]);
if (!height) height=glyph->m_height; // > height) height=glyph->m_height;
width+=glyph->m_advance_x;
@ -123,7 +124,7 @@ void DrawText2(wxString text, float x, float y,TextureFont *font)
vbuffer->Clear();
glyph->AddToVertexBuffer(vbuffer, markup, &pen);
for (int j=1; j<text.Length(); ++j) {
for (unsigned j=1; j<text.Length(); ++j) {
glyph=font->GetGlyph(text[j]);
pen.x += glyph->GetKerning(text[j-1]);
glyph->AddToVertexBuffer(vbuffer, markup, &pen);
@ -133,7 +134,9 @@ void DrawText2(wxString text, float x, float y,TextureFont *font)
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_TEXTURE_2D );
glColor4f(1,1,1,1);
#if !defined(__WXMSW__)
vbuffer->Render(GL_TRIANGLES, (char *)"vtc" );
#endif
glDisable(GL_BLEND);
}
@ -804,196 +807,33 @@ void gGraphWindow::SetMargins(float top, float right, float bottom, float left)
m_marginRight=right;
}
#if !defined(__WXMAC__) && defined (__UNIX__)
GLXContext real_shared_context=0;
#endif
wxGLContext *shared_context=NULL;
pBuffer *pbuffer=NULL;
wxBitmap * gGraphWindow::RenderBitmap(int width,int height)
{
//pBuffers are evil.. but I need to use them here.
if (!pbuffer) {
try {
#if defined(__WXMSW__)
int mv=MAX(width,height);
// convert to nearest binary power of two.
int pbwidth=1024;
int pbheight=pbwidth; // Windows sucks ass.
unsigned int texture=0;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 4, pbwidth, pbheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
HDC saveHdc = wglGetCurrentDC();
HGLRC saveHglrc = wglGetCurrentContext();
wxLogError(wxT("Foo1"));
int pixelFormats;
int intAttrs[32] ={
WGL_RED_BITS_ARB,8,
WGL_GREEN_BITS_ARB,8,
WGL_BLUE_BITS_ARB,8,
WGL_ALPHA_BITS_ARB,8,
WGL_DRAW_TO_PBUFFER_ARB, GL_TRUE,
WGL_BIND_TO_TEXTURE_RGBA_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
WGL_DOUBLE_BUFFER_ARB,GL_FALSE,
0
}; // 0 terminate the list
unsigned int numFormats = 0;
wxLogError(wxT("Foo2"));
if (!wglChoosePixelFormatARB( saveHdc, intAttrs, NULL, 1, &pixelFormats, &numFormats)) {
wxLogError(wxT("WGL: pbuffer creation error: Couldn't find a suitable pixel format.\n"));
return &wxNullBitmap;
}
wxLogError(wxT("Foo3"));
if (numFormats==0) {
return &wxNullBitmap;
}
wxLogError(wxT("Foo3"));
const int attributes[]= {
WGL_TEXTURE_FORMAT_ARB,
WGL_TEXTURE_RGBA_ARB, // p-buffer will have RBA texture format
WGL_TEXTURE_TARGET_ARB,
WGL_TEXTURE_2D_ARB,
0
}; // Of texture target will be GL_TEXTURE_2D
//wglCreatePbufferARB(hDC, pixelFormats, pbwidth, pbheight, attributes);
HPBUFFERARB hBuffer=wglCreatePbufferARB(saveHdc, pixelFormats, pbwidth, pbheight, attributes );
wxLogError(wxT("Foo4"));
HDC hdc=wglGetPbufferDCARB( hBuffer );
wxLogError(wxT("Foo5"));
HGLRC hGlRc=wglCreateContext(hdc);
wxLogError(wxT("Foo6"));
//printf("PBuffer size: %d x %d\n",w,h);
int w,h;
wglQueryPbufferARB(hBuffer, WGL_PBUFFER_WIDTH_ARB, &w);
wglQueryPbufferARB(hBuffer, WGL_PBUFFER_HEIGHT_ARB, &h);
wxLogError(wxT("Foo7"));
wglMakeCurrent(hdc,hGlRc);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // enable transparency
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
// switch back to the screen context
wglMakeCurrent(saveHdc, saveHglrc);
// So we can share the main context
wglShareLists(saveHglrc, hGlRc);
// Jump back to pBuffer for rendering
wglMakeCurrent(hdc, hGlRc);
// WGL pBuffer Implementation
//return &wxNullBitmap;
pbuffer=new pBufferWGL(width,height);
#elif defined(__WXMAC__) || defined(__WXDARWIN__)
return &wxNullBitmap;
pbuffer=new pBufferAGL(width,height);
#elif defined(__UNIX__)
int attrib[]={
GLX_PBUFFER_WIDTH,width,
GLX_PBUFFER_HEIGHT,height,
GLX_PRESERVED_CONTENTS, True
};
int ret;
Display *display=NULL;
GLXFBConfig *fbc=NULL;
#if wxCHECK_VERSION(2,9,0)
display=wxGetX11Display();
fbc = GetGLXFBConfig();
fbc = &fbc[0];
GLXPbuffer pBuffer=glXCreatePbuffer(display, fbc[0], attrib );
#else
display=(Display *)wxGetDisplay();
int doubleBufferAttributess[] = {
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DOUBLEBUFFER, True,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
None
};
fbc=glXChooseFBConfig(display, DefaultScreen(display), doubleBufferAttributess, &ret);
GLXPbuffer pBuffer=glXCreatePbuffer(display, *fbc, attrib );
// TODO:
// have to setup a GLXFBConfig structure for wx2.8 because wx2.8 is crap.
// already done this crap but deleted it.. arggghh.....
// return &wxNullBitmap;
pbuffer=new pBufferGLX(width,height);
#endif
if (pBuffer == 0) {
wxLogError(wxT("pBuffer not availble"));
} catch(GLException e) {
// Should log already if failed..
return NULL;
}
}
GLXContext cx=0,gx=0;
// This function is not in WX sourcecode yet :(
//cx=shared_context->GetGLXContext();
if (!cx && real_shared_context) cx=real_shared_context; // Only available after redraw.. :(
else {
// First render screws up unless we do this..
gx=cx = glXCreateNewContext(display,*fbc,GLX_RGBA_TYPE, NULL, True);
if (pbuffer) {
pbuffer->UseBuffer(true);
}
// Move this bitmap code to pBuffer
//real_shared_context =
//GLXContext cx=real_shared_context;
if (cx == 0) {
wxLogError(wxT("CX not availble"));
}
#if !wxCHECK_VERSION(2,9,0)
XFree(fbc);
#endif
if (glXMakeCurrent(display,pBuffer,cx)!=True) {
wxLogError(wxT("Couldn't make buffer current"));
}
#endif
// glClearColor(1,1,0,1);
// glClearColor(1,1,0,1);
glClear(GL_COLOR_BUFFER_BIT);
// Can't use font's in multiple contexts
@ -1001,30 +841,25 @@ wxBitmap * gGraphWindow::RenderBitmap(int width,int height)
void* pixels = malloc(3 * width * height); // must use malloc
glPixelStorei(GL_PACK_ALIGNMENT, 1);
//glDrawBuffer(GL_BACK_LEFT);
//glReadBuffer(GL_FRONT);
glReadBuffer( GL_BACK_LEFT );
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);
glFlush();
#if defined(__WXMSW__)
wglDeleteContext(hGlRc);
wglReleasePbufferDCARB(hBuffer, hdc);
wglDestroyPbufferARB(hBuffer);
#elif defined(__DARWIN__) || defined (__WXMAC__)
#elif !defined(__WXMAC__) && defined (__UNIX__) // Linux
if (gx) glXDestroyContext(display,gx); // Destroy the context only if we created it..
glXDestroyPbuffer(display, pBuffer);
#endif
if (pbuffer) {
//delete pbuffer;
}
return bmp;
}
@ -1058,18 +893,21 @@ void gGraphWindow::Render(float scrX, float scrY)
(*l)->Plot(*this,scrX,scrY);
}
// glEnable(GL_DEPTH_TEST);
glEnable(GL_DEPTH_TEST);
}
void gGraphWindow::OnPaint(wxPaintEvent& event)
{
// Shouldn't need this anymore as opengl double buffers anyway.
//#if defined(__WXMSW__)
// wxAutoBufferedPaintDC dc(this);
//#else
wxPaintDC dc(this);
//#endif
//#if wxCHECK_VERSION(2,9,0)
//SetCurrent(*shared_context);
//#else
@ -1092,13 +930,13 @@ void gGraphWindow::OnPaint(wxPaintEvent& event)
if (m_mouseLDown) {
if (m_mouseRBrect.width>0)
glDisable(GL_DEPTH_TEST);
RoundedRectangle(m_mouseRBrect.x,m_mouseRBrect.y,m_mouseRBrect.width-1,m_mouseRBrect.height,5,*wxDARK_GREY);
glEnable(GL_DEPTH_TEST);
}
glEnable(GL_DEPTH_TEST);
SwapBuffers();
SwapBuffers(); // Dump to screen.
event.Skip();
}
@ -1348,10 +1186,10 @@ void gXAxis::Plot(gGraphWindow & w,float scrx,float scry)
{
float px,py;
int start_px=w.GetLeftMargin();
int start_py=w.GetTopMargin();
int width=scrx-(w.GetLeftMargin()+w.GetRightMargin());
int height=scry-(w.GetTopMargin()+w.GetBottomMargin());
//int start_px=w.GetLeftMargin();
//int start_py=w.GetTopMargin();
float width=scrx-(w.GetLeftMargin()+w.GetRightMargin());
// float height=scry-(w.GetTopMargin()+w.GetBottomMargin());
double xx=w.max_x-w.min_x;
@ -1637,7 +1475,7 @@ void gFooBar::Plot(gGraphWindow & w,float scrx,float scry)
int start_px=w.GetLeftMargin();
int width=scrx - (w.GetLeftMargin() + w.GetRightMargin());
int height=scry - (w.GetTopMargin() + w.GetBottomMargin());
// int height=scry - (w.GetTopMargin() + w.GetBottomMargin());
wxColor & col1=color[0];
wxColor & col2=color[1];
@ -2103,7 +1941,7 @@ void gLineOverlayBar::Plot(gGraphWindow & w,float scrx,float scry)
if (!data) return;
if (!data->IsReady()) return;
int start_px=w.GetLeftMargin();
//int start_px=w.GetLeftMargin();
int start_py=w.GetBottomMargin();
int width=scrx-(w.GetLeftMargin()+w.GetRightMargin());
int height=scry-(w.GetTopMargin()+w.GetBottomMargin());
@ -2122,7 +1960,7 @@ void gLineOverlayBar::Plot(gGraphWindow & w,float scrx,float scry)
wxColor & col=color[0];
for (int n=0;n<data->VC();n++) {
bool done=false;
// bool done=false;
bool first=true;
int fi=0,li;
for (li=0;li<data->np[n];li++) {
@ -2278,7 +2116,7 @@ void gFlagsLine::Plot(gGraphWindow & w,float scrx,float scry)
for (int n=0;n<data->VC();n++) {
bool done=false;
//bool done=false;
bool first=true;
for (li=0;li<data->np[n];li++) { //,done==false
if (data->point[n][li].m_y < w.min_x) continue;

View File

@ -7,30 +7,14 @@ License: LGPL
#ifndef GRAPH_H
#define GRAPH_H
#define GL_GLEXT_PROTOTYPES
//#define _UNICODE 1
#include "gl_pbuffer.h"
extern pBuffer *buffer;
#ifdef __DARWIN__
#include <OpenGL/gl.h>
#include <AGL/agl.h>
#elif defined(__WXMSW__)
//#undef Yield
#define GLEW_STATIC
#define WGL_WGLEXT_PROTOTYPES
//#include <windows.h>
#include <GL/glew.h>
#include <GL/wglew.h>
//#include <GL/freeglut_std.h>
//#include <GL/freeglut_ext.h>
// windows gl extensions
#endif
#undef Yield
#include <wx/dcgraph.h>
//#include <wx/dcgraph.h>
#include <wx/glcanvas.h>
//#include <FTGL/ftgl.h>
#include <wx/geometry.h>
#include <sleeplib/machine.h>
#include <list>
@ -143,7 +127,6 @@ public:
extern wxGLContext *shared_context;
class gGraphWindow:public wxGLCanvas //Window // rename to gGraphWindow
{
public:

View File

@ -16,14 +16,14 @@ namespace AutoVersion{
//Standard Version Type
static const long _MAJOR = 0;
static const long _MINOR = 7;
static const long _BUILD = 5742;
static const long _REVISION = 14712;
static const long _BUILD = 5861;
static const long _REVISION = 15371;
//Miscellaneous Version Types
static const long _BUILDS_COUNT = 6072;
#define _RC_FILEVERSION 0,7,5742,14712
#define _RC_FILEVERSION_STRING "0, 7, 5742, 14712\0"
static const char _FULLVERSION_STRING[] = "0.7.5742.14712";
static const long _BUILDS_COUNT = 6256;
#define _RC_FILEVERSION 0,7,5861,15371
#define _RC_FILEVERSION_STRING "0, 7, 5861, 15371\0"
static const char _FULLVERSION_STRING[] = "0.7.5861.15371";
//These values are to keep track of your versioning state, don't modify them.
static const long _BUILD_HISTORY = 0;