[cairo] how could I use render with opengles correct?

Jihe Wei jihe.wei at gmail.com
Fri Jun 15 01:56:25 PDT 2012


Hi,
my code, as below
*cplus in ndk*
static void draw_frame(int textureid) {
    EGLint err;
    EGLDisplay display = eglGetCurrentDisplay();
    EGLContext context = eglGetCurrentContext();
    EGLSurface egl_surface = eglGetCurrentSurface(EGL_DRAW);
    cairo_device_t * device = cairo_egl_device_create(display, context);
    cairo_status_t status = cairo_device_status(device);
    if (status == CAIRO_STATUS_SUCCESS)//return success
        LOGE("cairo_device_status success");
    cairo_surface_t *surface = NULL;
    surface=cairo_gl_surface_create_for_texture(device,
CAIRO_CONTENT_COLOR_ALPHA,textureid ,256,
            256); //return CAIRO_SURFACE_TYPE_GL type

    //..,draw...

    /* Clean up. */
    cairo_destroy(cr);
    cairo_surface_destroy(surface);

    eglMakeCurrent(display, egl_surface, egl_surface, context);
}
*java in androd*
    private static native void drawFrame(int textureid);

    public static int loadTexture(final Context context, final int
resourceId) {
        final int[] textureHandle = new int[1];
        GLES20.glGenTextures(1, textureHandle, 0);
        if (textureHandle[0] != 0) {
            // Bind to the texture in OpenGL
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
            // Set filtering
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                    GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                    GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
            GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA,
256,
                    256, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
            drawFrame(textureHandle[0]);
        }
        if (textureHandle[0] == 0) {
            throw new RuntimeException("Error loading texture.");
        }
        return textureHandle[0];
    }

i verify it in two devices, HTC G12 and G17(evo 3d):
G12 could display something, but in an unregular way, G17 display nothing.

Thanks,
Wei


2012/6/5 Jihe Wei <jihe.wei at gmail.com>

> We tried display an texture that created by
> cairo_gl_surface_create_for_texture,
> 1. init an gl_surface with parameter textureid and draw something on it.
>     actually, must create an eglsurface, even not need eglsurface.
>     But after finish draw,must call eglMakeCurrent method.
> 2. return the textureid
> 3. use the textureid to create an texture and display it.
>     But can't identify what's it, except an image with unregular color.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20120615/cdeebee3/attachment.htm>


More information about the cairo mailing list