GreenJuiceTeam/GreenJuiceTeam.Android.NativeActivity/main.cpp
/**
* Initialize an EGL context for the current display.
*/
Initialize an EGL context for the current display.
Initialize an EGL context for the current display .
static int engine_init_display(struct engine* engine) {
	const EGLint attribs[] = {
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
		EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
		EGL_BLUE_SIZE, 8,
		EGL_GREEN_SIZE, 8,
		EGL_RED_SIZE, 8,
		EGL_ALPHA_SIZE, 8,
		EGL_DEPTH_SIZE, 8,
		EGL_STENCIL_SIZE, 8,
		EGL_NONE
	};
	EGLint w, h, format;
	EGLint numConfigs;
	EGLConfig config;
	EGLSurface surface;
	EGLContext context;
	EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	eglInitialize(display, 0, 0);
	eglChooseConfig(display, attribs, &config, 1, &numConfigs);
	eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
	ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);
	surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
	EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
	context = eglCreateContext(display, config, NULL, contextAttribs);
	if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
		LOGW("Unable to eglMakeCurrent");
		return -1;
	}
	eglQuerySurface(display, surface, EGL_WIDTH, &w);
	eglQuerySurface(display, surface, EGL_HEIGHT, &h);
	engine->display = display;
	engine->context = context;
	engine->surface = surface;
	engine->width = w;
	engine->height = h;
	engine->state.angle = 0;
	if (!engine->engine)
	{
		engine->engine.reset(new Engine());
		JNIEnv *jni;
		engine->app->activity->vm->AttachCurrentThread(&jni, NULL);
		engine->engine->init(800, 480);
		engine->app->activity->vm->DetachCurrentThread();
	}
	return 0;
}
static int engine_init_display ( struct engine * engine ) { const EGLint attribs [ ] = { EGL_RENDERABLE_TYPE , EGL_OPENGL_ES2_BIT , EGL_SURFACE_TYPE , EGL_WINDOW_BIT , EGL_BLUE_SIZE , 8 , EGL_GREEN_SIZE , 8 , EGL_RED_SIZE , 8 , EGL_ALPHA_SIZE , 8 , EGL_DEPTH_SIZE , 8 , EGL_STENCIL_SIZE , 8 , EGL_NONE } ; EGLint w , h , format ; EGLint numConfigs ; EGLConfig config ; EGLSurface surface ; EGLContext context ; EGLDisplay display = eglGetDisplay ( EGL_DEFAULT_DISPLAY ) ; eglInitialize ( display , 0 , 0 ) ; eglChooseConfig ( display , attribs , & config , 1 , & numConfigs ) ; eglGetConfigAttrib ( display , config , EGL_NATIVE_VISUAL_ID , & format ) ; ANativeWindow_setBuffersGeometry ( engine -> app -> window , 0 , 0 , format ) ; surface = eglCreateWindowSurface ( display , config , engine -> app -> window , NULL ) ; EGLint contextAttribs [ ] = { EGL_CONTEXT_CLIENT_VERSION , 2 , EGL_NONE } ; context = eglCreateContext ( display , config , NULL , contextAttribs ) ; if ( eglMakeCurrent ( display , surface , surface , context ) == EGL_FALSE ) { LOGW ( " " ) ; return -1 ; } eglQuerySurface ( display , surface , EGL_WIDTH , & w ) ; eglQuerySurface ( display , surface , EGL_HEIGHT , & h ) ; engine -> display = display ; engine -> context = context ; engine -> surface = surface ; engine -> width = w ; engine -> height = h ; engine -> state . angle = 0 ; if ( ! engine -> engine ) { engine -> engine . reset ( new Engine ( ) ) ; JNIEnv * jni ; engine -> app -> activity -> vm -> AttachCurrentThread ( & jni , NULL ) ; engine -> engine -> init ( 800 , 480 ) ; engine -> app -> activity -> vm -> DetachCurrentThread ( ) ; } return 0 ; }
Initialize an EGL context for the current display.
Initialize an EGL context for the current display .
// initialize OpenGL ES and EGL /*
	* Here specify the attributes of the desired configuration.
	* Below, we select an EGLConfig with at least 8 bits per color
	* component compatible with on-screen windows
	*/ /* Here, the application chooses the configuration it desires. In this
	* sample, we have a very simplified selection process, where we pick
	* the first EGLConfig that matches our criteria */ /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
	* guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
	* As soon as we picked a EGLConfig, we can safely reconfigure the
	* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ //engine->engine->init(w, h);