コード例 #1
0
ファイル: graphics.cpp プロジェクト: qwook/spine
Material CGraphicsModule::loadMaterial(const char *matName, ImageData *data) {
    Material material = materials[matName];
    
    if (material.mat) {
        return useMaterial(matName);
    }
    
    GLuint textureID;
    glGenTextures( 1, &textureID );
    glActiveTexture(GL_TEXTURE0);
    glBindTexture( GL_TEXTURE_2D, textureID );
    
    unsigned int format = GL_RGBA;
    unsigned int level = 0;
    glTexImage2D( GL_TEXTURE_2D, level, format,
                 data->width, data->height, 0, format,
                 GL_UNSIGNED_BYTE, (void*) data->data );
    
    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_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
    
    Material ret = { (unsigned int)textureID, data->width, data->height };
    materials[matName] = ret;
    
    return ret;
}
コード例 #2
0
// Add an overwrite primitive material
void GLC_RenderProperties::addOverwritePrimitiveMaterial(GLC_uint id, GLC_Material* pMaterial, int bodyIndex)
{
	Q_ASSERT(NULL != pMaterial);
	if (NULL != m_pOverwritePrimitiveMaterialMaps)
	{
		if (m_pOverwritePrimitiveMaterialMaps->contains(bodyIndex))
		{
			QHash<GLC_uint, GLC_Material*>* pHash= m_pOverwritePrimitiveMaterialMaps->value(bodyIndex);
			if (pHash->contains(id))
			{
				if (pHash->value(id) != pMaterial)
				{
					GLC_Material* pOldMaterial= pHash->value(id);
					unUseMaterial(pOldMaterial);
					pHash->remove(id);

					pHash->insert(id, pMaterial);
					useMaterial(pMaterial);
				}
				// Else, noting to do
			}
			else
			{
				pHash->insert(id, pMaterial);
				useMaterial(pMaterial);
			}
		}
		else
		{
			QHash<GLC_uint, GLC_Material*>* pHash= new QHash<GLC_uint, GLC_Material*>();
			pHash->insert(id, pMaterial);
			useMaterial(pMaterial);
			m_pOverwritePrimitiveMaterialMaps->insert(bodyIndex, pHash);
		}
	}
	else
	{
		m_pOverwritePrimitiveMaterialMaps= new QHash<int, QHash<GLC_uint, GLC_Material*>* >();
		QHash<GLC_uint, GLC_Material*>* pHash= new QHash<GLC_uint, GLC_Material*>();
		pHash->insert(id, pMaterial);
		m_pOverwritePrimitiveMaterialMaps->insert(bodyIndex, pHash);
		useMaterial(pMaterial);
	}
}
コード例 #3
0
ファイル: graphics.cpp プロジェクト: qwook/spine
Material CGraphicsModule::loadMaterial(const char *matName) {
    Material material = materials[matName];
    
    if (material.mat) {
        return useMaterial(matName);
    }
    
    GLuint textureID;
    glGenTextures( 1, &textureID );
    
    GLFWimage teximg; // Use intermediate GLFWimage to get width and height
    
    if(!glfwReadImage(matName, &teximg, GLFW_NO_RESCALE_BIT))
        printf("I/O error %s", "Failed to load distance texture from TGA file.");
    
    glActiveTexture(GL_TEXTURE0);
    glBindTexture( GL_TEXTURE_2D, textureID );
    
    glfwLoadTextureImage2D( &teximg, 0 );
    
    unsigned int width = teximg.Width, height = teximg.Height;
    
    // The special shader used to render this texture performs its own minification
    // and magnification. Specify nearest neighbor sampling to avoid trampling
    // over the distance values split over two channels as 8.8 fixed-point data.
    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_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
    glfwFreeImage(&teximg); // Clean up the malloc()'ed data pointer
    
    Material ret = { (unsigned int)textureID, width, height };
    materials[matName] = ret;
    
    return ret;
}