NormalTexture.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. #include <cmath>
  2. #include <iostream>
  3. #include "client/rendering/NormalTexture.h"
  4. #include "client/utils/PNGReader.h"
  5. NormalTexture::NormalTexture(const char* path) : texture(Texture::NEAREST) {
  6. u32 maxWidth = 256;
  7. u32 maxHeight = 256;
  8. u32 buffer[256 * 256];
  9. if(PNGReader::load(path, buffer, maxWidth, maxHeight)) {
  10. for(uint x = 0; x < maxWidth; x++) {
  11. for(uint y = 0; y < maxHeight; y++) {
  12. /*float fx = (x % 16) * (2.0f * M_PIf32 / 15.0f);
  13. float fb = (sinf(fx) + 1.0f) * 0.5f;
  14. uint r = 0;
  15. uint g = sqrtf(1 - fb * fb) * 255.0f;
  16. uint b = fb * 255.0f;
  17. if(y == 0)
  18. std::cout << x << " " << fb << "\n";
  19. buffer[y * maxWidth + x] = (b << 16) | (g << 8) | r;*/
  20. buffer[y * maxWidth + x] = 0x00FF00;
  21. }
  22. }
  23. texture.setRGBAData(maxWidth, maxHeight, buffer);
  24. }
  25. }
  26. void NormalTexture::bind(uint index) const {
  27. texture.bind(index);
  28. }