void GlutWindow::init(int & argc, char * argv []) { glutInit(&argc, argv); glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); glutCreateWindow(programName); printGLInfo(); GLenum glewErr = glewInit(); if (GLEW_OK != glewErr) { /* Problem: glewInit failed, something is seriously wrong. */ std::cout << glewGetErrorString(glewErr) << std::endl; } glutDisplayFunc(frwDisplay); //glutReshapeFunc(GL_FALSE); // TODO: reshape when I'm not lazy glutKeyboardFunc(frwKeyboard); glutIdleFunc(frwIdle); glutMouseFunc(frwMouseClick); glutMotionFunc(frwMouseMove); deferredShader.init(camera); scene.loadContent(contentManager); camera.setCameraPerspective(30.0,1.5,5.0,1000.0); camera.setCameraPosition( glm::vec3(-26.0,10.0,-20.0), glm::vec3(0.0,4.0,0.0), glm::vec3(0.0,1.0,0.0)); camera.setCameraSpeed(0.01); glutWarpPointer(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); // Reset mouse //glutSetCursor(GLUT_CURSOR_NONE); }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ if (key == ' '){ // todo: rewrite this with ofLog: FILE *fp; if((fp=freopen(ofToDataPath("openglReport.txt").c_str(), "w" ,stdout))==NULL) { cout << "Cannot open file.\n"; return; } cout << "-------------------------------------------------\n"; cout << "opengl info\n"; cout << "-------------------------------------------------\n"; printGLInfo(); cout << "-------------------------------------------------\n"; cout << "opengl limits\n"; cout << "-------------------------------------------------\n"; print_limits(); cout << "-------------------------------------------------\n"; cout << "shader limits\n"; cout << "-------------------------------------------------\n"; printShaderLimits(); cout << "-------------------------------------------------\n"; cout << "available extensions\n"; cout << "-------------------------------------------------\n"; const GLubyte * strExt; strExt = glGetString (GL_EXTENSIONS); //cout << "extensions: " << strExt << endl; print_extension_list((char *)strExt); //isShade = gluCheckExtension ((const GLubyte*)"GL_ARB_shading_language_100", strExt); cout << "-------------------------------------------------\n"; cout << "opengl calls available\n"; cout << "-------------------------------------------------\n"; printGlewInfo(); fclose(fp); #ifdef TARGET_WIN32 string command = "start " + ofToString(ofToDataPath("openglReport.txt").c_str()); #elif defined(TARGET_LINUX) string command = "xdg-open " + ofToString(ofToDataPath("openglReport.txt").c_str()); #else string command = "open " + ofToString(ofToDataPath("openglReport.txt").c_str()); #endif if (0 != system(command.c_str())){ ofLogWarning() << "Command " << command.c_str() << " did not return 0. Something may have gone wrong."; } } }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ if (key == ' '){ // todo: rewrite this with ofLog: FILE *fp; if((fp=freopen(ofToDataPath("openglReport.txt").c_str(), "w" ,stdout))==NULL) { printf("Cannot open file.\n"); return; } printf("-------------------------------------------------\n"); printf("opengl info\n"); printf("-------------------------------------------------\n"); printGLInfo(); printf("-------------------------------------------------\n"); printf("opengl limits\n"); printf("-------------------------------------------------\n"); print_limits(); printf("-------------------------------------------------\n"); printf("shader limits\n"); printf("-------------------------------------------------\n"); printShaderLimits(); printf("-------------------------------------------------\n"); printf("available extensions\n"); printf("-------------------------------------------------\n"); const GLubyte * strExt; strExt = glGetString (GL_EXTENSIONS); //cout << "extensions: " << strExt << endl; print_extension_list((char *)strExt); //isShade = gluCheckExtension ((const GLubyte*)"GL_ARB_shading_language_100", strExt); printf("-------------------------------------------------\n"); printf("opengl calls available\n"); printf("-------------------------------------------------\n"); printGlewInfo(); fclose(fp); string command = "open " + ofToString(ofToDataPath("openglReport.txt").c_str()); system(command.c_str()); } }
int rgssThreadFun(void *userdata) { RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata); const Config &conf = threadData->config; SDL_Window *win = threadData->window; SDL_GLContext glCtx; /* Setup GL context */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if (conf.debugMode) SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); glCtx = SDL_GL_CreateContext(win); if (!glCtx) { rgssThreadError(threadData, std::string("Error creating context: ") + SDL_GetError()); return 0; } try { initGLFunctions(); } catch (const Exception &exc) { rgssThreadError(threadData, exc.msg); SDL_GL_DeleteContext(glCtx); return 0; } if (!conf.enableBlitting) gl.BlitFramebuffer = 0; gl.ClearColor(0, 0, 0, 1); gl.Clear(GL_COLOR_BUFFER_BIT); SDL_GL_SwapWindow(win); printGLInfo(); bool vsync = conf.vsync || conf.syncToRefreshrate; SDL_GL_SetSwapInterval(vsync ? 1 : 0); GLDebugLogger dLogger; /* Setup AL context */ ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0); if (!alcCtx) { rgssThreadError(threadData, "Error creating OpenAL context"); SDL_GL_DeleteContext(glCtx); return 0; } alcMakeContextCurrent(alcCtx); try { SharedState::initInstance(threadData); } catch (const Exception &exc) { rgssThreadError(threadData, exc.msg); alcDestroyContext(alcCtx); SDL_GL_DeleteContext(glCtx); return 0; } /* Start script execution */ scriptBinding->execute(); threadData->rqTermAck.set(); threadData->ethread->requestTerminate(); SharedState::finiInstance(); alcDestroyContext(alcCtx); SDL_GL_DeleteContext(glCtx); return 0; }
void Screen::begin(const std::string& path) { batb->log << "batb->screen->begin( " << path << " )" << std::endl; LogIndent indent( batb->log, "* " ); if ( init_empty() ) { // set configuration file config( path ); //////////////////////////////////////////////////////////////////////////////// // setup GLFW // glfwSetErrorCallback( glfw_error_callback ); if ( !glfwInit() ) { batb->log << "ERROR: could not initialize GLFW" << std::endl; throw std::runtime_error( "Screen: Could not init GLFW" ); } //////////////////////////////////////////////////////////////////////////////// // screen bool debugctx = yaml["debug"].as<bool>( false ); glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, debugctx ); // debug symbols (?) batb->log << "debug context = " << debugctx << std::endl; // multisamples uint samples = 0; if ( YAML::Node node = yaml[ "multisamples" ] ) { samples = node.as<uint>( samples ); glfwWindowHint( GLFW_SAMPLES, samples ); } batb->log << "multisamples = " << samples << std::endl; // size uint wth = 640; uint hth = 480; if ( YAML::Node node = yaml[ "size" ] ) { wth = node[ "wth" ].as<uint>( wth ); hth = node[ "hth" ].as<uint>( hth ); } batb->log << "window size = " << wth << "x" << hth << std::endl; // fullscreen bool fullscreen = false; if ( YAML::Node node = yaml[ "fullscreen" ] ) { glfw_monitor = node.as<bool>( fullscreen ) ? glfwGetPrimaryMonitor() : 0; // if we create a fullscreen window, let us use the display's resolution if ( glfw_monitor ) { if ( auto mode = glfwGetVideoMode( glfw_monitor ) ) { // save before we set fullscreen nonfullscreen_wth_ = wth; nonfullscreen_hth_ = hth; wth = mode->width; hth = mode->height; } } } batb->log << "window fullscreen = " << fullscreen; if ( fullscreen ) batb->log << " (overriding window size with display resolution (" << wth << "x" << hth << ")"; batb->log->endl(); // title std::string title = ""; if ( YAML::Node node = yaml[ "title" ] ) { title = node.as<std::string>( title ); } batb->log << "window title = " << title << std::endl; // set addioninal windown hints // http://www.glfw.org/docs/latest/window.html#window_hints if ( YAML::Node node = yaml[ "glfw-hints" ] ) { batb->log << "GLFW hints:" << std::endl; LogIndent indent( batb->log, "- " ); for (auto p : node) { auto hint = p.first.as<std::string>(); auto value = p.second.as<std::string>(""); constexpr uint padding = 30; std::string pad( hint.size() < padding ? (padding - hint.size()) : 0, ' ' ); batb->log << hint << pad << " = " << value; if ( glfw_set_windowhint( hint, value ) ) { batb->log->endl(); } else { batb->log << " (WARNING: could not set)" << std::endl; } } } // NOTE: error in implementation of glfw, according to valgrind: glfw_window = glfwCreateWindow( wth, hth, title.c_str(), glfw_monitor, 0 ); // set GL context as 'theWindow_' glfwMakeContextCurrent( glfw_window ); if ( !glfw_window ) { batb->log << "ERROR: could not create GLFW window" << std::endl; throw std::runtime_error( "Screen: could not create GLFW window" ); } // we now have a context, init GLEW // or other, see // * http://www.glfw.org/docs/latest/context_guide.html#context_glext_auto // * https://www.khronos.org/opengl/wiki/OpenGL_Loading_Library GLenum err = glewInit(); if ( err != GLEW_OK ) { batb->log << "ERROR: could not initialize the OpenGL loading library (GLEW): " << glewGetErrorString( err ) << std::endl; std::ostringstream os; os << "Screen: could not init GLEW (" << glewGetErrorString( err ) << ")"; throw std::runtime_error( os.str() ); } // print verbose GL info if ( YAML::Node node = yaml[ "info" ] ) { if ( node.as<bool>() ) { printGLInfo(); } } } init( true ); }
int rgssThreadFun(void *userdata) { RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata); SDL_Window *win = threadData->window; SDL_GLContext glCtx; /* Setup GL context */ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if (threadData->config.debugMode) SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); glCtx = SDL_GL_CreateContext(win); if (!glCtx) { rgssThreadError(threadData, std::string("Error creating context: ") + SDL_GetError()); return 0; } if (glewInit() != GLEW_OK) { rgssThreadError(threadData, "Error initializing glew"); SDL_GL_DeleteContext(glCtx); return 0; } glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SDL_GL_SwapWindow(win); printGLInfo(); /* Check for required GL version */ if (!GLEW_VERSION_2_0) { rgssThreadError(threadData, "At least OpenGL 2.0 is required"); SDL_GL_DeleteContext(glCtx); return 0; } /* Setup optional GL extensions */ if (!setupOptionalGLExtensions(threadData)) { SDL_GL_DeleteContext(glCtx); return 0; } SDL_GL_SetSwapInterval(threadData->config.vsync ? 1 : 0); DebugLogger dLogger; /* Setup AL context */ ALCdevice *alcDev = alcOpenDevice(0); if (!alcDev) { rgssThreadError(threadData, "Error opening OpenAL device"); SDL_GL_DeleteContext(glCtx); return 0; } ALCcontext *alcCtx = alcCreateContext(alcDev, 0); if (!alcCtx) { rgssThreadError(threadData, "Error creating OpenAL context"); alcCloseDevice(alcDev); SDL_GL_DeleteContext(glCtx); return 0; } alcMakeContextCurrent(alcCtx); try { SharedState::initInstance(threadData); } catch (const Exception &exc) { rgssThreadError(threadData, exc.msg); alcDestroyContext(alcCtx); alcCloseDevice(alcDev); SDL_GL_DeleteContext(glCtx); return 0; } /* Start script execution */ scriptBinding->execute(); threadData->rqTermAck = true; threadData->ethread->requestTerminate(); SharedState::finiInstance(); alcDestroyContext(alcCtx); alcCloseDevice(alcDev); SDL_GL_DeleteContext(glCtx); return 0; }