Advertisement
Guest User

codedeedede

a guest
Dec 8th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. void Mesh::LoadTexture(const char* filename)
  2. {
  3. //Pointless use of bmp file type
  4. // load bmp through SDL
  5. //SDL_Surface* image = SDL_LoadBMP(filename);
  6.  
  7. //Replacement for bitmap fileloading using IMG_Load
  8. //this supports the use of many different image file types
  9. SDL_Surface* image = IMG_Load(filename);
  10.  
  11. // check if the image has loaded if not throw a hissy fit
  12. if (!image)
  13. {
  14. system("cd");
  15. std::cout << "FAILED : Cannot open file:" << filename << std::endl;
  16. return;
  17. }
  18.  
  19. //if successfull tell everyone about it
  20. std::cout << "SUCCESS : Texture loaded" << std::endl;
  21.  
  22. // generate texture from inported data using glew
  23. glGenTextures(1, &diffuseTexID);
  24. glBindTexture(GL_TEXTURE_2D, diffuseTexID);
  25.  
  26. //try catch to see if anything fails - stuff likes to fail
  27. try {
  28.  
  29. //set up image data and pass into glTexImage2D which converts our image to a texture
  30. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->w, image->h, 0, GL_RGB, GL_UNSIGNED_BYTE, image->pixels);
  31.  
  32. //free the poor loaded image
  33. SDL_FreeSurface(image);
  34.  
  35. //Applyparameters to texturing
  36. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  37. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  38. }
  39. catch(...)
  40. {
  41. std::cout << "texture could not be loaded, check filename and filetype\n";
  42. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  43. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement