bool GL2TextureManager::init()
	{
		stbi_set_flip_vertically_on_load(true);

		ResourceMeta* meta = loader->includeMeta("default", "texture", "TEXTURE");

		// Init error texture
		u16 id = textures.addResource(meta);
		errorTexture = textures.getResourceAddress(id);
		new (errorTexture)GL2Texture(meta); // Reconstruct object giving it the meta

		GLuint errorTextureId = GenerateErrorTexture();
		errorTexture->m_textureType = GL_TEXTURE_2D;
		errorTexture->m_textureID = errorTextureId;

		// Erase textures
		for (GL2Texture& t : textures.getResources())
		{
			t.m_textureType = errorTexture->m_textureType;
			t.m_textureID = errorTexture->m_textureID;
			t.m_loaded = GL2Texture::TextureLoadState::NOT_LOADED;
			t.meta = meta;
		}

		errorTexture->m_loaded = GL2Texture::TextureLoadState::LOADED;

		return true;
	}
Beispiel #2
0
csRef<iImage> BaseMapGen::LoadImage (const csString& filename, int format)
{
  csPrintf ("Trying to load '%s'... \t", filename.GetData());
  fflush (stdout);
  csRef<iImage> image;
  csRef<iImageIO> imageio = csQueryRegistry<iImageIO> (object_reg);
  csRef<iVFS> VFS = csQueryRegistry<iVFS> (object_reg);

  csRef<iDataBuffer> buf = VFS->ReadFile (filename.GetData(), false);
  if (!buf)
  {
    Report ("Failed to load image file '%s'!", filename.GetData());
    return GenerateErrorTexture (32, 32);
  }
  image = imageio->Load (buf, format);
  image.IsValid() ? csPrintf ("success.\n") : csPrintf ("failed.\n");

  return image;
}