55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
|
|
/*
|
||
|
|
#include <GL/glew.h>
|
||
|
|
*/
|
||
|
|
#include <GLES2/gl2.h>
|
||
|
|
#include "../../HEADERS/EFFECTS/ReelManager.h"
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
/* equals stdlib.h from C */
|
||
|
|
#include <cstdlib>
|
||
|
|
|
||
|
|
ReelManager::ReelManager(unsigned int textureNumber, unsigned int width, unsigned int height) {
|
||
|
|
TEXTURE_NUM = textureNumber;
|
||
|
|
textures = (GLuint*) malloc(TEXTURE_NUM * sizeof(GLuint));
|
||
|
|
glGenFramebuffers(1, &FBO);
|
||
|
|
glGenTextures(TEXTURE_NUM, textures);
|
||
|
|
for (int i = 0; i < TEXTURE_NUM; i++) {
|
||
|
|
glActiveTexture(GL_TEXTURE0);
|
||
|
|
glBindTexture(GL_TEXTURE_2D, textures[i]);
|
||
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||
|
|
}
|
||
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
void ReelManager::nextTexture() {
|
||
|
|
currentIndex = ++currentIndex % TEXTURE_NUM;
|
||
|
|
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
|
||
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[currentIndex], 0);
|
||
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
void ReelManager::clearTexture() {
|
||
|
|
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
|
||
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[currentIndex], 0);
|
||
|
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
GLuint ReelManager::getFBO() {
|
||
|
|
return FBO;
|
||
|
|
}
|
||
|
|
|
||
|
|
std::vector<GLuint> ReelManager::getTextures() {
|
||
|
|
std::vector<GLuint> vec = std::vector<GLuint>();
|
||
|
|
for (int i = currentIndex + 1 ; i < TEXTURE_NUM; i++) {
|
||
|
|
vec.push_back(textures[i]);
|
||
|
|
}
|
||
|
|
for (int i = 0; i <= currentIndex; i++) {
|
||
|
|
vec.push_back(textures[i]);
|
||
|
|
}
|
||
|
|
return vec;
|
||
|
|
}
|