fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. class TextureLoader;
  5. class Texture
  6. {
  7. public:
  8.  
  9. typedef std::size_t Id;
  10. static const Id NULL_ID = 0;
  11.  
  12. private:
  13.  
  14. // width, height, depth
  15.  
  16. Id _id = NULL_ID;
  17. };
  18.  
  19. class TextureLoader
  20. {
  21. public:
  22.  
  23. virtual bool load(const std::string& filepath, Texture* texture) = 0;
  24. virtual void destroy(Texture* texture) = 0;
  25. };
  26.  
  27. class OglTextureLoader : public TextureLoader
  28. {
  29. public:
  30.  
  31. virtual bool load(const std::string& filepath, Texture* texture)
  32. {
  33. /*
  34.   // load the texture in an image
  35.   GLuint actualTexture = 0;
  36.   // gl specific code...
  37.   texture->_id = nextId();
  38.   // resize array if _actualTextures if required
  39.   _actualTextures[texture->id] = actualTexture;
  40.   */
  41. std::cout << "Loading image: " << filepath << "...\n";
  42. std::cout << "Uploading image to OpenGL Texture...\n";
  43. return true;
  44. }
  45.  
  46. virtual void destroy(Texture* texture)
  47. {
  48. // glDeleteTextures(_oglTextures[texture->_id]);
  49. std::cout << "Destroying OpenGL Texture\n";
  50. }
  51.  
  52. private:
  53.  
  54. std::vector<unsigned int /* GLuint */> _oglTextures; // use texture id's for index
  55. };
  56.  
  57. int main(int argc, char* argv[])
  58. {
  59. Texture texture;
  60. TextureLoader* textureLoader = new OglTextureLoader;
  61.  
  62. if(!textureLoader->load("something.png", &texture))
  63. {
  64. std::cout << "Failed to load something.png";
  65. }
  66.  
  67. textureLoader->destroy(&texture);
  68.  
  69. delete textureLoader;
  70. return 0;
  71. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
Loading image: something.png...
Uploading image to OpenGL Texture...
Destroying OpenGL Texture