コード例 #1
0
GLuint gl4::TextureManager::_loadTextureFromTGA(const char *filename) {
	GLuint textureID = 0;
	GLFWimage img;

	if(!glfwReadImage(filename, &img, GLFW_NO_RESCALE_BIT))
		std::cerr << "   Failed to load texture from TGA file." << std::endl;

	glGenTextures(1, &textureID);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture( GL_TEXTURE_2D, textureID );

	glfwLoadTextureImage2D( &img, 0 );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	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(&img); // Clean up the malloc()'ed data pointer
	return textureID;
}
コード例 #2
0
/*
 * loadDistTexture - load 8-bit distance texture data
 * from a TGA file and set up the corresponding texture object.
 */
void loadDistTexture(char *filename, GLuint texID, int *texw, int *texh) {
  
  GLFWimage teximg; // Use intermediate GLFWimage to get width and height

  if(!glfwReadImage(filename, &teximg, GLFW_NO_RESCALE_BIT))
    printError("I/O error", "Failed to load distance texture from TGA file.");
  
  *texw = teximg.Width;
  *texh = teximg.Height;
  
  glActiveTextureARB(GL_TEXTURE0);
  glBindTexture( GL_TEXTURE_2D, texID );

  glfwLoadTextureImage2D( &teximg, 0 );
  // 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
}
コード例 #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;
}