English 中文(简体)
如何在 Java FloorView 中创建本地窗口时, 从本地函数创建 EGL 环境?
原标题:How can I create an EGL context from a native function when the NativeWindowType is created in a Java SurfaceView?

我试图创建 EGL 环境以在本地功能调用中绘制 OpenglES 的所有内容。 问题在于我需要访问本地WindowType 实例, 但我只能找到一个函数来创建它( 我无法找到如何连接它 ) 。 然而, 即使我创建了一个函数, 我怀疑这是错误的, 因为我真正需要的就是由我称之为本地功能的地平面观察实例创建的函数 。

这是代码:

static int egl_init() {

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 egl_major_version, egl_minor_version;
EGLint numConfigs;
EGLConfig egl_config;
EGLSurface egl_surface;
EGLContext egl_context;

EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

// v--------- This is where I should get the display window
NativeWindowType display_window;
display_window = android_createDisplaySurface();

eglInitialize(egl_display, &egl_major_version, &egl_minor_version);
printf("GL Version: %d.%d
", egl_major_version, egl_minor_version);

if (!eglChooseConfig(egl_display, attribs, &egl_config, 1, &numConfigs))
{
  printf("eglChooseConfig failed
");
  if (egl_context == 0) printf("Error code: %x
", eglGetError());
}

eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &format);

// v---------- This requires that I link libandroid, it is found in android/native_window.h
ANativeWindow_setBuffersGeometry(display_window, 0, 0, format);

egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, NULL);
if (egl_context == 0) LOGE("Error code: %x
", eglGetError());

egl_surface = eglCreateWindowSurface(egl_display, egl_config, display_window, NULL);
if (egl_surface == 0) LOGE("Error code: %x
", eglGetError());

if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE) {
    LOGE("Unable to eglMakeCurrent");
    return -1;
}
return 0;
}

谢谢你的帮忙

问题回答

表面无法支持请求的egl配置( 红色、 绿色和蓝色至少为 8 比特 ) 。

const EGLint attribs[] = { 
                EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
                EGL_BLUE_SIZE, 8,
                EGL_GREEN_SIZE, 8,
                EGL_RED_SIZE, 8,
                EGL_NONE
};

有些电话 默认情况下所有表面缓冲器 RGB_565

In Java to get more detailed colors or alpha you can getWindow and setFormat(). Like so: getWindow().setFormat(PixelFormat.TRANSLUCENT); To do something equivalent in a native-activity you must do something like the following.

ANativeWindow_setBuffersGeometry(display_window, 0, 0, 1);

h 定义在和机器人/本地-窗口中。

/*
 * Pixel formats that a window can use.
 */
enum {
        WINDOW_FORMAT_RGBA_8888           = 1,
        WINDOW_FORMAT_RGBX_8888           = 2,
        WINDOW_FORMAT_RGB_565                   = 4,
};

希望这能帮上忙 我看到了这个问题,我刚想通了





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签