Last active
February 7, 2018 19:38
-
-
Save phrz/ffeba3c8478f3e9067c6cf0215add392 to your computer and use it in GitHub Desktop.
Conway's Game of Life (OpenGL with SFML + GLSL shader) in 818 bytes
This file contains hidden or 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
| // -std=c++1z -lsfml-graphics -lsfml-window -lsfml-system -Ofast -ffast-math | |
| #import<SFML/Graphics.hpp> | |
| #define B b[i++]=x | |
| using namespace sf;Sprite q;RenderTexture r;Texture j;Shader d;Event e;long i,w=1300,z=w*w*4,x;int main(){auto*b=new Uint8[z];RenderWindow y(VideoMode(w,w),"");d.loadFromMemory("#define g(A,B)mod(gl_FragCoord.A+B,r.A)\n#define V(A,B)texture2D(t,vec2(g(x,A),g(y,B))/r).r\n#define f float\n#define F(A)for(f A=-1.;A<2.;A++)\nuniform sampler2D t;uniform vec2 r;void main(){f s;F(i)F(j)s+=V(i,j);s=f(s==3.||(V(0.,0.)==1.&&s==4.));gl_FragColor=vec4(s,s,s,1.);}",Shader::Fragment);d.setUniform("r",Vector2f(w,w)),j.create(w,w),r.create(w,w);for(;i<z;i++)x=rand()%2*255,B,B,B,b[i]=255;j.update(&b[0]),q.setTexture(j),r.draw(q),r.display(),q.setTexture(r.getTexture());for(;;){while(y.pollEvent(e))if(e.type==Event::Closed)exit(0);y.draw(q),y.display(),r.draw(q,&d),r.display();}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment