Repository navigation
Expand file tree
/
Copy pathSnowTrailMap.cpp
More file actions
54 lines (44 loc) · 1.59 KB
/
Copy pathSnowTrailMap.cpp
File metadata and controls
54 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "SnowTrailMap.h"
#include <iostream>
SnowTrailMap::SnowTrailMap(int w, int h) : width_(w), height_(h)
{
glGenFramebuffers(1, &fbo);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width_, height_, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GLenum drawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, drawBuffers);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cerr << "SnowTrailMap FBO incomplete!" << std::endl;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// Initial full snow (white = 255 = full height)
clear();
}
SnowTrailMap::~SnowTrailMap()
{
glDeleteTextures(1, &texture);
glDeleteFramebuffers(1, &fbo);
}
void SnowTrailMap::bindForWriting()
{
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glViewport(0, 0, width_, height_);
}
void SnowTrailMap::bindForReading(GLenum unit)
{
glActiveTexture(unit);
glBindTexture(GL_TEXTURE_2D, texture);
}
void SnowTrailMap::clear()
{
bindForWriting();
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // FULL SNOW
glClear(GL_COLOR_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}