当前位置: 首页>>代码示例>>C++>>正文


C++ Activity::getApplicationContext方法代码示例

本文整理汇总了C++中Activity::getApplicationContext方法的典型用法代码示例。如果您正苦于以下问题:C++ Activity::getApplicationContext方法的具体用法?C++ Activity::getApplicationContext怎么用?C++ Activity::getApplicationContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Activity的用法示例。


在下文中一共展示了Activity::getApplicationContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LoadBitmaps

void LoadBitmaps(JavaVM* vm, JNIEnv* env, jobject objActivity)
{
	vm->AttachCurrentThread(&env, NULL);

	BitmapFactory::Options options = BitmapFactory::Options();
	options.set_inScaled(false); // No pre-scaling
	Activity activity = Activity(objActivity);
	Context context = activity.getApplicationContext();
	AssetManager assetManager = context.getAssets();

	String path = String("");
	std::vector<std::string> files = assetManager.list(path);
	for (int index = 0; index < files.size(); ++index)
	{
		__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, files[index].c_str());
	}

	glGenTextures(TEXTURE_COUNT, &textures[0]);

	int textureId = 0;
	g_controller = LoadTexture(env, assetManager, options, "controller.png", textureId);
	g_buttonA = LoadTexture(env, assetManager, options, "a.png", ++textureId);
	g_dpadDown = LoadTexture(env, assetManager, options, "dpad_down.png", ++textureId);
	g_dpadLeft = LoadTexture(env, assetManager, options, "dpad_left.png", ++textureId);
	g_dpadRight = LoadTexture(env, assetManager, options, "dpad_right.png", ++textureId);
	g_dpadUp = LoadTexture(env, assetManager, options, "dpad_up.png", ++textureId);
	g_leftBumper = LoadTexture(env, assetManager, options, "lb.png", ++textureId);
	g_leftTrigger = LoadTexture(env, assetManager, options, "lt.png", ++textureId);
	g_leftStickInactive = LoadTexture(env, assetManager, options, "l_stick.png", ++textureId);
	g_buttonO = LoadTexture(env, assetManager, options, "o.png", ++textureId);
	g_rightBumper = LoadTexture(env, assetManager, options, "rb.png", ++textureId);
	g_rightTrigger = LoadTexture(env, assetManager, options, "rt.png", ++textureId);
	g_rightStickInactive = LoadTexture(env, assetManager, options, "r_stick.png", ++textureId);
	g_leftStickActive = LoadTexture(env, assetManager, options, "thumbl.png", ++textureId);
	g_rightStickActive = LoadTexture(env, assetManager, options, "thumbr.png", ++textureId);
	g_buttonU = LoadTexture(env, assetManager, options, "u.png", ++textureId);
	g_buttonY = LoadTexture(env, assetManager, options, "y.png", ++textureId);

	__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "Loaded %d textures", textureId + 1);
}
开发者ID:davidting,项目名称:ouya-sdk-examples,代码行数:40,代码来源:main.cpp

示例2: engine_init_display

/**
 * Initialize an EGL context for the current display.
 */
static int engine_init_display(struct engine* engine) {
    // initialize OpenGL ES and EGL
	if (JNI_ERR == RegisterClasses(engine->app->activity))
	{
		return JNI_ERR;
	}

	g_model = Build::MODEL();

	{
		Activity activity = Activity(engine->app->activity->clazz);
		Context context = activity.getApplicationContext();
		AssetManager assetManager = context.getAssets();

		InputStream inputStream = assetManager.open("input.json", AssetManager::ACCESS_BUFFER());
		int length = inputStream.available();
		jbyte* configurationBytes = new jbyte[length];
		inputStream.read(configurationBytes, length);
		String json = String(configurationBytes, length);
		std::string strJson = json.ToString();
		inputStream.close();
		delete configurationBytes;

		g_parser.parse(strJson);
	}

    /*
     * 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
     */
    const EGLint attribs[] = {
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
            EGL_BLUE_SIZE, 8,
            EGL_GREEN_SIZE, 8,
            EGL_RED_SIZE, 8,
            EGL_NONE
    };
    EGLint w, h, dummy, format;
    EGLint numConfigs;
    EGLConfig config;
    EGLSurface surface;
    EGLContext context;

    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

    eglInitialize(display, 0, 0);

    /* 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 */
    eglChooseConfig(display, attribs, &config, 1, &numConfigs);

    /* 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. */
    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);

    ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);

    surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
    context = eglCreateContext(display, config, NULL, NULL);

    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;

    // Initialize GL state.
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
    glEnable(GL_CULL_FACE);
	glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);
    glDisable(GL_DEPTH_TEST);

	LoadBitmaps(engine->app->activity->vm, engine->app->activity->env, engine->app->activity->clazz);

	glGenBuffers(3, g_vbo);
	glBindBuffer(GL_ARRAY_BUFFER, g_vbo[0]);
	glBufferData(GL_ARRAY_BUFFER, 4 * 12, g_positions, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, g_vbo[1]);
	glBufferData(GL_ARRAY_BUFFER, 4 * 8, g_textureCoords, GL_STATIC_DRAW);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_vbo[2]);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2 * 4, g_indices, GL_STATIC_DRAW);
//.........这里部分代码省略.........
开发者ID:Gorf-,项目名称:ouya-sdk-examples,代码行数:101,代码来源:main.cpp


注:本文中的Activity::getApplicationContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。