dynamically switch between OpenGL 2 and OpenGL 3 (test gwen)
This commit is contained in:
@@ -305,67 +305,59 @@ extern int avoidUpdate;
|
||||
int main()
|
||||
{
|
||||
|
||||
//#define TEST_OPENGL2_GWEN
|
||||
#ifdef TEST_OPENGL2_GWEN
|
||||
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
|
||||
window->setKeyboardCallback(keyCallback);
|
||||
b3gWindowConstructionInfo wci;
|
||||
wci.m_openglVersion = 2;
|
||||
wci.m_width = sWidth;
|
||||
wci.m_height = sHeight;
|
||||
// wci.m_resizeCallback = MyResizeCallback;
|
||||
|
||||
window->createWindow(wci);
|
||||
window->setResizeCallback(MyResizeCallback);
|
||||
window->setWindowTitle("render test");
|
||||
|
||||
// Gwen::Renderer::OpenGL_DebugFont* pRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
int majorGlVersion, minorGlVersion;
|
||||
|
||||
if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2)
|
||||
{
|
||||
printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n");
|
||||
exit(0);
|
||||
}
|
||||
if (majorGlVersion>=3)
|
||||
{
|
||||
float retinaScale = 1.f;
|
||||
|
||||
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();
|
||||
|
||||
// Main OpenGL Render Loop
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
window->endRendering();
|
||||
}
|
||||
*/
|
||||
//exit(0);
|
||||
#else
|
||||
|
||||
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__
|
||||
glewInit();
|
||||
glewInit();
|
||||
#endif
|
||||
|
||||
retinaScale = window->getRetinaScale();
|
||||
retinaScale = window->getRetinaScale();
|
||||
|
||||
primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
|
||||
primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
|
||||
|
||||
sth_stash* font = initFont(primRenderer );
|
||||
sth_stash* font = initFont(primRenderer );
|
||||
|
||||
|
||||
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
|
||||
#endif
|
||||
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
|
||||
|
||||
} 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;
|
||||
while( !window->requestedExit() )
|
||||
{
|
||||
|
||||
saveOpenGLState(sWidth,sHeight);
|
||||
if (majorGlVersion<3)
|
||||
{
|
||||
saveOpenGLState(sWidth,sHeight);
|
||||
}
|
||||
|
||||
// Skip out if the window is closed
|
||||
//if ( !IsWindowVisible( g_pHWND ) )
|
||||
@@ -508,7 +502,11 @@ glClearColor(1,0,0,1);
|
||||
// SwapBuffers( GetDC( g_pHWND ) );
|
||||
}
|
||||
window->endRendering();
|
||||
restoreOpenGLState();
|
||||
|
||||
if (majorGlVersion<3)
|
||||
{
|
||||
restoreOpenGLState();
|
||||
}
|
||||
}
|
||||
|
||||
window->closeWindow();
|
||||
|
||||
@@ -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
|
||||
//support HighResolutionOSX for Retina Macbook
|
||||
[m_internalData->m_myview setWantsBestResolutionOpenGLSurface:YES];
|
||||
|
||||
if (ci.m_openglVersion>=3)
|
||||
{
|
||||
[m_internalData->m_myview setWantsBestResolutionOpenGLSurface:YES];
|
||||
}
|
||||
NSSize sz;
|
||||
sz.width = 1;
|
||||
sz.height = 1;
|
||||
@@ -354,16 +356,9 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
||||
|
||||
[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];
|
||||
glGenBuffers(n, vbo);
|
||||
checkError("glGenBuffers");
|
||||
|
||||
[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_height = m_internalData->m_myview.GetWindowHeight;
|
||||
|
||||
glGenBuffers(n, vbo);
|
||||
checkError("glGenBuffers");
|
||||
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
glGenBuffers(n, vbo);
|
||||
checkError("glGenBuffers");
|
||||
|
||||
|
||||
//[m_internalData->m_window setLevel:NSMainMenuWindowLevel];
|
||||
|
||||
Reference in New Issue
Block a user