static GLboolean valid_version(void) { int major, minor, revision; glfwGetVersion(&major, &minor, &revision); printf("GLFW header version: %u.%u.%u\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); printf("GLFW library version: %u.%u.%u\n", major, minor, revision); if (major != GLFW_VERSION_MAJOR) { printf("*** ERROR: GLFW major version mismatch! ***\n"); return GL_FALSE; } if (minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION) printf("*** WARNING: GLFW version mismatch! ***\n"); printf("GLFW library version string: \"%s\"\n", glfwGetVersionString()); return GL_TRUE; }
void printGLFWversion() { int majorVersion; int minorVersion; int rev; glfwGetVersion(&majorVersion, &minorVersion, &rev); printf("GLFW version: %d.%d.%d\n", majorVersion, minorVersion, rev); }
int main (void) { // MIDI init if (!MIDIController.init()) { std::cerr << "Error: Cannot initiate MIDI!" << std::endl; system("PAUSE"); return -1; } // GLFW init GLFWwindow * window; glfwSetErrorCallback (errorCallback); if (!glfwInit()) { std::cerr << "Error: Cannot initiate GLFW!" << std::endl; return -2; } // print glfw version int glfwMaj, glfwMin, glfwRev; glfwGetVersion(&glfwMaj, &glfwMin, &glfwRev); std::cout << "Initialized GLFW " << glfwMaj << "." << glfwMin << "." << glfwRev << std::endl; window = createWindow(); if (!window) { glfwTerminate(); return -3; } glfwMakeContextCurrent(window); std::cout << "Using OpenGL " << glGetString(GL_VERSION) << std::endl; // GLEW init GLenum err = glewInit(); if (GLEW_OK != err) { std::cerr << "Error: " << glewGetErrorString(err) << std::endl; glfwDestroyWindow(window); glfwTerminate(); return -4; } std::cout << "Initialized GLEW " << glewGetString(GLEW_VERSION) << std::endl; //DevIL ilInit(); // Leftover inits -- controller, models, shaders, callbacks rejfpankInit(window); // main loop while (!glfwWindowShouldClose(window)) { controller.redraw(window); controller.update(); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; }
util::VersionInfo Application::initGLFW() { int maj,min,patch; if(glfwInit() == GL_FALSE) { throw APIError("Initialization of GLFW failed!"); } glfwGetVersion(&maj,&min,&patch); return util::VersionInfo(maj,min,patch); }
static void print_version(void) { int major, minor, revision; glfwGetVersion(&major, &minor, &revision); printf("GLFW header version: %u.%u.%u\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); printf("GLFW library version: %u.%u.%u\n", major, minor, revision); printf("GLFW library version string: \"%s\"\n", glfwGetVersionString()); }
Visualization::Visualization(ros::NodeHandle handleNode, string strMapTopic) { m_bInitialized = (glfwInit() == GL_TRUE ? true : false); if(m_bInitialized) { int nMajor, nMinor, nRev; glfwGetVersion(&nMajor, &nMinor, &nRev); ROS_INFO("Running GLFW version %d.%d (rev %d)", nMajor, nMinor, nRev); m_imgCameraFrame.Data = NULL; m_mapMap = new Map(handleNode, strMapTopic, 200, 200); } else { ROS_INFO("GLFW failed to initialize."); } }
int main(int argc, char** argv) { int glfwver[3] = {0}; if(start_gfx("Distance And Modular Entities",512, 512)) { return 1; } glfwGetVersion(&glfwver[0], &glfwver[1], &glfwver[2]); printf("Using GL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION)); demo2(); stop_gfx(); return 0; }
static int valid_version(void) { int major, minor, revision; glfwGetVersion(&major, &minor, &revision); if (major != GLFW_VERSION_MAJOR) { printf("*** ERROR: GLFW major version mismatch! ***\n"); return GLFW_FALSE; } if (minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION) printf("*** WARNING: GLFW version mismatch! ***\n"); return GLFW_TRUE; }
void GLFWBackendInit(int argc, char** argv, bool WithDepth, bool WithStencil) { sWithDepth = WithDepth; sWithStencil = WithStencil; if (glfwInit() != 1) { OGLDEV_ERROR("Error initializing GLFW"); exit(1); } int Major, Minor, Rev; glfwGetVersion(&Major, &Minor, &Rev); printf("GLFW %d.%d.%d initialized\n", Major, Minor, Rev); glfwSetErrorCallback(GLFWErrorCallback); }
void call(int* major, int* minor, int* rev) { return glfwGetVersion(major, minor, rev); }
int main(int argc, char** argv) { int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision; GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE; GLint flags, mask; GLFWwindow window; while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1) { switch (ch) { case 'd': debug = GL_TRUE; break; case 'f': forward = GL_TRUE; break; case 'h': usage(); exit(EXIT_SUCCESS); case 'l': list = GL_TRUE; break; case 'm': major = atoi(optarg); break; case 'n': minor = atoi(optarg); break; case 'p': if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0) profile = GLFW_OPENGL_CORE_PROFILE; else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0) profile = GLFW_OPENGL_COMPAT_PROFILE; else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0) profile = GLFW_OPENGL_ES2_PROFILE; else { usage(); exit(EXIT_FAILURE); } break; case 'r': if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0) strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION; else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0) strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET; else { usage(); exit(EXIT_FAILURE); } break; default: usage(); exit(EXIT_FAILURE); } } argc -= optind; argv += optind; glfwSetErrorCallback(error_callback); if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); } if (major != 1 || minor != 0) { glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, major); glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, minor); } if (debug) glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); if (forward) glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); if (profile != 0) glfwWindowHint(GLFW_OPENGL_PROFILE, profile); if (strategy) glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy); // We assume here that we stand a better chance of success by leaving all // possible details of pixel format selection to GLFW window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Version", NULL); if (!window) exit(EXIT_FAILURE); glfwMakeContextCurrent(window); // Report GLFW version glfwGetVersion(&major, &minor, &revision); printf("GLFW header version: %u.%u.%u\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); printf("GLFW library version: %u.%u.%u\n", major, minor, revision); if (major != GLFW_VERSION_MAJOR || minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION) { printf("*** WARNING: GLFW version mismatch! ***\n"); } printf("GLFW library version string: \"%s\"\n", glfwGetVersionString()); // Report OpenGL version printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION)); major = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MAJOR); minor = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MINOR); revision = glfwGetWindowParam(window, GLFW_OPENGL_REVISION); printf("OpenGL context version parsed by GLFW: %u.%u.%u\n", major, minor, revision); // Report OpenGL context properties if (major >= 3) { glGetIntegerv(GL_CONTEXT_FLAGS, &flags); printf("OpenGL context flags (0x%08x):", flags); if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) printf(" forward-compatible"); if (flags & 0) printf(" debug"); putchar('\n'); printf("OpenGL context flags parsed by GLFW:"); if (glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT)) printf(" forward-compatible"); if (glfwGetWindowParam(window, GLFW_OPENGL_DEBUG_CONTEXT)) printf(" debug"); putchar('\n'); } if (major > 3 || (major == 3 && minor >= 2)) { glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); printf("OpenGL profile mask (0x%08x): %s\n", mask, get_profile_name(mask)); printf("OpenGL profile mask parsed by GLFW: %s\n", get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE))); } printf("OpenGL context renderer string: \"%s\"\n", glGetString(GL_RENDERER)); printf("OpenGL context vendor string: \"%s\"\n", glGetString(GL_VENDOR)); if (major > 1) { printf("OpenGL context shading language version: \"%s\"\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); } // Report OpenGL extensions if (list) list_extensions(major, minor); glfwTerminate(); exit(EXIT_SUCCESS); }
void Image::show(const char * title) { fprintf(stderr, "Showing image %s.\n", title); glfwSetErrorCallback(error_char); if (!glfwInit()) return; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); GLFWwindow * pWindow = NULL; if (title == 0) pWindow = glfwCreateWindow(_width, _height, "Image", NULL, NULL); else pWindow = glfwCreateWindow(_width, _height, title, NULL, NULL); if (!pWindow) { fprintf(stderr, "\nGLFW Window creation failed.\n"); glfwTerminate(); return; } else { int major, minor, rev; glfwMakeContextCurrent(pWindow); #ifdef WIN_COMPILE glewExperimental=GL_TRUE; if (glewInit() != GLEW_OK) { fprintf(stderr, "GLEW initialization failed.\n"); return; } #endif glfwGetVersion(&major, &minor, &rev); fprintf(stderr, "OpenGL version recieved: %d.%d.%d.\n", major, minor, rev); } glfwSwapInterval(1); glfwSetKeyCallback(pWindow, key_callback); //After the openGL context is set up, initialize openGL initializeDraw(); //Then load data into a texture { glGenTextures(1, &GLInfo._tex); glBindTexture(GL_TEXTURE_2D, GLInfo._tex); 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_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _width, _height, 0, GL_RGBA, GL_UNSIGNED_BYTE, _buf); GLuint tex_id = glGetUniformLocation(GLInfo._pid, "tex"); glUniform1i(tex_id, 0 /*GL_TEXTURE0*/); } glUseProgram(GLInfo._pid); glBindVertexArray(GLInfo._vao); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, GLInfo._tex); //ok we're ready. Let glfw do the msg loop and draw the quad while (!glfwWindowShouldClose(pWindow)) { glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glfwSwapBuffers(pWindow); glfwPollEvents(); } /// Close OpenGL window and terminate GLFW glfwDestroyWindow(pWindow); cleanupDraw(); glfwTerminate(); }
int main(int argc, char** argv) { #if defined(_WIN32) LOG_INFO("Windows build."); #elif defined(_LINUX) LOG_INFO("Linux build."); #elif defined(_MACOS) LOG_INFO("MacOS build."); #endif bool useOpenGLCoreContext = false; #ifdef USE_CORE_CONTEXT useOpenGLCoreContext = true; #endif g_renderMode.outputType = RenderingMode::OVR_SDK; LOG_INFO("Using GLFW3 backend."); LOG_INFO("Compiled against GLFW %i.%i.%i", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); int major, minor, revision; glfwGetVersion(&major, &minor, &revision); LOG_INFO("Running against GLFW %i.%i.%i", major, minor, revision); LOG_INFO("glfwGetVersionString: %s", glfwGetVersionString()); // Command line options for (int i=0; i<argc; ++i) { const std::string a = argv[i]; LOG_INFO("argv[%d]: %s", i, a.c_str()); if (!a.compare("-sdk")) { g_renderMode.outputType = RenderingMode::OVR_SDK; } else if (!a.compare("-client")) { g_renderMode.outputType = RenderingMode::OVR_Client; } else if (!a.compare("-core")) { useOpenGLCoreContext = true; } else if (!a.compare("-compat")) { useOpenGLCoreContext = false; } } #ifdef USE_OCULUSSDK g_app.initHMD(); #else g_renderMode.outputType = RenderingMode::Mono_Buffered; #endif GLFWwindow* l_Window = NULL; glfwSetErrorCallback(ErrorCallback); if (!glfwInit()) { exit(EXIT_FAILURE); } // Log system monitor information const GLFWmonitor* pPrimary = glfwGetPrimaryMonitor(); int monitorCount = 0; GLFWmonitor** ppMonitors = glfwGetMonitors(&monitorCount); for (int i=0; i<monitorCount; ++i) { GLFWmonitor* pCur = ppMonitors[i]; const GLFWvidmode* mode = glfwGetVideoMode(pCur); if (mode != NULL) { (void)pPrimary; LOG_INFO("Monitor #%d: %dx%d @ %dHz %s", i, mode->width, mode->height, mode->refreshRate, pCur==pPrimary ? "Primary":""); } } bool swapBackBufferDims = false; // Context setup - before window creation glfwWindowHint(GLFW_DEPTH_BITS, 16); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, useOpenGLCoreContext ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE); //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #ifdef _DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif #if defined(USE_OSVR) std::string windowTitle = ""; windowTitle = PROJECT_NAME "-GLFW-Osvr"; if (g_app.UsingDebugHmd()) { const hmdRes sz = { 800, 600 }; // Create a normal, decorated application window LOG_INFO("Using Debug HMD mode."); windowTitle = PROJECT_NAME "-GLFW-DebugHMD"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); } else { const hmdRes sz = { g_app.getHmdResolution().h, g_app.getHmdResolution().w }; const winPos pos = g_app.getHmdWindowPos(); g_renderMode.outputType = RenderingMode::SideBySide_Undistorted; LOG_INFO("Using Extended desktop mode."); windowTitle = PROJECT_NAME "-GLFW-Extended"; LOG_INFO("Creating GLFW_DECORATED window %dx%d@%d,%d", sz.w, sz.h, pos.x, pos.y); glfwWindowHint(GLFW_DECORATED, 0); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); glfwWindowHint(GLFW_DECORATED, 1); glfwSetInputMode(l_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetWindowPos(l_Window, pos.x, pos.y); } #elif defined(OVRSDK06) std::string windowTitle = ""; LOG_INFO("Using SDK 0.6.0.0's direct mode."); windowTitle = PROJECT_NAME "-GLFW-06-Direct"; GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); ovrSizei sz; ovrVector2i pos; sz.w = mode->width/2; sz.h = mode->height/2; pos.x = 100; pos.y = 100; // Create just a regular window for presenting OVR SDK 0.6's mirror texture ///@todo Is it any faster with no mirror at all? LOG_INFO("Creating window %dx%d@%d,%d", sz.w, sz.h, pos.x, pos.y); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); g_app.SetAppWindowSize(sz); #else l_Window = glfwCreateWindow(800, 600, "GLFW Oculus Rift Test", NULL, NULL); std::string windowTitle = PROJECT_NAME; #endif //USE_OSVR|OVRSDK06 if (!l_Window) { LOG_INFO("Glfw failed to create a window. Exiting."); glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(l_Window); glfwSetWindowSizeCallback(l_Window, resize_Aux); glfwSetMouseButtonCallback(l_Window, mouseDown_Aux); glfwSetCursorPosCallback(l_Window, mouseMove_Aux); glfwSetScrollCallback(l_Window, mouseWheel_Aux); glfwSetKeyCallback(l_Window, keyboard_Aux); memset(m_keyStates, 0, GLFW_KEY_LAST*sizeof(int)); // joysticks for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { if (GL_FALSE == glfwJoystickPresent(i)) continue; const char* pJoyName = glfwGetJoystickName(i); if (pJoyName == NULL) continue; int numAxes = 0; int numButtons = 0; glfwGetJoystickAxes(i, &numAxes); glfwGetJoystickButtons(i, &numButtons); LOG_INFO("Glfw opened Joystick #%d: %s w/ %d axes, %d buttons", i, pJoyName, numAxes, numButtons); if (g_joystickIdx == -1) g_joystickIdx = i; } printGLContextInfo(l_Window); glfwMakeContextCurrent(l_Window); g_pHMDWindow = l_Window; // Don't forget to initialize Glew, turn glewExperimental on to // avoid problems fetching function pointers... glewExperimental = GL_TRUE; const GLenum l_Result = glewInit(); if (l_Result != GLEW_OK) { LOG_INFO("glewInit() error."); exit(EXIT_FAILURE); } #ifdef _DEBUG // Debug callback initialization // Must be done *after* glew initialization. glDebugMessageCallback(myCallback, NULL); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, -1 , "Start debugging"); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); #endif #ifdef USE_ANTTWEAKBAR LOG_INFO("Using AntTweakbar."); TwInit(useOpenGLCoreContext ? TW_OPENGL_CORE : TW_OPENGL, NULL); InitializeBar(); #endif LOG_INFO("Calling initGL..."); g_app.initGL(); LOG_INFO("Calling initVR..."); g_app.initVR(swapBackBufferDims); LOG_INFO("initVR(%d) complete.", swapBackBufferDims); SetVsync(0); // SDK 0.6 requires vsync OFF while (!glfwWindowShouldClose(l_Window)) { g_app.CheckForTapToDismissHealthAndSafetyWarning(); glfwPollEvents(); joystick(); timestep(); g_fps.OnFrame(); if (g_dynamicallyScaleFBO) { DynamicallyScaleFBO(); } #ifdef USE_ANTTWEAKBAR TwRefreshBar(g_pTweakbar); #endif g_app.pre_render_pass(); displayToHMD(); #ifndef _LINUX // Indicate FPS in window title // This is absolute death for performance in Ubuntu Linux 12.04 { std::ostringstream oss; oss << windowTitle << " " << static_cast<int>(g_fps.GetFPS()) << " fps"; glfwSetWindowTitle(l_Window, oss.str().c_str()); } #endif const float dumpInterval = 1.f; if (g_logDumpTimer.seconds() > dumpInterval) { LOG_INFO("Frame rate: %d fps", static_cast<int>(g_fps.GetFPS())); g_logDumpTimer.reset(); } } g_app.exitVR(); glfwDestroyWindow(l_Window); glfwTerminate(); exit(EXIT_SUCCESS); }
bool gl4::Engine::initGL() { //init glfw and set start time glfwInit(); _t0 = glfwGetTime(); #ifdef __APPLE__ glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 ); glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 ); #else glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 4 ); glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 3 ); #endif glfwOpenWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE ); // open window glfwOpenWindow( _windowWidth, _windowHeight, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ); // check if window opened correctly if( glfwGetWindowParam( GLFW_OPENED ) ) { glEnable(GL_TEXTURE_2D); // init GLEW with experimental features glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { std::cerr << "Error " << glewGetErrorString(err) << std::endl; } // glew init with "glewExperimental = GL_TRUE" fires an error GLenum errorID = glGetError(); // fetching versions char buffer [50]; const char *format = "%-12s %i.%i.%i\n"; int GLFWmajor = 0, GLFWminor = 0, GLFWrev = 0; int OpenGLmajor = 0, OpenGLminor = 0, OpenGLrev = 0; glfwGetVersion( &GLFWmajor, &GLFWminor, &GLFWrev ); OpenGLmajor = glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR); OpenGLminor = glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR); // printing versions LOG("%s\n", "Using versions:"); LOG(format, "GLFW:", GLFWmajor, GLFWminor, GLFWrev); LOG("%-12s %s\n", "GLEW:", glewGetString(GLEW_VERSION) ); LOG(format, "OpenGL:", OpenGLmajor, OpenGLminor, OpenGLrev ); LOG("%-12s %s\n", "GLSL:", glGetString(GL_SHADING_LANGUAGE_VERSION) ); std::sprintf (buffer, format, "GL4 Engine:", GL4_ENGINE_VERION_MAJOR, GL4_ENGINE_VERION_MINOR, GL4_ENGINE_VERION_REVISION ); LOG("%s",buffer ); glfwSetWindowTitle( buffer ); // make sure the managers are initialized gl4::ShaderManager::getInstance(); gl4::TextureManager::getInstance(); // init the fixed render target _deferredRender.init(_windowWidth, _windowHeight); // call user defined init if (_initFunc != 0) { _initFunc(); } // set callbacks if (_keyboardCallbackFunc != 0) { glfwSetKeyCallback(_keyboardCallbackFunc); } return true; } // if unable to open window, print error ERRLOG("%s\n", "Could not open window"); return false; }
int main(int argc, char** argv) { LOG_INFO("RiftRay version %s", pRiftRayVersion); #if defined(_WIN32) LOG_INFO("Windows build."); #elif defined(_LINUX) LOG_INFO("Linux build."); #elif defined(_MACOS) LOG_INFO("MacOS build."); #endif bool useOpenGLCoreContext = false; g_renderMode.outputType = RenderingMode::OVR_SDK; #ifdef USE_CORE_CONTEXT useOpenGLCoreContext = true; #endif #ifdef _LINUX // Linux driver seems to be lagging a bit useOpenGLCoreContext = false; #endif LOG_INFO("Using GLFW3 backend."); LOG_INFO("Compiled against GLFW %i.%i.%i", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); int major, minor, revision; glfwGetVersion(&major, &minor, &revision); LOG_INFO("Running against GLFW %i.%i.%i", major, minor, revision); LOG_INFO("glfwGetVersionString: %s", glfwGetVersionString()); // Command line options for (int i=0; i<argc; ++i) { const std::string a = argv[i]; LOG_INFO("argv[%d]: %s", i, a.c_str()); if (!a.compare("-sdk")) { g_renderMode.outputType = RenderingMode::OVR_SDK; } else if (!a.compare("-client")) { g_renderMode.outputType = RenderingMode::OVR_Client; } else if (!a.compare("-core")) { useOpenGLCoreContext = true; } else if (!a.compare("-compat")) { useOpenGLCoreContext = false; } } LoadConfigFile(); g_app.initHMD(); GLFWwindow* l_Window = NULL; glfwSetErrorCallback(ErrorCallback); if (!glfwInit()) { exit(EXIT_FAILURE); } #ifdef __APPLE__ // Set the working directory to the Resources dir of the .app bundle CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX); CFRelease(resourcesURL); strcat( path, "/shaders" ); struct stat sb; if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) chdir(path); #endif #ifndef _LINUX glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); # if defined(_MACOS) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); # else glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); # endif #endif //ndef _LINUX if (useOpenGLCoreContext) { LOG_INFO("Using OpenGL core context."); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); } else { #ifndef _LINUX glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); #endif } glfwWindowHint(GLFW_SAMPLES, 0); #ifdef _DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif std::string windowTitle = "RiftRay-v" + std::string(pRiftRayVersion); #ifdef USE_OCULUSSDK const ovrSizei sz = g_app.getHmdResolution(); const ovrVector2i pos = g_app.getHmdWindowPos(); if (g_app.UsingDebugHmd() == true) { // Create a normal, decorated application window LOG_INFO("Using Debug HMD mode."); windowTitle += "-GLFW-DebugHMD"; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); g_app.m_dashScene.m_bDraw = false; g_renderMode.outputType = RenderingMode::Mono_Buffered; } else if (g_app.UsingDirectMode()) { LOG_INFO("Using Direct to Rift mode."); windowTitle += "-GLFW-Direct"; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); #if defined(_WIN32) g_app.AttachToWindow((void*)glfwGetWin32Window(l_Window)); #endif } else { LOG_INFO("Using Extended desktop mode."); windowTitle += "-GLFW-Extended"; glfwWindowHint(GLFW_DECORATED, 0); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); glfwWindowHint(GLFW_DECORATED, 1); glfwSetWindowPos(l_Window, pos.x, pos.y); } resize(l_Window, sz.w, sz.h); // inform AppSkeleton of window size #else const glm::vec2 sz(800, 600); // Create a normal, decorated application window LOG_INFO("Using No VR SDK."); windowTitle += "-GLFW-NoVRSDK"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.x, sz.y, windowTitle.c_str(), NULL, NULL); resize(l_Window, sz.x, sz.y); // inform AppSkeleton of window size #endif //USE_OSVR|USE_OCULUSSDK if (!l_Window) { LOG_INFO("Glfw failed to create a window. Exiting."); glfwTerminate(); exit(EXIT_FAILURE); } #ifdef USE_OCULUSSDK // Required for SDK rendering (to do the buffer swap on its own) # if defined(_WIN32) g_app.setWindow(glfwGetWin32Window(l_Window)); # elif defined(__linux__) g_app.setWindow(glfwGetX11Display()); # endif #endif glfwMakeContextCurrent(l_Window); glfwSetWindowSizeCallback(l_Window, resize); glfwSetMouseButtonCallback(l_Window, mouseDown); glfwSetCursorPosCallback(l_Window, mouseMove); glfwSetScrollCallback(l_Window, mouseWheel); glfwSetKeyCallback(l_Window, keyboard); memset(m_keyStates, 0, GLFW_KEY_LAST*sizeof(int)); FindPreferredJoystick(); // Log system monitor information const GLFWmonitor* pPrimary = glfwGetPrimaryMonitor(); int monitorCount = 0; GLFWmonitor** ppMonitors = glfwGetMonitors(&monitorCount); for (int i=0; i<monitorCount; ++i) { GLFWmonitor* pCur = ppMonitors[i]; const GLFWvidmode* mode = glfwGetVideoMode(pCur); if (mode != NULL) { LOG_INFO("Monitor #%d: %dx%d @ %dHz %s", i, mode->width, mode->height, mode->refreshRate, pCur==pPrimary ? "Primary":""); } } printGLContextInfo(l_Window); glfwMakeContextCurrent(l_Window); g_pHMDWindow = l_Window; // Don't forget to initialize Glew, turn glewExperimental on to // avoid problems fetching function pointers... glewExperimental = GL_TRUE; const GLenum l_Result = glewInit(); if (l_Result != GLEW_OK) { LOG_INFO("glewInit() error."); exit(EXIT_FAILURE); } #ifdef _DEBUG // Debug callback initialization // Must be done *after* glew initialization. glDebugMessageCallback(myCallback, NULL); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, -1, "Start debugging"); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); #endif #ifdef USE_ANTTWEAKBAR LOG_INFO("Using AntTweakbar."); TwInit(useOpenGLCoreContext ? TW_OPENGL_CORE : TW_OPENGL, NULL); InitializeBar(); #endif LOG_INFO("Calling initGL..."); g_app.initGL(); LOG_INFO("Calling initVR..."); g_app.initVR(); LOG_INFO("initVR complete."); SetVsync(1); // default to vsync on StartShaderLoad(); while (!glfwWindowShouldClose(l_Window)) { const bool tapped = g_app.CheckForTapOnHmd(); if (tapped && (g_receivedFirstTap == false)) { g_app.RecenterPose(); g_receivedFirstTap = true; } glfwPollEvents(); joystick(); timestep(); g_fps.OnFrame(); if (g_dynamicallyScaleFBO) { DynamicallyScaleFBO(); } #ifdef USE_ANTTWEAKBAR TwRefreshBar(g_pTweakbar); TwRefreshBar(g_pShaderTweakbar); #endif displayToHMD(); #ifndef _LINUX // Indicate FPS in window title // This is absolute death for performance in Ubuntu Linux 12.04 { std::ostringstream oss; oss << windowTitle << " " << static_cast<int>(g_fps.GetFPS()) << " fps"; glfwSetWindowTitle(l_Window, oss.str().c_str()); if (g_AuxWindow != NULL) glfwSetWindowTitle(g_AuxWindow, oss.str().c_str()); } #endif const float dumpInterval = 1.f; if (g_logDumpTimer.seconds() > dumpInterval) { LOG_INFO("Frame rate: %d fps", static_cast<int>(g_fps.GetFPS())); g_logDumpTimer.reset(); } // Optionally display to auxiliary mono view if (g_AuxWindow != NULL) { glfwMakeContextCurrent(g_AuxWindow); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///@note VAOs *cannot* be shared between contexts. ///@note GLFW windows are inextricably tied to their own unique context. /// For these two reasons, calling draw a third time for the auxiliary window /// is not possible. Furthermore, it is not strictly desirable for the extra /// rendering cost. /// Instead, we share the render target texture from the stereo render and present /// just the left eye to the aux window. if (g_drawToAuxWindow) { presentSharedFboTexture(); } #ifdef USE_ANTTWEAKBAR TwDraw(); ///@todo Should this go first? Will it write to a depth buffer? #endif glfwSwapBuffers(g_AuxWindow); if (glfwWindowShouldClose(g_AuxWindow)) { destroyAuxiliaryWindow(g_AuxWindow); } // Set context to Rift window when done glfwMakeContextCurrent(l_Window); } } g_app.exitVR(); glfwDestroyWindow(l_Window); glfwTerminate(); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { #if defined(_WIN32) LOG_INFO("Windows build."); #elif defined(_LINUX) LOG_INFO("Linux build."); LOG_INFO("DISPLAY=%s", getenv("DISPLAY")); #elif defined(_MACOS) LOG_INFO("MacOS build."); #endif bool useOpenGLCoreContext = false; #ifdef USE_CORE_CONTEXT useOpenGLCoreContext = true; #endif g_renderMode.outputType = RenderingMode::OVR_SDK; LOG_INFO("Using GLFW3 backend."); LOG_INFO("Compiled against GLFW %i.%i.%i", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); int major, minor, revision; glfwGetVersion(&major, &minor, &revision); LOG_INFO("Running against GLFW %i.%i.%i", major, minor, revision); LOG_INFO("glfwGetVersionString: %s", glfwGetVersionString()); // Command line options for (int i=0; i<argc; ++i) { const std::string a = argv[i]; LOG_INFO("argv[%d]: %s", i, a.c_str()); if (!a.compare("-sdk")) { g_renderMode.outputType = RenderingMode::OVR_SDK; } else if (!a.compare("-client")) { g_renderMode.outputType = RenderingMode::OVR_Client; } else if (!a.compare("-core")) { useOpenGLCoreContext = true; } else if (!a.compare("-compat")) { useOpenGLCoreContext = false; } } #ifdef USE_OCULUSSDK g_app.initHMD(); #else g_renderMode.outputType = RenderingMode::Mono_Buffered; #endif GLFWwindow* l_Window = NULL; glfwSetErrorCallback(ErrorCallback); if (!glfwInit()) { exit(EXIT_FAILURE); } // Log system monitor information const GLFWmonitor* pPrimary = glfwGetPrimaryMonitor(); int monitorCount = 0; GLFWmonitor** ppMonitors = glfwGetMonitors(&monitorCount); for (int i=0; i<monitorCount; ++i) { GLFWmonitor* pCur = ppMonitors[i]; const GLFWvidmode* mode = glfwGetVideoMode(pCur); if (mode != NULL) { (void)pPrimary; LOG_INFO("Monitor #%d: %dx%d @ %dHz %s", i, mode->width, mode->height, mode->refreshRate, pCur==pPrimary ? "Primary":""); } } bool swapBackBufferDims = false; // Context setup - before window creation glfwWindowHint(GLFW_DEPTH_BITS, 16); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, useOpenGLCoreContext ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE); //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #ifdef _DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif #if defined(USE_OSVR) LOG_INFO("USE_OSVR=1"); std::string windowTitle = ""; windowTitle = PROJECT_NAME "-GLFW-Osvr"; if (g_app.UsingDebugHmd()) { const hmdRes sz = { 800, 600 }; // Create a normal, decorated application window LOG_INFO("Using Debug HMD mode."); windowTitle = PROJECT_NAME "-GLFW-DebugHMD"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); } else { const hmdRes sz = { g_app.getHmdResolution().h, g_app.getHmdResolution().w }; const winPos pos = g_app.getHmdWindowPos(); g_renderMode.outputType = RenderingMode::SideBySide_Undistorted; LOG_INFO("Using Extended desktop mode."); windowTitle = PROJECT_NAME "-GLFW-Extended"; LOG_INFO("Creating GLFW_DECORATED window %dx%d@%d,%d", sz.w, sz.h, pos.x, pos.y); glfwWindowHint(GLFW_DECORATED, 0); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); glfwWindowHint(GLFW_DECORATED, 1); glfwSetInputMode(l_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetWindowPos(l_Window, pos.x, pos.y); } #elif defined(USE_OCULUSSDK) LOG_INFO("USE_OCULUSSDK=1"); ovrSizei sz = g_app.getHmdResolution(); const ovrVector2i pos = g_app.getHmdWindowPos(); std::string windowTitle = ""; if (g_app.UsingDebugHmd() == true) { // Create a normal, decorated application window LOG_INFO("Using Debug HMD mode."); windowTitle = PROJECT_NAME "-GLFW-DebugHMD"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); } else if (g_app.UsingDirectMode()) { // HMD active - position undecorated window to fill HMD viewport LOG_INFO("Using Direct to Rift mode."); windowTitle = PROJECT_NAME "-GLFW-Direct"; GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); sz.w = mode->width; sz.h = mode->height; LOG_INFO("Creating window %dx%d@%d,%d", sz.w, sz.h, pos.x, pos.y); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), monitor, NULL); glfwSetInputMode(l_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); #ifdef _LINUX swapBackBufferDims = true; #endif #if defined(_WIN32) g_app.AttachToWindow((void*)glfwGetWin32Window(l_Window)); #endif } else { LOG_INFO("Using Extended desktop mode."); windowTitle = PROJECT_NAME "-GLFW-Extended"; LOG_INFO("Creating GLFW_DECORATED window %dx%d@%d,%d", sz.w, sz.h, pos.x, pos.y); glfwWindowHint(GLFW_DECORATED, 0); l_Window = glfwCreateWindow(sz.w, sz.h, windowTitle.c_str(), NULL, NULL); glfwWindowHint(GLFW_DECORATED, 1); glfwSetInputMode(l_Window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetWindowPos(l_Window, pos.x, pos.y); } resize(l_Window, sz.w, sz.h); // inform AppSkeleton of window size #else const glm::vec2 sz(800, 600); // Create a normal, decorated application window LOG_INFO("Using No VR SDK."); const std::string windowTitle = PROJECT_NAME "-GLFW-NoVRSDK"; g_renderMode.outputType = RenderingMode::Mono_Buffered; l_Window = glfwCreateWindow(sz.x, sz.y, windowTitle.c_str(), NULL, NULL); #endif //USE_OSVR|USE_OCULUSSDK if (!l_Window) { LOG_INFO("Glfw failed to create a window. Exiting."); glfwTerminate(); exit(EXIT_FAILURE); } // Required for SDK rendering (to do the buffer swap on its own) #ifdef OVRSDK05 #if defined(_WIN32) g_app.setWindow(glfwGetWin32Window(l_Window)); #elif defined(__linux__) g_app.setWindow(NULL);//glfwGetX11Display()); #endif #endif //USE_OCULUSSDK glfwMakeContextCurrent(l_Window); glfwSetWindowSizeCallback(l_Window, resize); glfwSetMouseButtonCallback(l_Window, mouseDown); glfwSetCursorPosCallback(l_Window, mouseMove); glfwSetScrollCallback(l_Window, mouseWheel); glfwSetKeyCallback(l_Window, keyboard); memset(m_keyStates, 0, GLFW_KEY_LAST*sizeof(int)); // joysticks for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { if (GL_FALSE == glfwJoystickPresent(i)) continue; const char* pJoyName = glfwGetJoystickName(i); if (pJoyName == NULL) continue; int numAxes = 0; int numButtons = 0; glfwGetJoystickAxes(i, &numAxes); glfwGetJoystickButtons(i, &numButtons); LOG_INFO("Glfw opened Joystick #%d: %s w/ %d axes, %d buttons", i, pJoyName, numAxes, numButtons); if (g_joystickIdx == -1) g_joystickIdx = i; } printGLContextInfo(l_Window); glfwMakeContextCurrent(l_Window); g_pHMDWindow = l_Window; // Don't forget to initialize Glew, turn glewExperimental on to // avoid problems fetching function pointers... glewExperimental = GL_TRUE; const GLenum l_Result = glewInit(); if (l_Result != GLEW_OK) { LOG_INFO("glewInit() error."); exit(EXIT_FAILURE); } #ifdef _DEBUG // Debug callback initialization // Must be done *after* glew initialization. glDebugMessageCallback(myCallback, NULL); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE); glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, -1 , "Start debugging"); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); #endif #ifdef USE_ANTTWEAKBAR LOG_INFO("Using AntTweakbar."); TwInit(useOpenGLCoreContext ? TW_OPENGL_CORE : TW_OPENGL, NULL); InitializeBar(); #endif LOG_INFO("Calling initGL..."); g_app.initGL(); LOG_INFO("Calling initVR..."); g_app.initVR(swapBackBufferDims); LOG_INFO("initVR(%d) complete.", swapBackBufferDims); while (!glfwWindowShouldClose(l_Window)) { g_app.CheckForTapToDismissHealthAndSafetyWarning(); glfwPollEvents(); joystick(); timestep(); g_fps.OnFrame(); if (g_dynamicallyScaleFBO) { DynamicallyScaleFBO(); } #ifdef USE_ANTTWEAKBAR TwRefreshBar(g_pTweakbar); #endif displayToHMD(); #ifndef _LINUX // Indicate FPS in window title // This is absolute death for performance in Ubuntu Linux 12.04 { std::ostringstream oss; oss << windowTitle << " " << static_cast<int>(g_fps.GetFPS()) << " fps"; glfwSetWindowTitle(l_Window, oss.str().c_str()); if (g_AuxWindow != NULL) glfwSetWindowTitle(g_AuxWindow, oss.str().c_str()); } #endif const float dumpInterval = 1.f; if (g_logDumpTimer.seconds() > dumpInterval) { LOG_INFO("Frame rate: %d fps", static_cast<int>(g_fps.GetFPS())); g_logDumpTimer.reset(); } // Optionally display to auxiliary mono view if (g_AuxWindow != NULL) { glfwMakeContextCurrent(g_AuxWindow); glClearColor(0.f, 0.f, 0.f, 0.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///@note VAOs *cannot* be shared between contexts. ///@note GLFW windows are inextricably tied to their own unique context. /// For these two reasons, calling draw a third time for the auxiliary window /// is not possible. Furthermore, it is not strictly desirable for the extra /// rendering cost. /// Instead, we share the render target texture from the stereo render and present /// just the left eye to the aux window. if (g_drawToAuxWindow) { presentSharedFboTexture(); } #ifdef USE_ANTTWEAKBAR TwDraw(); ///@todo Should this go first? Will it write to a depth buffer? #endif glfwSwapBuffers(g_AuxWindow); if (glfwWindowShouldClose(g_AuxWindow)) { destroyAuxiliaryWindow(g_AuxWindow); } // Set context to Rift window when done glfwMakeContextCurrent(l_Window); } } g_app.exitVR(); glfwDestroyWindow(l_Window); glfwTerminate(); exit(EXIT_SUCCESS); }
void PullInfo(){ printf("================================================================================\n"); int major, minor, rev; glfwGetVersion(&major, &minor, &rev); printf("GLFW version is %i.%i.%i\n", major, minor, rev); int width, height; glfwGetWindowSize(&width, &height); printf("Window size is %i %i\n", width, height); int status = glfwGetKey(GLFW_KEY_LCTRL); if(status == GLFW_PRESS) printf("Left control is pressed\n"); else printf("Left control is released\n"); status = glfwGetMouseButton(GLFW_MOUSE_BUTTON_1); if(status == GLFW_PRESS) printf("Mouse button 1 is pressed\n"); else printf("Mouse button 1 is released\n"); int x, y; glfwGetMousePos(&x, &y); printf("Mouse position is %i %i\n", x, y); int wheel = glfwGetMouseWheel(); printf("Mouse wheel pos is %i\n", wheel); double time = glfwGetTime(); printf("Time is %f\n", time); glfwGetGLVersion(&major, &minor, &rev); printf("GL version is %i.%i.%i\n", major, minor, rev); int proc = glfwGetNumberOfProcessors(); printf("%i processors are available\n", proc); unsigned int i; for(i = 0; i<nb_params; i++) printf(" - %-27s : %i\n", GetParamName(params[i]), glfwGetWindowParam(params[i])); const char* extension = "MOZ_WEBGL_compressed_texture_s3tc"; printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported"); extension = "GL_EXT_framebuffer_object"; printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported"); extension = "glBindBuffer"; void* proc_addr = glfwGetProcAddress(extension); printf("'%s' extension proc address is %p.\n", extension, proc_addr); printf("Sleeping 1 sec...\n"); glfwSleep(1); printf("...Done.\n"); printf("================================================================================\n"); #ifdef REPORT_RESULT int result = 1; REPORT_RESULT(); #endif }
void initComponents() { int a, b, c, i, j, k; glfwGetVersion(&a, &b, &c); glfwGetGLVersion(&i, &j, &k); ostringstream ss; ss << "GLFW Version: " << a << "." << b << "." << c << " | "; ss << "OpenGL Version: " << i << "." << j << "." << k << " | "; ss << "FSAA_SAMPLES: " << glfwGetWindowParam(GLFW_FSAA_SAMPLES); button = new Button(); label1 = new Label(); label2 = new Label(); ipanel1 = new Panel(); label1->setLocation(20, 0); label2->setLocation(20, 690); label1->setText("0"); // label2->setAutoDimension(false); label2->setDimension(400, 200); label2->setAlign(Label::MiddleCenter); label2->setText(ss.str()); // image = Image::loadImage("/home/paulocanedo/Pictures/netbeans.png"); // label1->setImage(image); // label1->setDimension(200, 200); // label1->setAlign(Component::ComponentAlign::TopCenter); // label1->setAlign(Component::ComponentAlign::MiddleCenter); // label1->setAlign(Component::ComponentAlign::BottomCenter); // label1->setForegroundColor(pcglYellow); // label1->setBackgroundColor(pcglBootstrapBlue); int y = 80; int gap = 2; button->setLocation(20, 30); // button->setAutoDimension(false); // button->setDimension(300, 80); CustomAction *caction = new CustomAction(); button->setAction(caction); button->setText("Button 1"); rbutton1 = new RadioButton(); rbutton1->setLocation(20, y); rbutton1->setText("RadioButton 1"); y += rbutton1->getDimension().h + gap; rbutton2 = new RadioButton(); rbutton2->setLocation(20, y); rbutton2->setText("RadioButton 2"); y += rbutton1->getDimension().h + gap; rbutton3 = new RadioButton(); rbutton3->setLocation(20, y); rbutton3->setText("RadioButton 3"); y += rbutton1->getDimension().h + gap; rbutton4 = new RadioButton(); rbutton4->setLocation(20, y); rbutton4->setText("RadioButton 4"); y += rbutton1->getDimension().h + gap; rbutton5 = new RadioButton(); rbutton5->setLocation(0, 0); rbutton5->setText("RadioButton 5"); rbutton1->setGroupId(1); rbutton2->setGroupId(1); rbutton3->setGroupId(1); rbutton4->setGroupId(1); cbbutton1 = new CheckBoxButton(); cbbutton1->setText("CheckBox 1"); cbbutton1->setLocation(200, 80); cbbutton2 = new CheckBoxButton(); cbbutton2->setText("CheckBox 2"); cbbutton2->setLocation(200, 105); panel = new Panel(); panel->setDimension(1920 * 4, 1080 * 4); ipanel1->setLocation(100, 300); ipanel1->setDimension(500, 300); ipanel1->setBackgroundColor(pcglLightGray); ipanel1->add(rbutton5); panel->add(label1); panel->add(label2); panel->add(rbutton1); panel->add(rbutton2); panel->add(rbutton3); panel->add(rbutton4); panel->add(cbbutton1); panel->add(cbbutton2); panel->add(button); panel->add(ipanel1); rootc->add(panel); }
int main() { GLFWwindow *window; char *userptr = "userptr"; glfwSetErrorCallback(errorcb); assert(glfwInit() == GL_TRUE); assert(!strcmp(glfwGetVersionString(), "3.2.1 JS WebGL Emscripten")); assert(glfwGetCurrentContext() == NULL); { int major, minor, rev; glfwGetVersion(&major, &minor, &rev); assert(major == 3); assert(minor == 2); assert(rev == 1); } { int count, x, y, w, h; GLFWmonitor **monitors = glfwGetMonitors(&count); assert(count == 1); for (int i = 0; i < count; ++i) { assert(monitors[i] != NULL); } assert(glfwGetPrimaryMonitor() != NULL); glfwGetMonitorPos(monitors[0], &x, &y); glfwGetMonitorPhysicalSize(monitors[0], &w, &h); assert(glfwGetMonitorName(monitors[0]) != NULL); glfwSetMonitorCallback(monitcb); // XXX: not implemented // assert(glfwGetVideoModes(monitors[0], &count) != NULL); // assert(glfwGetVideoMode(monitors[0]) != NULL); // glfwSetGamma(monitors[0], 1.0f); // assert(glfwGetGammaRamp(monitors[0]) != NULL); // glfwSetGammaRamp(monitors[0], ramp); } { int x, y, w, h; glfwDefaultWindowHints(); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL); assert(window != NULL); glfwSetWindowPosCallback(window, wposicb); glfwSetWindowSizeCallback(window, wsizecb); glfwSetWindowCloseCallback(window, wcloscb); glfwSetWindowRefreshCallback(window, wrfrscb); glfwSetWindowFocusCallback(window, wfocucb); glfwSetWindowIconifyCallback(window, wiconcb); glfwSetFramebufferSizeCallback(window, wfsizcb); assert(glfwWindowShouldClose(window) == 0); glfwSetWindowShouldClose(window, 1); assert(glfwWindowShouldClose(window) == 1); glfwSetWindowTitle(window, "test"); glfwSetWindowTitle(window, "glfw3.c"); // XXX: not implemented // glfwSetWindowPos(window, 1, 1); glfwGetWindowPos(window, &x, &y); // stub glfwGetWindowSize(window, &w, &h); assert(w == 640 && h == 480); glfwSetWindowSize(window, 1, 1); glfwGetWindowSize(window, &w, &h); assert(w == 1 && h == 1); glfwSetWindowSize(window, 640, 480); glfwGetFramebufferSize(window, &w, &h); // XXX: not implemented // glfwIconifyWindow(window); // glfwRestoreWindow(window); // glfwShowWindow(window); // glfwHideWindow(window); assert(glfwGetWindowMonitor(window) == NULL); glfwDestroyWindow(window); window = glfwCreateWindow(640, 480, "glfw3.c", glfwGetPrimaryMonitor(), NULL); assert(window != NULL); assert(glfwGetWindowMonitor(window) == glfwGetPrimaryMonitor()); glfwDestroyWindow(window); window = glfwCreateWindow(640, 480, "glfw3.c", NULL, NULL); assert(window != NULL); assert(glfwGetWindowAttrib(window, GLFW_CLIENT_API) == GLFW_OPENGL_ES_API); assert(glfwGetWindowUserPointer(window) == NULL); glfwSetWindowUserPointer(window, userptr); assert(glfwGetWindowUserPointer(window) == userptr); } { double x, y; glfwSetKeyCallback(window, wkeypcb); glfwSetCharCallback(window, wcharcb); glfwSetMouseButtonCallback(window, wmbutcb); glfwSetCursorPosCallback(window, wcurpcb); glfwSetCursorEnterCallback(window, wcurecb); glfwSetScrollCallback(window, wscrocb); // XXX: stub, events come immediatly // glfwPollEvents(); // glfwWaitEvents(); assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL); // XXX: not implemented // glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwGetKey(window, GLFW_KEY_A); glfwGetMouseButton(window, 0); glfwGetCursorPos(window, &x, &y); // XXX: not implemented // glfwSetCursorPos(window, 0, 0); } { // XXX: not implemented // glfwJoystickPresent(joy); // glfwGetJoystickAxes(joy, &count); // glfwGetJoystickButtons(joy, &count); // glfwGetJoystickName(joy); } { // XXX: not implemented // glfwSetClipboardString(window, "string"); // glfwGetClipboardString(window); } { glfwGetTime(); glfwSetTime(0); } { glfwMakeContextCurrent(window); // stub assert(glfwGetCurrentContext() == window); glfwSwapBuffers(window); // stub glfwSwapInterval(0); // stub } { assert(glfwExtensionSupported("nonexistant") == 0); assert(glfwGetProcAddress("nonexistant") == NULL); } glfwTerminate(); #ifdef REPORT_RESULT REPORT_RESULT(1); #endif return 0; }
// Main function int main(int argc, char * argv[]) { /*{ PointerState test; test.UpdateButtonState(0) = true; test.UpdateButtonState(1) = true; test.UpdateButtonState(2) = true; PointerState test2(test); test2.UpdateButtonState(2) = false; std::cout << test.GetButtonState(2) << &std::endl; std::cout << test2.GetButtonState(2) << &std::endl; return 0; }*/ #if 0 { std::function<void()> Test = []() { std::cout << "Hi from anon func.\n"; }; //std::function<ConceptString(const std::vector<ConceptId> &)> Test = [](const std::vector<ConceptId> & Parameters){ return ConceptString({FindConcept("<"), GetParameterIfExists(Parameters, 0), FindConcept(">")}); }; // Call Test() //Test(); printf("size of func %ld\n", sizeof(Test)); return 0; } #endif // Set env vars std::string GoPath; // This has to exist even after putenv() call because putenv simply adds a pointer rather than copying the value std::string Path = "PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/go/bin"; { // Initialize the value of GoPath GoPath = "GOPATH="; // Get current working directory { auto cwd = getcwd(nullptr, 0); if (nullptr == cwd) { printf("Fatal Error: getcwd() failed."); exit(1); } printf("Current-working-dir is '%s' (should be the folder where README.md is).\n", cwd); GoPath = GoPath + cwd + "/GoLand"; GoPath += ":"; GoPath = GoPath + cwd + "/GoLanding"; Path = Path + ":" + cwd + "/GoLand/bin"; free(cwd); } putenv(const_cast<char *>("DYLD_INSERT_LIBRARIES=")); // HACK: Const cast putenv(const_cast<char *>("TERM=xterm")); // HACK: Const cast putenv(const_cast<char *>(GoPath.c_str())); // HACK: Const cast // HACK: Add go/bin to $PATH by hardcoding the whole PATH for OS X putenv(const_cast<char *>(Path.c_str())); // HACK: Const cast } glfwInit(); // Verify the GLFW library and header versions match { int Major, Minor, Revision; glfwGetVersion(&Major, &Minor, &Revision); bool Match = (GLFW_VERSION_MAJOR == Major && GLFW_VERSION_MINOR == Minor && GLFW_VERSION_REVISION == Revision); if (!Match) { std::cerr << "Error: GLFW library and header versions do not match." << std::endl; throw 0; } else { std::cout << "Using GLFW " << Major << "." << Minor << "." << Revision << "." << std::endl; } } // Open main window { GLFWvidmode DesktopMode; glfwGetDesktopMode(&DesktopMode); glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 32); const bool Fullscreen = static_cast<bool>(0); const Vector2n WindowDimensons(1536, 960); if (!Fullscreen) { glfwOpenWindow(WindowDimensons.X(), WindowDimensons.Y(), DesktopMode.RedBits, DesktopMode.GreenBits, DesktopMode.BlueBits, 0, 0, 0, GLFW_WINDOW); glfwSetWindowPos((DesktopMode.Width - WindowDimensons.X()) / 2, (DesktopMode.Height - WindowDimensons.Y()) / 2); // Center the window } else { glfwOpenWindow(DesktopMode.Width, DesktopMode.Height, DesktopMode.RedBits, DesktopMode.GreenBits, DesktopMode.BlueBits, 0, 0, 0, GLFW_FULLSCREEN); glfwEnable(GLFW_MOUSE_CURSOR); } { std::ostringstream x; x << "CPU Count: " << glfwGetNumberOfProcessors() << std::endl << "GL Renderer: " << glGetString(GL_VENDOR) << " " << glGetString(GL_RENDERER) << " " << glGetString(GL_VERSION) << std::endl << "GLFW_ACCELERATED: " << glfwGetWindowParam(GLFW_ACCELERATED) << std::endl << "GLFW_RED_BITS: " << glfwGetWindowParam(GLFW_RED_BITS) << std::endl << "GLFW_GREEN_BITS: " << glfwGetWindowParam(GLFW_GREEN_BITS) << std::endl << "GLFW_BLUE_BITS: " << glfwGetWindowParam(GLFW_BLUE_BITS) << std::endl << "GLFW_ALPHA_BITS: " << glfwGetWindowParam(GLFW_ALPHA_BITS) << std::endl << "GLFW_DEPTH_BITS: " << glfwGetWindowParam(GLFW_DEPTH_BITS) << std::endl << "GLFW_STENCIL_BITS: " << glfwGetWindowParam(GLFW_STENCIL_BITS) << std::endl << "GLFW_REFRESH_RATE: " << glfwGetWindowParam(GLFW_REFRESH_RATE) << std::endl << "GLFW_FSAA_SAMPLES: " << glfwGetWindowParam(GLFW_FSAA_SAMPLES) << std::endl; std::cout << x.str(); } { //glfwSetWindowTitle("Conception"); glfwSwapInterval(1); // Set Vsync glfwDisable(GLFW_AUTO_POLL_EVENTS); glfwEnable(GLFW_KEY_REPEAT); glfwDisable(GLFW_SYSTEM_KEYS); } } { InputManager InputManager; g_InputManager = &InputManager; ConceptionApp MainApp(InputManager); //LiveEditorApp MainApp(InputManager); //ConceptionTestApp MainApp(InputManager); //MultitouchTestApp MainApp(InputManager); //SentienceApp MainApp(InputManager); glfwSetWindowTitle(MainApp.GetTitle().c_str()); // Perform the layout of UI widgets MainApp.Layout(); // OpenGL settings InitializeOpenGL(); std::cout << std::endl; // Done loading // Main loop while (glfwGetWindowParam(GLFW_OPENED)) { auto CurrentTime = glfwGetTime(); static auto LastTime = CurrentTime; auto TimePassed = CurrentTime - LastTime; LastTime = CurrentTime; // DEBUG: Moved to top of loop to enable debug printing from input handling code glClear(GL_COLOR_BUFFER_BIT); // Clear frame // Process input { // Populate InputEventQueue if (MainApp.ShouldRedrawRegardless()) glfwPollEvents(); else { glfwWaitEvents(); //if (glfwGetTime() - LastTime >= 1) printf("Slept for %f secs\n", glfwGetTime() - LastTime); LastTime = glfwGetTime(); } //InputManager.ProcessTimePassed(TimePassed); MainApp.ProcessEventQueue(InputManager.ModifyInputEventQueue()); MainApp.ProcessTimePassed(TimePassed); } // Render { // DEBUG: Moved to top of loop to enable debug printing from input handling code ///glClear(GL_COLOR_BUFFER_BIT); // Clear frame MainApp.Render(); } // Display new frame glfwSwapBuffers(); //glFinish(); ///printf("%f ms frame\n", TimePassed * 1000); // Use less CPU in background if (!glfwGetWindowParam(GLFW_ACTIVE)) { glfwSleep(0.100); } } } // Clean up OglUtilsKillFont(); glfwTerminate(); std::cout << "\nReturning 0 from main().\n"; return 0; }
int main(int argc, char** argv) { int ch, profile = 0, major = 1, minor = 1, revision; GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE; GLint flags, mask; while ((ch = getopt(argc, argv, "dfhlm:n:p:")) != -1) { switch (ch) { case 'd': debug = GL_TRUE; break; case 'f': forward = GL_TRUE; break; case 'h': usage(); exit(0); case 'l': list = GL_TRUE; break; case 'm': major = atoi(optarg); break; case 'n': minor = atoi(optarg); break; case 'p': if (strcasecmp(optarg, "core") == 0) profile = GLFW_OPENGL_CORE_PROFILE; else if (strcasecmp(optarg, "compat") == 0) profile = GLFW_OPENGL_COMPAT_PROFILE; else { usage(); exit(1); } break; default: usage(); exit(1); } } argc -= optind; argv += optind; if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(1); } if (major != 1 || minor != 1) { glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor); } if (debug) glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); if (forward) glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); if (profile != 0) glfwOpenWindowHint(GLFW_OPENGL_PROFILE, profile); // We assume here that we stand a better chance of success by leaving all // possible details of pixel format selection to GLFW if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) { glfwTerminate(); fprintf(stderr, "Failed to open GLFW window\n"); exit(1); } // Report GLFW version glfwGetVersion(&major, &minor, &revision); printf("GLFW header version: %u.%u.%u\n", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION); printf("GLFW library version: %u.%u.%u\n", major, minor, revision); if (major != GLFW_VERSION_MAJOR || minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION) printf("*** WARNING: GLFW version mismatch! ***\n"); // Report OpenGL version printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION)); glfwGetGLVersion(&major, &minor, &revision); printf("OpenGL context version parsed by GLFW: %u.%u.%u\n", major, minor, revision); // Report OpenGL context properties if (major >= 3) { glGetIntegerv(GL_CONTEXT_FLAGS, &flags); printf("OpenGL context flags:"); if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) puts(" forward-compatible"); else puts(" none"); } if (major > 3 || (major == 3 && minor >= 2)) { glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); printf("OpenGL profile mask: 0x%08x (%s)\n", mask, get_profile_name(mask)); } printf("OpenGL context renderer string: \"%s\"\n", glGetString(GL_RENDERER)); printf("OpenGL context vendor string: \"%s\"\n", glGetString(GL_VENDOR)); if (major > 1) { printf("OpenGL context shading language version: \"%s\"\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); } // Report OpenGL extensions if (list) list_extensions(major, minor); glfwTerminate(); exit(0); }