+#include <GLES3/gl32.h>
+#include <string>
#include <vector>
-extern "C" int foo() {
- std::vector<int> *xs = new std::vector<int>();
- xs->push_back(42);
- return (*xs)[0];
+#include <glm/glm.hpp>
+#include <glm/ext.hpp>
+#include <glm/gtc/type_ptr.hpp>
+
+const char* vertShaderSrc = R"(
+attribute vec4 vertPos;
+uniform mat4 model;
+void main() {
+ gl_Position = model * vertPos;
+}
+)";
+
+const char *fragShaderSrc = R"(
+void main() {
+ gl_FragColor = vec4(1, 0, 1, 1);
+}
+)";
+
+GLuint program;
+
+extern "C" void setup() {
+ GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
+ const char* sources[1] = { vertShaderSrc };
+ const GLint lengths[1] = { (GLint)strlen(vertShaderSrc) };
+ glShaderSource(vertShader, 1, sources, lengths);
+ glCompileShader(vertShader);
+
+ GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);
+ glShaderSource(fragShader, 1,
+ new const char*[1] { fragShaderSrc },
+ new const GLint[1] { (GLint)strlen(fragShaderSrc) });
+ glCompileShader(fragShader);
+
+ program = glCreateProgram();
+ glAttachShader(program, vertShader);
+ glAttachShader(program, fragShader);
+ glLinkProgram(program);
+ glUseProgram(program);
+
+ GLuint vertPosBuffer;
+ glGenBuffers(1, &vertPosBuffer);
+ glBindBuffer(GL_ARRAY_BUFFER, vertPosBuffer);
+ std::vector<float> vertPositions = {
+ 0, 1, 0,
+ 1, -1, 0,
+ -1, -1, 0
+ };
+ glBufferData(GL_ARRAY_BUFFER, vertPositions.size(), vertPositions.data(), GL_STATIC_DRAW);
+
+ GLuint vertPosLoc = glGetAttribLocation(program, "vertPos");
+ glEnableVertexAttribArray(vertPosLoc);
+ glVertexAttribPointer(vertPosLoc, 3, GL_FLOAT, false, 0, 0);
+}
+
+extern "C" void update(int tick) {
+ GLuint modelLoc = glGetUniformLocation(program, "model");
+ const glm::mat4 model = glm::rotate(glm::mat4(1), (float)tick * 0.001f, glm::vec3(0, 0, 1));
+ glUniformMatrix4fv(modelLoc, 1, false, glm::value_ptr(model));
}