Texture.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "rendering/wrapper/Texture.h"
  2. #include "rendering/wrapper/GLWrapper.h"
  3. Texture::Texture() : texture(0) {
  4. glGenTextures(1, &texture);
  5. glBindTexture(GL_TEXTURE_2D, texture);
  6. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  7. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  8. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  9. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  10. }
  11. Texture::~Texture() {
  12. glDeleteTextures(1, &texture);
  13. }
  14. void Texture::setColorData(int width, int height, const Color4* data) {
  15. setColorData(width, height, GL_RGBA, data);
  16. }
  17. void Texture::setColorData(int width, int height, const Color3* data) {
  18. setColorData(width, height, GL_RGB, data);
  19. }
  20. void Texture::setColorData(int width, int height, const Color2* data) {
  21. setColorData(width, height, GL_RG, data);
  22. }
  23. void Texture::setColorData(int width, int height, const Color1* data) {
  24. setColorData(width, height, GL_RED, data);
  25. }
  26. void Texture::bind() const {
  27. glActiveTexture(GL_TEXTURE0);
  28. glBindTexture(GL_TEXTURE_2D, texture);
  29. }