Util.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "Util.h"
  2. #include "stb_image.h"
  3. Util::Util()
  4. {
  5. }
  6. Util::~Util()
  7. {
  8. }
  9. GLuint Util::loadTexture(const std::string &filename)
  10. {
  11. int width, height, bpp;
  12. stbi_set_flip_vertically_on_load(true);
  13. unsigned char* imgData = stbi_load(filename.c_str(), &width, &height, &bpp, 4);
  14. GLuint num;
  15. glGenTextures(1, &num);
  16. glBindTexture(GL_TEXTURE_2D, num);
  17. glTexImage2D(GL_TEXTURE_2D,
  18. 0, //level
  19. GL_RGBA, //internal format
  20. width, //width
  21. height, //height
  22. 0, //border
  23. GL_RGBA, //data format
  24. GL_UNSIGNED_BYTE, //data type
  25. imgData); //data
  26. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  27. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  28. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  29. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  30. stbi_image_free(imgData);
  31. return num;
  32. }
  33. void Util::glutBitmapString(std::string str, int x, int y)
  34. {
  35. glRasterPos2f(x, y);
  36. for (int i = 0; i < str.size(); i++)
  37. {
  38. glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
  39. }
  40. }