.x)/engine->width, engine->state.angle,
? ? ? ? ? ? ((float)engine->state.y)/engine->height, 1);
? ? glClear(GL_COLOR_BUFFER_BIT);
? ? glEnableClientState(GL_VERTEX_ARRAY);
? ? if(g_arVertex.size() >= 2)
? ? {
? ? ? ? glColor4f(1,1,1,1);
? ? ? ? glVertexPointer(3,GL_FLOAT,0,&g_arVertex[0]);
? ? ? ? glDrawArrays(GL_LINE_STRIP,0,g_arVertex.size());
? ? }
? ? eglSwapBuffers(engine->display, engine->surface);
}
/**
?* Tear down the EGL context currently associated with the display.
?*/
static void engine_term_display(struct engine* engine) {
? ? if (engine->display != EGL_NO_DISPLAY) {
? ? ? ? eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
? ? ? ? if (engine->context != EGL_NO_CONTEXT) {
? ? ? ? ? ? eglDestroyContext(engine->display, engine->context);
? ? ? ? }
? ? ? ? if (engine->surface != EGL_NO_SURFACE) {
? ? ? ? ? ? eglDestroySurface(engine->display, engine->surface);
? ? ? ? }
? ? ? ? eglTerminate(engine->display);
? ? }
? ? engine->animating = 0;
? ? engine->display = EGL_NO_DISPLAY;
? ? engine->context = EGL_NO_CONTEXT;
? ? engine->surface = EGL_NO_SURFACE;
}
/**
?* Process the next input event.
?*/
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
{
? ? struct engine* engine = (struct engine*)app->userData;
? ? int32_t? ? evtType? ? =? ? AInputEvent_getType(event);
? ? switch(evtType)
? ? {
? ? case AINPUT_EVENT_TYPE_KEY:
? ? ? ? break;
? ? case AINPUT_EVENT_TYPE_MOTION:
? ? ? ? {
? ? ? ? ? ? switch(AInputEvent_getSource(event))
? ? ? ? ? ? {
? ? ? ? ? ? case AINPUT_SOURCE_TOUCHSCREEN:
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int32_t id = AMotionEvent_getAction(event);
? ? ? ? ? ? ? ? ? ? switch(id)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? case AMOTION_EVENT_ACTION_MOVE:
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? size_t? ? cnt = AMotionEvent_getPointerCount(event);
? ? ? ? ? ? ? ? ? ? ? ? ? ? for( int i = 0 ;i < cnt; ++ i )
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? float x = AMotionEvent_getX(event,i);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? float y = AMotionEvent_getY(event,i);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? char? szBuf[64];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? LOGI("x = %f? y = %f",x,y);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? float3 pt;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pt.x = x;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pt.y = y;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pt.z = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? g_arVertex.push_back(pt);
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case AMOTION_EVENT_ACTION_DOWN:
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? float x = AMotionEvent_getX(event,0);
? ? ? ? ? ? ? ? ? ? ? ? ? ? float y = AMotionEvent_getY(event,0);
? ? ? ? ? ? ? ? ? ? ? ? ? ? char? szBuf[64];
? ? ? ? ? ? ? ? ? ? ? ? ? ? LOGI("x = %f? y = %f",x,y);
? ? ? ? ? ? ? ? ? ? ? ? ? ? float3 pt;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pt.x = x;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pt.y = y;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pt.z = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? g_arVertex.push_back(pt);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case AMOTION_EVENT_ACTION_UP:
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case AINPUT_SOURCE_TRACKBALL:
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? break;
? ? }
? ? if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
? ? {
? ? ? ? engine->animating = 1;
? ? ? ? engine->state.x = AMotionEvent_getX(event, 0);
? ? ? ? engine->state.y = AMotionEvent_getY(event, 0);
? ? ? ? return 1;
? ? }
? ? return 0;
}
/**
?* Process the next main command.
?*/
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
? ? struct engine* engine = (struct engine*)app->userData;
? ? switch (cmd) {
? ? ? ? case APP_CMD_SAVE_STATE:
? ? ? ? ? ? break;
? ? ? ? case APP_CMD_INIT_WINDOW:
? ? ? ? ? ? // The window is being shown, get it ready.
? ? ? ? ? ? if (engine->app->window != NULL) {
? ? ? ? ? ? ? ? engine