Skip to content
Snippets Groups Projects
Commit e24103ab authored by Jonathan Kunstwald's avatar Jonathan Kunstwald
Browse files

Code cleanup III

parent 7834586a
No related branches found
No related tags found
No related merge requests found
......@@ -8,42 +8,42 @@ glow::SharedTexture2D flock::tex_utils::generateRandom1DTexture(int extent)
{
auto tex = glow::Texture2D::create(extent, 1, GL_RGBA);
float* pRaw = new float[extent * 4];
unsigned const size = static_cast<unsigned>(extent) * 4u;
for (uint32_t n = 0; n < extent * 4; n++)
pRaw[n] = rand() / (float)RAND_MAX;
std::vector<float> randomData(size);
for (auto n = 0u; n < size; ++n)
randomData[n] = rand() / static_cast<float>(RAND_MAX);
{
auto boundTex = tex->bind();
boundTex.setWrap(GL_REPEAT, GL_REPEAT);
boundTex.setMinFilter(GL_LINEAR);
boundTex.setMagFilter(GL_LINEAR);
boundTex.setData(GL_RGBA, extent, 1, GL_RGBA, GL_FLOAT, pRaw);
boundTex.setData(GL_RGBA, extent, 1, GL_RGBA, GL_FLOAT, randomData.data());
}
delete[] pRaw;
return tex;
}
glow::SharedTexture2D flock::tex_utils::generateSpotTexture(int width, int height)
glow::SharedTexture2D flock::tex_utils::generateSpotTexture(unsigned width, unsigned height)
{
auto tex = glow::Texture2D::create(width, height, GL_RED);
auto tex = glow::Texture2D::create(static_cast<int>(width), static_cast<int>(height), GL_RED);
uint8_t* pRaw = new uint8_t[width * height];
unsigned const size = width * height;
const float fMaxDist = (float)sqrt(width * height / 2.f);
for (uint32_t y = 0; y < height; y++)
{
for (uint32_t x = 0; x < width; x++)
std::vector<uint8_t> spotData(size);
const float fMaxDist = std::sqrt(size / 2.f);
for (auto y = 0u; y < height; ++y)
for (auto x = 0u; x < width; ++x)
{
float length = (float)sqrt((x - width / 2.f) * (x - width / 2.f) + (y - height / 2.f) * (y - height / 2.f));
float length = std::sqrt((x - width / 2.f) * (x - width / 2.f) + (y - height / 2.f) * (y - height / 2.f));
float fSpot = (float)powf((fMaxDist - length) / fMaxDist, 8.f);
float fSpot = std::pow((fMaxDist - length) / fMaxDist, 8.f);
fSpot = fSpot > 1.f ? 1.f : fSpot;
pRaw[x + y * width] = fSpot > 0 ? (uint8_t)(fSpot * 255.f) : 0;
}
spotData[x + y * width] = fSpot > 0 ? static_cast<uint8_t>(fSpot * 255.f) : 0;
}
{
......@@ -51,11 +51,9 @@ glow::SharedTexture2D flock::tex_utils::generateSpotTexture(int width, int heigh
boundTex.setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
boundTex.setMagFilter(GL_LINEAR);
boundTex.setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
boundTex.setData(GL_RED, width, height, GL_RED, GL_UNSIGNED_BYTE, pRaw);
boundTex.setData(GL_RED, static_cast<int>(width), static_cast<int>(height), GL_RED, GL_UNSIGNED_BYTE, spotData.data());
boundTex.generateMipmaps();
}
delete[] pRaw;
return tex;
}
......@@ -9,6 +9,6 @@ namespace flock
namespace tex_utils
{
glow::SharedTexture2D generateRandom1DTexture(int extent);
glow::SharedTexture2D generateSpotTexture(int width, int height);
glow::SharedTexture2D generateSpotTexture(unsigned width, unsigned height);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment