Exemple #1
0
void RiftAppSkeleton::LoadTexturesFromFile()
{
    Timer t;
    const std::string texdir("../textures/");
    const std::vector<std::string> texturenames = GetListOfFilesFromDirectory(texdir);
    for (std::vector<std::string>::const_iterator it = texturenames.begin();
        it != texturenames.end();
        ++it)
    {
        const std::string& s = *it;
        const std::string fullName = texdir + s;

        GLuint texId = 0;
        GLuint width = 0;
        GLuint height = 0;
        ///@todo Case insensitivity?
        if (hasEnding(fullName, ".jpg"))
            texId = LoadTextureFromJpg(fullName.c_str(), &width, &height);
        else if (hasEnding(fullName, ".png"))
            texId = LoadTextureFromPng(fullName.c_str(), &width, &height);

        textureChannel tc = {texId, width, height};
        m_texLibrary[s] = tc;
    }
    std::cout << "Textures loaded in " << t.seconds() << " seconds." << std::endl;

    m_shaderToyScene.SetTextureLibraryPointer(&m_texLibrary);
}
std::vector<std::string> GetListOfFilesFromDirectoryAndSubdirs(const std::string& d)
{
    std::vector<std::string> names;
    std::vector<std::string> directories;

    DIR *dir;
    struct dirent *ent;
    if ((dir = opendir (d.c_str())) != NULL)
    {
        while ((ent = readdir (dir)) != NULL)
        {
            std::string s(ent->d_name);
            if (!s.compare("."))
                continue;
            if (!s.compare(".."))
                continue;
#ifndef _LINUX
            if (S_ISDIR(ent->d_type))
            {
                directories.push_back(s);
                continue;
            }
#endif
            names.push_back(s);
        }
        closedir(dir);
    }
    else
    {
        // could not open directory
    }

    // Scan all subdirectories(only one level deep, not recursion)
    for (std::vector<std::string>::const_iterator it = directories.begin();
        it != directories.end();
        ++it)
    {
        const std::string& subdir = *it;
        std::vector<std::string> dirFiles = GetListOfFilesFromDirectory(d + subdir);
        for (std::vector<std::string>::const_iterator it = dirFiles.begin();
            it != dirFiles.end();
            ++it)
        {
            const std::string& f = *it;
            const std::string filepath = subdir + "/" + f;
            names.push_back(filepath);
        }
    }

    std::sort(names.begin(), names.end());
    return names;
}
Exemple #3
0
void RiftAppSkeleton::DiscoverShaders()
{
    const std::vector<std::string> shadernames = GetListOfFilesFromDirectory("../shaders/");
    for (std::vector<std::string>::const_iterator it = shadernames.begin();
        it != shadernames.end();
        ++it)
    {
        const std::string& s = *it;

        ShaderToy* pSt = new ShaderToy(s);
        if (pSt == NULL)
            continue;

        m_shaderToys.push_back(pSt);

        Pane* pP = m_paneScene.AddShaderPane(pSt);
        pP->initGL();
    }
}