Esempio n. 1
0
Texture* ContentManager::loadTexture( const char* path )
{
	Texture* result;
	std::string s = std::string(path);
	
	// check if key is present
	if (textures.find(s) != textures.end())
		result = textures[s];
	else
	{
		result = textureFromFile( path );
		textures[s] = result;
	}

	return result;
}
Esempio n. 2
0
workshopScene::workshopScene(std::string path_)
:mouseRayCallback(btVector3(0, 0, 0), btVector3(0, 0, 0)),
 axisResult(btVector3(0, 0, 0), btVector3(0, 0, 0))
{
    path = path_;
    DIR *dir;
    dirent *ent;
    gWorld = new world();
    gWorld->btWorld->setGravity(btVector3(0, 0, 0));
    mouseConstraint = 0;
    std::stringstream ss;
    ss << path << "data/plane_10x10.bsm";
    gWorld->addObject(new physObj(0, btVector3(0, -1, 0), new btStaticPlaneShape(btVector3(0, 1, 0), 1), new model(ss.str())));
    ss.str("");
    ss << path << "assemblies";
    dir = opendir(ss.str().c_str());
    if (dir == NULL)
    {
        std::cout << "Could not open assemblies directory.\n";
        return;
    }
    int i = 0;
    while ((ent = readdir(dir)) != NULL)
    {
        if (ent->d_type == DT_DIR && ++i > 2)     //discard "." and ".."
        {
            partnames.push_back(ent->d_name);
        }
    }
    closedir(dir);

    for (unsigned int i = 0; i < partnames.size(); i++)
    {
        std::cout << "Part: " << partnames[i] << "\n";
        std::stringstream ss;
        ss << path << "assemblies/" << partnames[i] << "/thumb.tga";
        std::cout << ss.str() << "\n";
        GLFWimage img;
        if (glfwReadImage(ss.str().c_str(), &img, 0))
        {
            thumbnails.push_back(makeTexture(img));
            glfwFreeImage(&img);
        }
        else
        {
            thumbnails.push_back(0);
            std::cout << "Could not load thumbnail for " << partnames[i] << "\n";
        }
    }
    cursor = textureFromFile("cursor.tga");
    panel = ninePatch(textureFromFile("9patch.tga"));
    button = ninePatch(textureFromFile("button.tga"));
    bubble = ninePatch(textureFromFile("bubble.tga"), 8, 16, 12, 8, 0.25, 0.5, 0.375, 0.75);
    tooltextures.push_back(textureFromFile("drag.tga"));
    tooltextures.push_back(textureFromFile("axis.tga"));
    tooltextures.push_back(textureFromFile("delete.tga"));
    font = textureFromFile("font.tga");
    cursorx = 0;
    cursory = 0;
    mousevelx = 0;
    mousevely = 0;
    mouseWasCaptured = false;
    camera.position = btVector3(0, 0, 10);
    camera.pitch = 0;
    camera.yaw = 0;
    camera.orientationFromAngles();
    selectedItem = -1;
    selectedTool = -1;
    static unsigned char fontpixels[STB_SOMEFONT_BITMAP_HEIGHT][STB_SOMEFONT_BITMAP_WIDTH];
    STB_SOMEFONT_CREATE(fontdata, fontpixels, STB_SOMEFONT_BITMAP_HEIGHT);
    glGenTextures(1, &stbfont);
    glBindTexture(GL_TEXTURE_2D, stbfont);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_WRAP_BORDER);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_WRAP_BORDER);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, STB_SOMEFONT_BITMAP_HEIGHT, STB_SOMEFONT_BITMAP_WIDTH, 0, GL_ALPHA, GL_UNSIGNED_BYTE, fontpixels);
}