Example #1
0
bool Renderer::AddTexture(const char * filename, TextureCategory category, TextureWrap wrapS, TextureWrap wrapT, bool invertY)
{
	assert(filename != nullptr);

	uint32_t width = 128;
	uint32_t height = 128;

	TextureManager::GetTiffImageSize(filename, width, height);

	uint16_t rendererId = (uint16_t)GetInstanceId();

	TextureInfo textureInfo(filename, rendererId, category, (GLsizei)width, (GLsizei)height, wrapS, wrapT, invertY);

	mTextureInfoList.push_back(textureInfo);

	return true;
}
Example #2
0
//-----------------------------------------------------------------------------------------------
void Material::AddTexture( Texture* texture, std::string textureUniformName, textureUnit activeTextureLayer )
{
	int uniformLocation = OpenGLRenderer::GetUniformLocation( m_glShaderProgram->m_programID, textureUniformName.c_str() );
	TextureInfo textureInfo( texture, uniformLocation, activeTextureLayer );
	m_textures.push_back( textureInfo );
}
Example #3
0
void SphereGenerator::output()
{
//    texture = cv::imread(sTexture.toStdString().c_str());
//    QDateTime currTime = QDateTime::currentDateTime();
//    long long timeStamp = currTime.toMSecsSinceEpoch();
    std::ofstream out(sObj.toStdString().c_str());
    // for usemtl
    QString keyWords = "wire_sphere";
    out << "# created by h005 SphereGenerator" << std::endl;
    out << std::endl;
    // mtl file
    QFileInfo objFile(sObj);
    QString mtlFile(objFile.absolutePath());
    mtlFile.append("/");
    mtlFile.append(objFile.baseName());
    mtlFile.append(".mtl");
    QFileInfo mtlFileInfo(mtlFile);

    out << "mtllib "<< mtlFileInfo.fileName().toStdString() <<std::endl;

    for(int i=0;i<centerList.size();i++)
        out << "v "<< centerList.at(i).x
                  << " " << centerList.at(i).y
                  << " " << centerList.at(i).z << std::endl;

    out << "# "<< centerList.size() << " vertices" << std::endl;

    if(isCircle)
        sZ++;

    float uStep = 1.0 / (float)(sX-1);
    float vStep = 1.0 / (float)(sZ-1);

//    float u = 1.0f,v = 1.0f;
    float u = 0.f, v = 1.0f;
    for(int i=0;i<sX;i++)
    {
        v = 1.0f;
        for(int j=0;j<sZ;j++)
        {
            out << "vt " << u << " " << v << std::endl;
            v -= vStep;
            if( v < 0.f)
                v = 0.f;
        }
        u += uStep;
        if(u > 1.f)
            u = 1.f;
    }

    out << "# "<< centerList.size() << " texture coords" << std::endl;

    out << "g " << "Sphere 001"<< std::endl;

//    out << "usemtl " << keyWords.toStdString() << std::endl;

    out << "s 1" << std::endl;

    if(!isCircle)
    {
        for(int i=0;i<sX-1;i++)
        {
            for(int j=1;j<sZ;j++)
            {
                out << "f " << i * sZ + j << "/" << i * sZ + j << " ";
                out << (i+1) * sZ + j << "/" << (i+1) * sZ + j << " ";
                out << (i+1) * sZ + j + 1 << "/" << (i+1) * sZ + j + 1 << " ";
                out << i * sZ + j + 1 << "/" << i * sZ + j + 1 << std::endl;
            }
        }
        out << "# "<<(sX-1)*(sZ-1)<<" polygons"<<std::endl;
    }
    else
    {
        // 先完成环的那部分
        sZ--;
        for(int i=0;i<sX-1;i++)
        {
            for(int j=1;j<sZ;j++)
            {
                out << "f " << i * sZ + j << "/" << i * (sZ + 1) + j << " ";
                out << (i+1) * sZ + j << "/" << (i+1) * (sZ + 1) + j << " ";
                out << (i+1) * sZ + j + 1 << "/" << (i+1) * (sZ + 1) + j + 1 << " ";
                out << i * sZ + j + 1 << "/" << i * (sZ + 1) + j + 1 << std::endl;
            }
        }

        // 将环给衔接起来
            for(int i=0;i<sX-1;i++)
            {
                out << "f " << i * sZ + 1 << "/" << (i + 1) * (sZ + 1) << " ";
                out << (i+1) * sZ << "/" << (i+1) * (sZ + 1) - 1 << " ";
                out << (i+2) * sZ << "/" << (i+2) * (sZ + 1) - 1 << " ";
                out << (i+1) * sZ + 1 << "/" << (i+2) * (sZ + 1) << std::endl;
            }

        out << "# "<<(sX)*(sZ-1)<<" polygons"<<std::endl;
    }

    out.close();

    std::cout << "mtlFile "<<mtlFile.toStdString() << std::endl;
    out.open(mtlFile.toStdString().c_str());

    out << "# created by h005 SphereGenerator" << std::endl;
    out << "newmtl wire_plane" << std::endl;
    out << "	Ns 32"<< std::endl;
    out << "	d 1"<< std::endl;
    out << "	Tr 0" << std::endl;
    out << "	Tf 1 1 1"<< std::endl;
    out << "	illum 2" << std::endl;
    out << "	Ka 0.7765 0.8824 0.3412"<< std::endl;
    out << "	Kd 0.7765 0.8824 0.3412"<< std::endl;
    out << "	Ks 0.3500 0.3500 0.3500"<< std::endl;
    QFileInfo textureInfo(sTexture);
    out << "	map_Ka "<< textureInfo.fileName().toStdString() << std::endl;
    out << "	map_Kd "<< textureInfo.fileName().toStdString() << std::endl;

    out.close();
}