void FontManager::loadAll(std::string directory) { if (directory.size() == 0) return; OSFile file; OSDir dir(directory.c_str()); while (dir.getNextFile(file, true)) { const char *ext = file.getExtension(); if (ext) { if (strcasecmp(ext, "fmt") == 0) { TextureFont *pFont = new TextureFont; if (pFont) { if (pFont->load(file)) { std::string str = pFont->getFaceName(); GetTypeFaceName((char*)str.c_str()); FontFaceMap::iterator faceItr = faceNames.find(str); int faceID = 0; if (faceItr == faceNames.end()) { // its new FontSizeMap faceList; fontFaces.push_back(faceList); faceID = (int)fontFaces.size() - 1; faceNames[str] = faceID; } else { faceID = faceItr->second; } fontFaces[faceID][pFont->getSize()] = pFont; } else { DEBUG4("Font Texture load failed: %s\n", file.getOSName()); delete(pFont); } } } } } }
int main() { auto error_callback = [](int error, const char* description) { slog.e(TAG, "Error (%d): %s\n", error, description); }; glfwSetErrorCallback(error_callback); if(glfwInit() != GLFW_TRUE) { slog.e(TAG, "Failed to initialize GLFW library" ); return -1; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Open a window and create its OpenGL context GLFWwindow* window = glfwCreateWindow(window_size.width, window_size.height, TAG, NULL, NULL); if(!window) { slog.e(TAG, "Failed to open GLFW window. Not OpenGL 3.3 compatible"); glfwTerminate(); return -2; } glfwMakeContextCurrent(window); // Initialize GLEW glewExperimental = true; // Needed for core profile if(glewInit() != GLEW_OK) { slog.e(TAG, "Failed to initialize GLEW library"); glfwTerminate(); return -3; } // Ensure we can capture the escape key being pressed below glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); // Hide the mouse and enable unlimited mouvement glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwPollEvents(); // Set the mouse at the center of the screen glfwSetCursorPos(window, window_size.width/2, window_size.height/2); // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); // Cull triangles which normal is not towards the camera glEnable(GL_CULL_FACE); // double lastTime = glfwGetTime(); std::string dir = File::dirname(__FILE__); bool flag = Program::loadFromFile(program, dir + "/font.vert", dir + "/font.frag"); assert(flag); program.use(); font.load(File::getResourcePath() + "/font/FreeSans.ttf", 48); while(true) { // Dark blue background glClearColor(0.0f, 0.0f, 0.24f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); // Check if the ESC key was pressed or the window was closed if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS || glfwWindowShouldClose(window) != 0) break; } // Close OpenGL window and terminate GLFW glfwTerminate(); return 0; }