12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include <png.h>
- #include <vector>
- #include <cstdlib>
- #include <iostream>
- #include "client/rendering/NoiseTexture.h"
- NoiseTexture::NoiseTexture(u32 width, u32 height)
- {
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- std::vector<float> data;
- for(u32 x = 0; x < width; x++)
- {
- for(u32 y = 0; y < height; y++)
- {
- data.push_back(getRandom());
- data.push_back(getRandom());
- data.push_back(getRandom());
- }
- }
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, data.data());
- }
- NoiseTexture::~NoiseTexture()
- {
- glDeleteTextures(1, &texture);
- }
- void NoiseTexture::bind(unsigned int index) const
- {
- glActiveTexture(GL_TEXTURE0 + index);
- glBindTexture(GL_TEXTURE_2D, texture);
- }
- float NoiseTexture::getRandom() const
- {
- float r = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
- return r * 2.0f - 1.0f;
- }
|