Last active
February 9, 2023 09:26
-
-
Save ponnamkarthik/e9938ffb1e40e30172ebc06a956d966c to your computer and use it in GitHub Desktop.
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
class ShaderHomePage extends StatefulWidget { | |
const ShaderHomePage({super.key}); | |
@override | |
State<ShaderHomePage> createState() => _ShaderHomePageState(); | |
} | |
class _ShaderHomePageState extends State<ShaderHomePage> { | |
late Timer timer; | |
double delta = 0; | |
FragmentShader? shader; | |
void loadMyShader() async { | |
var program = await FragmentProgram.fromAsset('shaders/shader.frag'); | |
shader = program.fragmentShader(); | |
setState(() { | |
// trigger a repaint | |
}); | |
timer = Timer.periodic(const Duration(milliseconds: 16), (timer) { | |
setState(() { | |
delta += 1 / 60; | |
}); | |
}); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
loadMyShader(); | |
} | |
@override | |
void dispose() { | |
timer.cancel(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
if (shader == null) { | |
return const Center(child: CircularProgressIndicator()); | |
} else { | |
return CustomPaint(painter: ShaderPainter(shader!, delta)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment