Common::UString ResourceManager::findArchive(const Common::UString &file, const DirectoryList &dirs, const Common::FileList &files) { Common::UString escapedFile = Common::FilePath::escapeStringLiteral(file); Common::FileList nameMatch; if (!files.getSubList(".*/" + escapedFile, nameMatch, true)) return ""; Common::UString realName; for (DirectoryList::const_iterator dir = dirs.begin(); dir != dirs.end(); ++dir) { Common::UString escapedPath = Common::FilePath::escapeStringLiteral(Common::FilePath::normalize(*dir)) + "/" + escapedFile; if (!(realName = nameMatch.findFirst(escapedPath, true)).empty()) return realName; } return ""; }
void CGraphicsModule::initDriver( short width, short height ) { offsetX = 0; offsetY = 0; this->width = width; this->height = height; if (!glfwInit()) { printf("Failed to start GLFW."); exit(1); } #ifdef USE_OPENGL_3 glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 ); glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 ); glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE ); #endif glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE ); glfwOpenWindow( width, height, 0, 0, 0, 0, 8, 0, GLFW_WINDOW ); glfwSetWindowTitle( "Spine" ); const GLubyte* version = glGetString(GL_VERSION); const GLubyte* renderer = glGetString(GL_RENDERER); const GLubyte* vendor = glGetString(GL_VENDOR); const GLubyte* glslvers = glGetString(GL_SHADING_LANGUAGE_VERSION); printf("Version: %s\nRenderer: %s\nVendor: %s\nGLSLVersion: %s\n", version, renderer, vendor, glslvers); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { printf( "Error loading glew!" ); exit(1); } else { printf( "Using GLEW: %s %d\n", glewGetString(GLEW_VERSION), glewIsSupported("GL_ARB_fragment_program") ); } // Compile all the shaders. DirectoryList list = filesystem->getDirectoryList("./shaders/"); for (DirectoryList::iterator i = list.begin(); i != list.end(); ++i) { char name[50]; char exten[10]; util->getFileName(name, (*i).c_str()); util->getFileExtension(exten, (*i).c_str()); Buffer buffer; File *file = filesystem->open((*i).c_str()); file->readBuffer(&buffer); if (strcmp(exten, ".fsh") == 0) { const char *c_str = buffer.data; GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER ); glShaderSource( fragmentShader, 1, &c_str, NULL ); glCompileShader( fragmentShader ); shaders[name] = fragmentShader; GLint status; glGetShaderiv( fragmentShader, GL_COMPILE_STATUS, &status ); if (status == GL_TRUE) { printf("Loaded fragment shader: %s (%d)\n", name, fragmentShader); } else { char buffer[512]; glGetShaderInfoLog( fragmentShader, 512, NULL, buffer ); printf("Error loading fragment shader: %s (%d)\n", name, fragmentShader); printf("%s\n", buffer); } } else if (strcmp(exten, ".vsh") == 0) { const char *c_str = buffer.data; GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER ); glShaderSource( vertexShader, 1, &c_str, NULL ); glCompileShader( vertexShader ); shaders[name] = vertexShader; GLint status; glGetShaderiv( vertexShader, GL_COMPILE_STATUS, &status ); if (status == GL_TRUE) { printf("Loaded vertex shader: %s (%d)\n", name, vertexShader); } else { char buffer[512]; glGetShaderInfoLog( vertexShader, 512, NULL, buffer ); printf("Error loading vertex shader: %s (%d)\n", name, vertexShader); printf("%s\n", buffer); } } delete file; } // Compile all the programs. for (DirectoryList::iterator i = list.begin(); i != list.end(); ++i) { char exten[10]; util->getFileExtension(exten, (*i).c_str()); if (strcmp(exten, ".kv") == 0) { char name[50]; util->getFileName(name, (*i).c_str()); util->getFileNameNoExtension(name, name); Buffer buffer; File *file = filesystem->open((*i).c_str()); file->readBuffer(&buffer); KeyValue *kv = util->parseKeyValue(&buffer); GLuint shaderProgram = glCreateProgram(); KeyValue *shadermembers = kv->getMember("shaders"); if (shadermembers != NULL) { unsigned int b = 0; KeyValue *member = shadermembers->getMember(b); while ((member = shadermembers->getMember(b)) != NULL) { glAttachShader( shaderProgram, shaders[member->getString()] ); b++; } } KeyValue *fragdatamembers = kv->getMember("fragdata"); if (fragdatamembers != NULL) { unsigned int b = 0; KeyValue *member = fragdatamembers->getMember(b); while ((member = fragdatamembers->getMember(b)) != NULL) { glBindFragDataLocation( shaderProgram, b, member->getString().c_str()); b++; } } glLinkProgram( shaderProgram ); glUseProgram( shaderProgram ); GLint posAttrib = glGetAttribLocation( shaderProgram, "position" ); glEnableVertexAttribArray( posAttrib ); glVertexAttribPointer( posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0 ); programs[name] = shaderProgram; printf("Loaded program: %s (%d)\n", name, shaderProgram); kv->release(); file->release(); } } glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glBlendEquation( GL_FUNC_ADD ); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); loadMaterial("disttex.tga"); loadMaterial("8.tga"); // load default textures ImageData white(1, 1); white.setPixel(0, 0, Color(255, 255, 255)); loadMaterial("white", &white); ImageData black(1, 1); black.setPixel(0, 0, Color(0, 0, 0)); loadMaterial("black", &black); glfwSetMouseButtonCallback(&MousePressedCallback); }