Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. GLuint LoadTexture(const char * filename, int imageWidth, int imageHeight){
  2. GLuint texture;
  3.  
  4. int width, height;
  5.  
  6. unsigned char * data;
  7.  
  8. FILE * file;
  9.  
  10. file = fopen(filename, "rb");
  11.  
  12. if(file == NULL)
  13. return 0;
  14. width = imageWidth;
  15. height = imageHeight;
  16. data = (unsigned char *) malloc (width * height * 3);
  17.  
  18. fread(data, width * height * 3, 1, file);
  19. fclose(file);
  20.  
  21. for(int i = 0; i < width * height; ++i){
  22. int index = i * 3;
  23. unsigned char B,R;
  24. B = data[index];
  25. R = data[index + 2];
  26.  
  27. data[index] = R;
  28. data[index + 2] = B;
  29. }
  30.  
  31. glGenTextures(1, &texture);
  32. glBindTexture(GL_TEXTURE_2D, texture);
  33. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  34. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  35.  
  36. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  37. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  38. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  39. gluBuild2DMipmaps(GL_TEXTURE_2D, 3,width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
  40.  
  41. return texture;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement