dynamically switch between OpenGL 2 and OpenGL 3 (test gwen)
This commit is contained in:
@@ -305,54 +305,29 @@ extern int avoidUpdate;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
//#define TEST_OPENGL2_GWEN
|
|
||||||
#ifdef TEST_OPENGL2_GWEN
|
|
||||||
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
|
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
|
||||||
window->setKeyboardCallback(keyCallback);
|
window->setKeyboardCallback(keyCallback);
|
||||||
b3gWindowConstructionInfo wci;
|
b3gWindowConstructionInfo wci;
|
||||||
|
wci.m_openglVersion = 2;
|
||||||
wci.m_width = sWidth;
|
wci.m_width = sWidth;
|
||||||
wci.m_height = sHeight;
|
wci.m_height = sHeight;
|
||||||
// wci.m_resizeCallback = MyResizeCallback;
|
// wci.m_resizeCallback = MyResizeCallback;
|
||||||
|
|
||||||
window->createWindow(wci);
|
window->createWindow(wci);
|
||||||
window->setResizeCallback(MyResizeCallback);
|
window->setResizeCallback(MyResizeCallback);
|
||||||
window->setWindowTitle("render test");
|
window->setWindowTitle("render test");
|
||||||
|
|
||||||
// Gwen::Renderer::OpenGL_DebugFont* pRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
int majorGlVersion, minorGlVersion;
|
||||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
|
||||||
|
|
||||||
|
if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2)
|
||||||
skin.SetRender( gwenRenderer );
|
|
||||||
|
|
||||||
pCanvas = new Gwen::Controls::Canvas( &skin );
|
|
||||||
pCanvas->SetSize( sWidth, sHeight);
|
|
||||||
pCanvas->SetDrawBackground( true );
|
|
||||||
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
|
|
||||||
|
|
||||||
glClearColor(1,0,0,1);
|
|
||||||
/* while( !window->requestedExit() )
|
|
||||||
{
|
{
|
||||||
window->startRendering();
|
printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n");
|
||||||
|
exit(0);
|
||||||
// Main OpenGL Render Loop
|
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
||||||
window->endRendering();
|
|
||||||
}
|
}
|
||||||
*/
|
if (majorGlVersion>=3)
|
||||||
//exit(0);
|
{
|
||||||
#else
|
|
||||||
|
|
||||||
float retinaScale = 1.f;
|
float retinaScale = 1.f;
|
||||||
|
|
||||||
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
|
|
||||||
window->setKeyboardCallback(keyCallback);
|
|
||||||
b3gWindowConstructionInfo wci;
|
|
||||||
wci.m_width = sWidth;
|
|
||||||
wci.m_height = sHeight;
|
|
||||||
// wci.m_resizeCallback = MyResizeCallback;
|
|
||||||
window->createWindow(wci);
|
|
||||||
|
|
||||||
window->setResizeCallback(MyResizeCallback);
|
|
||||||
window->setWindowTitle("render test");
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
glewInit();
|
glewInit();
|
||||||
#endif
|
#endif
|
||||||
@@ -365,7 +340,24 @@ glClearColor(1,0,0,1);
|
|||||||
|
|
||||||
|
|
||||||
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
|
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
|
||||||
#endif
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
//OpenGL 2.x
|
||||||
|
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||||
|
|
||||||
|
|
||||||
|
skin.SetRender( gwenRenderer );
|
||||||
|
|
||||||
|
pCanvas = new Gwen::Controls::Canvas( &skin );
|
||||||
|
pCanvas->SetSize( sWidth, sHeight);
|
||||||
|
pCanvas->SetDrawBackground( true );
|
||||||
|
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
|
||||||
|
|
||||||
|
glClearColor(1,0,0,1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -418,8 +410,10 @@ glClearColor(1,0,0,1);
|
|||||||
// MSG msg;
|
// MSG msg;
|
||||||
while( !window->requestedExit() )
|
while( !window->requestedExit() )
|
||||||
{
|
{
|
||||||
|
if (majorGlVersion<3)
|
||||||
|
{
|
||||||
saveOpenGLState(sWidth,sHeight);
|
saveOpenGLState(sWidth,sHeight);
|
||||||
|
}
|
||||||
|
|
||||||
// Skip out if the window is closed
|
// Skip out if the window is closed
|
||||||
//if ( !IsWindowVisible( g_pHWND ) )
|
//if ( !IsWindowVisible( g_pHWND ) )
|
||||||
@@ -508,8 +502,12 @@ glClearColor(1,0,0,1);
|
|||||||
// SwapBuffers( GetDC( g_pHWND ) );
|
// SwapBuffers( GetDC( g_pHWND ) );
|
||||||
}
|
}
|
||||||
window->endRendering();
|
window->endRendering();
|
||||||
|
|
||||||
|
if (majorGlVersion<3)
|
||||||
|
{
|
||||||
restoreOpenGLState();
|
restoreOpenGLState();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window->closeWindow();
|
window->closeWindow();
|
||||||
delete window;
|
delete window;
|
||||||
|
|||||||
@@ -339,8 +339,10 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
|||||||
|
|
||||||
// https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//apple_ref/doc/uid/TP40012302-CH10-SW1
|
// https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//apple_ref/doc/uid/TP40012302-CH10-SW1
|
||||||
//support HighResolutionOSX for Retina Macbook
|
//support HighResolutionOSX for Retina Macbook
|
||||||
|
if (ci.m_openglVersion>=3)
|
||||||
|
{
|
||||||
[m_internalData->m_myview setWantsBestResolutionOpenGLSurface:YES];
|
[m_internalData->m_myview setWantsBestResolutionOpenGLSurface:YES];
|
||||||
|
}
|
||||||
NSSize sz;
|
NSSize sz;
|
||||||
sz.width = 1;
|
sz.width = 1;
|
||||||
sz.height = 1;
|
sz.height = 1;
|
||||||
@@ -354,16 +356,9 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
|||||||
|
|
||||||
[m_internalData->m_window setContentView: m_internalData->m_myview];
|
[m_internalData->m_window setContentView: m_internalData->m_myview];
|
||||||
|
|
||||||
GLuint n = 1;
|
|
||||||
GLuint vbo[3]={-1,-1,-1};
|
|
||||||
|
|
||||||
glGenBuffers(n, vbo);
|
|
||||||
checkError("glGenBuffers");
|
|
||||||
|
|
||||||
|
|
||||||
[m_internalData->m_window setDelegate:(id) m_internalData->m_myview];
|
[m_internalData->m_window setDelegate:(id) m_internalData->m_myview];
|
||||||
glGenBuffers(n, vbo);
|
|
||||||
checkError("glGenBuffers");
|
|
||||||
|
|
||||||
[m_internalData->m_window makeKeyAndOrderFront: nil];
|
[m_internalData->m_window makeKeyAndOrderFront: nil];
|
||||||
|
|
||||||
@@ -371,12 +366,8 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
|||||||
m_internalData->m_width = m_internalData->m_myview.GetWindowWidth;
|
m_internalData->m_width = m_internalData->m_myview.GetWindowWidth;
|
||||||
m_internalData->m_height = m_internalData->m_myview.GetWindowHeight;
|
m_internalData->m_height = m_internalData->m_myview.GetWindowHeight;
|
||||||
|
|
||||||
glGenBuffers(n, vbo);
|
|
||||||
checkError("glGenBuffers");
|
|
||||||
|
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
glGenBuffers(n, vbo);
|
|
||||||
checkError("glGenBuffers");
|
|
||||||
|
|
||||||
|
|
||||||
//[m_internalData->m_window setLevel:NSMainMenuWindowLevel];
|
//[m_internalData->m_window setLevel:NSMainMenuWindowLevel];
|
||||||
|
|||||||
Reference in New Issue
Block a user