refactor app and enable gles 3.0
This commit is contained in:
@@ -22,15 +22,8 @@
|
||||
#include <errno.h>
|
||||
#include <cassert>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl3.h>
|
||||
|
||||
#include <android/sensor.h>
|
||||
#include <android/log.h>
|
||||
#include <android_native_app_glue.h>
|
||||
|
||||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))
|
||||
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__))
|
||||
#include "pch.h"
|
||||
#include "app.h"
|
||||
|
||||
/**
|
||||
* Our saved state data.
|
||||
@@ -60,6 +53,8 @@ struct engine {
|
||||
struct saved_state state;
|
||||
};
|
||||
|
||||
Plane plane;
|
||||
|
||||
/**
|
||||
* Initialize an EGL context for the current display.
|
||||
*/
|
||||
@@ -120,10 +115,16 @@ static int engine_init_display(struct engine* engine) {
|
||||
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
|
||||
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
|
||||
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
|
||||
context = eglCreateContext(display, config, NULL, NULL);
|
||||
|
||||
const EGLint attribs_test[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs_test);
|
||||
|
||||
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
|
||||
LOGW("Unable to eglMakeCurrent");
|
||||
LOG("Unable to eglMakeCurrent");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -141,13 +142,23 @@ static int engine_init_display(struct engine* engine) {
|
||||
auto opengl_info = {GL_VENDOR, GL_RENDERER, GL_VERSION, GL_EXTENSIONS};
|
||||
for (auto name : opengl_info) {
|
||||
auto info = glGetString(name);
|
||||
LOGI("OpenGL Info: %s", info);
|
||||
LOG("OpenGL Info: %s", info);
|
||||
}
|
||||
// Initialize GL state.
|
||||
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
//glShadeModel(GL_SMOOTH);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
//glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
App::I.width = w;
|
||||
App::I.height = h;
|
||||
App::I.initShaders();
|
||||
|
||||
if (!plane.create<1>(1,1))
|
||||
LOG("Failed to create the plane mesh");
|
||||
|
||||
LOG("All ready");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -166,6 +177,13 @@ static void engine_draw_frame(struct engine* engine) {
|
||||
((float)engine->state.y)/engine->height, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glm::mat4 mvp = glm::ortho<float>(-1, 1, -1, 1, -1, 1);
|
||||
//App::I.update(now - _prevTime);
|
||||
ShaderManager::use(kShader::Color);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(1, 0, 0, 1));
|
||||
plane.draw_fill();
|
||||
|
||||
eglSwapBuffers(engine->display, engine->surface);
|
||||
}
|
||||
|
||||
@@ -283,6 +301,8 @@ void android_main(struct android_app* state) {
|
||||
engine.state = *(struct saved_state*)state->savedState;
|
||||
}
|
||||
|
||||
//App::I.create();
|
||||
|
||||
// loop waiting for stuff to do.
|
||||
|
||||
while (1) {
|
||||
@@ -308,9 +328,9 @@ void android_main(struct android_app* state) {
|
||||
ASensorEvent event;
|
||||
while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
|
||||
&event, 1) > 0) {
|
||||
LOGI("accelerometer: x=%f y=%f z=%f",
|
||||
event.acceleration.x, event.acceleration.y,
|
||||
event.acceleration.z);
|
||||
// LOGI("accelerometer: x=%f y=%f z=%f",
|
||||
// event.acceleration.x, event.acceleration.y,
|
||||
// event.acceleration.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user