#include <android_native_app_glue.h>
#include "esUtil.hpp"
struct UserData
{
GLuint id;
};
bool init(ESContext*);
void draw(ESContext*);
void shutdown(ESContext*);
int esMain(ESContext * esContext)
{
esContext->userData = new UserData;
esCreateWindow ( esContext, "", 1080, 2160, ES_WINDOW_RGB );
esRegisterShutdownFunc ( esContext, shutdown );
esRegisterDrawFunc ( esContext, draw );
if ( !init ( esContext ) )
{
return 0;
}
return 1;
}
bool init(ESContext * esContext)
{
UserData * ud = (UserData*)esContext->userData;
char vStr[] =
"#version 300 es\n"
"layout(location=0)in vec3 pos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(pos.x,pos.y,pos.z,1.0);\n"
"}\n";
char fStr[] =
"#version 300 es\n"
"out vec4 color;\n"
"void main()\n"
"{\n"
" color = vec4(1.0,1.0,1.0,1.0);\n"
"}\n";
ud->id = esLoadProgram(vStr,fStr);
if(ud->id == 0)
return false;
return true;
}
void draw(ESContext * esContext)
{
UserData * ud = (UserData*)esContext->userData;
GLfloat ver[] =
{
0.0,0.5,0.0,
-0.5,-0.5,0.0,
0.5,-0.5,0.,
};
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport ( 0, 0, esContext->width, esContext->height );
glUseProgram ( ud->id );
glEnableVertexAttribArray ( 0 );
glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, ver );
glDrawArrays ( GL_TRIANGLES, 0, 3 );
glDisableVertexAttribArray ( 0 );
}
void shutdown(ESContext * esContext)
{
UserData * ud = (UserData*)esContext->userData;
glDeleteProgram ( ud->id );
}