2 #include <ivorium_config.hpp>
11 static GLint program = 0;
12 static GLuint vertexBuffer = 0;
14 static void onFrame(GLFMDisplay *display,
const double frameTime);
15 static void onSurfaceCreated(GLFMDisplay *display,
const int width,
const int height);
16 static void onSurfaceDestroyed(GLFMDisplay *display);
21 glfmSetDisplayConfig(display,
22 GLFMRenderingAPIOpenGLES2,
23 GLFMColorFormatRGBA8888,
25 GLFMStencilFormatNone,
27 glfmSetSurfaceCreatedFunc(display, onSurfaceCreated);
28 glfmSetSurfaceResizedFunc(display, onSurfaceCreated);
29 glfmSetSurfaceDestroyedFunc(display, onSurfaceDestroyed);
30 glfmSetMainLoopFunc(display, onFrame);
38 static void onSurfaceCreated(GLFMDisplay *display,
const int width,
const int height) {
39 glViewport(0, 0, width, height);
42 static void onSurfaceDestroyed(GLFMDisplay *display) {
48 static GLuint compileShader(
const GLenum type,
const GLchar *shaderString) {
49 const GLint shaderLength = (GLint)strlen(shaderString);
50 GLuint shader = glCreateShader(type);
51 glShaderSource(shader, 1, &shaderString, &shaderLength);
52 glCompileShader(shader);
56 static void onFrame(GLFMDisplay *display,
const double frameTime) {
58 const GLchar *vertexShader =
59 "attribute highp vec4 position;\n"
61 " gl_Position = position;\n"
64 const GLchar *fragmentShader =
66 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
69 program = glCreateProgram();
70 GLuint vertShader = compileShader(GL_VERTEX_SHADER, vertexShader);
71 GLuint fragShader = compileShader(GL_FRAGMENT_SHADER, fragmentShader);
73 glAttachShader(program, vertShader);
74 glAttachShader(program, fragShader);
76 glLinkProgram(program);
78 glDeleteShader(vertShader);
79 glDeleteShader(fragShader);
81 if (vertexBuffer == 0) {
82 const GLfloat vertices[] = {
87 glGenBuffers(1, &vertexBuffer);
88 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
89 glBufferData(GL_ARRAY_BUFFER,
sizeof(vertices), vertices, GL_STATIC_DRAW);
92 glClearColor(0.4f, 0.0f, 0.6f, 1.0f);
93 glClear(GL_COLOR_BUFFER_BIT);
95 glUseProgram(program);
96 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
98 glEnableVertexAttribArray(0);
99 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
100 glDrawArrays(GL_TRIANGLES, 0, 3);