-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
935 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#version 130 | ||
|
||
uniform sampler2D inputMap; | ||
uniform ivec2 Coord; | ||
uniform int button; | ||
|
||
out vec4 outColor; | ||
|
||
in vec2 fTexCoord; | ||
|
||
void main(void){ | ||
ivec2 pos = ivec2(gl_FragCoord[0],gl_FragCoord[1]); | ||
vec4 data = texelFetch(inputMap, pos, 0); | ||
ivec2 MCoord = ivec2(Coord.x, Coord.y); | ||
|
||
if(pos == MCoord && button == 0) | ||
{ | ||
data[0] = 1; | ||
data[1] = 1; | ||
data[2] = 1; | ||
data[3] = 1; | ||
} | ||
if(pos == MCoord && button == 2) | ||
{ | ||
data[0] = 0; | ||
data[1] = 0; | ||
data[2] = 0; | ||
data[3] = 0; | ||
} | ||
else | ||
|
||
outColor = data; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "framebuffer.hpp" | ||
|
||
#include <string> | ||
#include <iostream> | ||
|
||
Framebuffer::Framebuffer(GLuint width, GLuint height, GLuint planes){ | ||
this->width = width; | ||
this->height = height; | ||
this->planes = planes; | ||
|
||
buffers = new GLenum[planes]; | ||
|
||
glGenFramebuffers(1, &handle); | ||
colorBuffer = new GLuint[planes]; | ||
glGenTextures(planes, colorBuffer); | ||
glBindFramebuffer(GL_FRAMEBUFFER, handle); | ||
|
||
for(unsigned int i = 0; i < planes; ++i){ | ||
glBindTexture(GL_TEXTURE_2D, colorBuffer[i]); | ||
glTexParameterf(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_BORDER); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | ||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, NULL); | ||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, colorBuffer[i], 0); | ||
buffers[i] = GL_COLOR_ATTACHMENT0 + i; | ||
if(glGetError() != GL_NO_ERROR){ | ||
std::cout << "Framebuffer: Error creating color attachment" << std::endl; | ||
} | ||
} | ||
|
||
glGenRenderbuffers(1, &depthBuffer); | ||
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer); | ||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); | ||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer); | ||
if(glGetError() != GL_NO_ERROR){ | ||
std::cout << "Framebuffer: Error creating depth attachment" << std::endl; | ||
} | ||
|
||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); | ||
if(status != GL_FRAMEBUFFER_COMPLETE){ | ||
std::cout << "Framebuffer: Incomplete framebuffer ("; | ||
switch(status){ | ||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: | ||
std::cout << "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"; | ||
break; | ||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: | ||
std::cout << "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"; | ||
break; | ||
case GL_FRAMEBUFFER_UNSUPPORTED: | ||
std::cout << "GL_FRAMEBUFFER_UNSUPPORTED"; | ||
break; | ||
} | ||
std::cout << ")" << std::endl; | ||
} | ||
|
||
glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
} | ||
|
||
Framebuffer::~Framebuffer(){ | ||
glDeleteFramebuffers(1, &handle); | ||
glDeleteRenderbuffers(1, &depthBuffer); | ||
} | ||
|
||
void Framebuffer::setRenderTarget(){ | ||
glBindFramebuffer(GL_FRAMEBUFFER, handle); | ||
glDrawBuffers(planes, buffers); | ||
glViewport(0,0, width, height); | ||
} | ||
|
||
void Framebuffer::disableRenderTarget(){ | ||
GLenum tmpBuff[] = { GL_COLOR_ATTACHMENT0 }; | ||
glDrawBuffers(1, tmpBuff); | ||
glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||
} | ||
|
||
void Framebuffer::clear(){ | ||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | ||
glClearDepth(1.0f); | ||
setRenderTarget(); | ||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||
disableRenderTarget(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef _FRAMEBUFFER_ | ||
#define _FRAMEBUFFER_ | ||
|
||
#include <GL/glew.h> | ||
|
||
class Framebuffer{ | ||
private: | ||
GLuint handle; | ||
GLuint* colorBuffer; | ||
GLuint depthBuffer; | ||
|
||
GLuint width, height; | ||
GLuint planes; | ||
|
||
GLenum* buffers; | ||
|
||
public: | ||
Framebuffer(GLuint width, GLuint height, GLuint planes); | ||
~Framebuffer(); | ||
|
||
void setRenderTarget(); | ||
void disableRenderTarget(); | ||
|
||
GLuint getColorBuffer(unsigned int plane){ | ||
return colorBuffer[plane]; | ||
} | ||
|
||
void clear(); | ||
|
||
int getWidth(){ | ||
return width; | ||
} | ||
|
||
int getHeight(){ | ||
return height; | ||
} | ||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#version 130 | ||
|
||
|
||
uniform int type; | ||
|
||
in vec2 fTexCoord; | ||
|
||
out vec4 outColor; | ||
|
||
void main(void){ | ||
if(type == 0) | ||
{ | ||
outColor = vec4((tan(fTexCoord.x*25) * sin(fTexCoord.y*3) + sin(fTexCoord.y*12)),0, 0 ,1 ); | ||
} | ||
else | ||
{ | ||
outColor = vec4(0,0, 0 ,1 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#version 130 | ||
|
||
uniform sampler2D inputMap; | ||
|
||
out vec4 outColor; | ||
|
||
in vec2 fTexCoord; | ||
|
||
void main(void){ | ||
// Is current cell alive? | ||
vec4 data = texelFetch(inputMap, ivec2(gl_FragCoord), 0); | ||
float IsAlive = data[0]; | ||
|
||
// Count Neighbours | ||
|
||
float NumberOfNeighbours = round(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2(-1, 0), 0).x) + | ||
round(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2( 1, 0), 0).x) + | ||
round(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2( 0, -1), 0).x) + | ||
round(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2( 0, 1), 0).x) + | ||
round(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2(-1, 1), 0).x) + | ||
round(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2( 1, 1), 0).x) + | ||
round(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2( 1, -1), 0).x) + | ||
round(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2(-1, -1), 0).x); | ||
|
||
/* | ||
float NumberOfNeighbours = floor(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2(-1, 0), 0).x) + | ||
floor(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2( 1, 0), 0).x) + | ||
floor(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2( 0, -1), 0).x) + | ||
floor(texelFetch(inputMap, ivec2(gl_FragCoord) + ivec2( 0, 1), 0).x); | ||
*/ | ||
if(IsAlive > 0.1) | ||
{ | ||
//Any live cell with fewer than two live neighbours dies, as if caused by under-population. | ||
if(NumberOfNeighbours<1.5) | ||
{ | ||
data[0] = 0; | ||
data[1] = 0.7; | ||
data[2] = 0.2; | ||
} | ||
else | ||
//Any live cell with two or three live neighbours lives on to the next generation. | ||
if(NumberOfNeighbours>1.9 && NumberOfNeighbours<3.1) | ||
{ | ||
data[0] = 1; | ||
data[1] = 0.3; | ||
data[2] = 0.3; | ||
} | ||
else | ||
//Any live cell with more than three live neighbours dies, as if by overcrowding. | ||
if(NumberOfNeighbours>3.1) | ||
{ | ||
data[0] = 0; | ||
data[1] = 0; | ||
data[2] = 1; | ||
} | ||
} | ||
else | ||
{ | ||
//Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. | ||
if(NumberOfNeighbours<3.1 && NumberOfNeighbours > 2.9) | ||
{ | ||
data[0] = 1; | ||
data[1] = 1; | ||
data[2] = 1; | ||
} | ||
else | ||
{ | ||
data = data * 0.95; | ||
} | ||
} | ||
outColor = vec4(data[0], data[1], data[2], data[3]); | ||
} |
Oops, something went wrong.