本文整理汇总了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);
}
示例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);
//.........这里部分代码省略.........