Skip to content

Instantly share code, notes, and snippets.

@ds84182
Created July 22, 2016 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ds84182/93f53d633fc66886dc846403c2c7c777 to your computer and use it in GitHub Desktop.
Save ds84182/93f53d633fc66886dc846403c2c7c777 to your computer and use it in GitHub Desktop.
import "package:sfml/sfml.dart" as sf;
import 'dart:typed_data';
const sf.Attribute attrPosition = const sf.Attribute("attrPosition", 0);
const List<sf.Attribute> attributes = const [
attrPosition
];
const sf.AttributeFormat attrFmtPos2D = const sf.AttributeFormat(sf.AttributeType.Float, 2);
main() async {
var context = new sf.RenderContext(new sf.VideoMode(800, 600), "dart:sf");
var shader = new sf.Shader(context);
await shader.compile(
"""
attribute vec4 attrPosition;
//uniform vec4 unifExample;
void main() {
gl_Position = attrPosition;
}
""",
"""
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
""", attributes);
var vao = new sf.VertexArray(context);
var data = new Float32List.fromList([
0.0, 0.5,
-0.5, -0.5,
0.5, -0.5
]);
var buffer = new sf.VertexBuffer(context, data, sf.BufferUsage.StaticDraw);
vao.bind(attrPosition, buffer, attrFmtPos2D);
var clearCmd = new sf.ClearCommand(new sf.Color.rgba(0, 0, 0));
var shaderBindCmd = new sf.BindShaderCommand(shader);
var vaoBindCmd = new sf.BindVertexArrayCommand(vao);
var drawArrayCmd = new sf.DrawArraysCommand(sf.PrimitiveMode.Triangles, 0, 3);
var commandList = new sf.CommandList(context, [clearCmd, shaderBindCmd, vaoBindCmd, drawArrayCmd]);
context.setCommands([commandList]);
var limiter = new sf.FrameLimiter(60);
context.frame.listen((_) async {
await limiter.sync;
context.render();
});
limiter.fpsStream.listen((fps) {
print("Frame rate: $fps fps");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment