Skip to content

Instantly share code, notes, and snippets.

@phrz
Last active February 7, 2018 19:38
Show Gist options
  • Select an option

  • Save phrz/ffeba3c8478f3e9067c6cf0215add392 to your computer and use it in GitHub Desktop.

Select an option

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
// -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