Hi,<br>my code, as below<br><font size="4"><b>cplus in ndk</b></font><br>static void draw_frame(int textureid) {<br> EGLint err;<br> EGLDisplay display = eglGetCurrentDisplay();<br> EGLContext context = eglGetCurrentContext(); <br>
EGLSurface egl_surface = eglGetCurrentSurface(EGL_DRAW);<br> cairo_device_t * device = cairo_egl_device_create(display, context); <br> cairo_status_t status = cairo_device_status(device); <br> if (status == CAIRO_STATUS_SUCCESS)//return success<br>
LOGE("cairo_device_status success");<br> cairo_surface_t *surface = NULL;<br> surface=cairo_gl_surface_create_for_texture(device, CAIRO_CONTENT_COLOR_ALPHA,textureid ,256,<br> 256); //return CAIRO_SURFACE_TYPE_GL type<br>
<br> //..,draw... <br><br> /* Clean up. */<br> cairo_destroy(cr);<br> cairo_surface_destroy(surface);<br><br> eglMakeCurrent(display, egl_surface, egl_surface, context);<br>}<br><font size="4"><b>java in androd</b></font><br>
private static native void drawFrame(int textureid);<br><br> public static int loadTexture(final Context context, final int resourceId) {<br> final int[] textureHandle = new int[1];<br> GLES20.glGenTextures(1, textureHandle, 0);<br>
if (textureHandle[0] != 0) {<br> // Bind to the texture in OpenGL<br> GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);<br> // Set filtering<br> GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,<br>
GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);<br> GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,<br> GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);<br> GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256,<br>
256, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);<br> drawFrame(textureHandle[0]);<br> }<br> if (textureHandle[0] == 0) {<br> throw new RuntimeException("Error loading texture.");<br>
}<br> return textureHandle[0];<br> } <br><br>i verify it in two devices, HTC G12 and G17(evo 3d):<br>G12 could display something, but in an unregular way, G17 display nothing.<br><br>Thanks,<br>Wei<br><br>
<br><div class="gmail_quote">2012/6/5 Jihe Wei <span dir="ltr"><<a href="mailto:jihe.wei@gmail.com" target="_blank">jihe.wei@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
We tried display an texture that created by cairo_gl_surface_create_for_texture,<br>1. init an gl_surface with parameter textureid and draw something on it.<br> actually, must create an eglsurface, even not need eglsurface.<br>
But after finish draw,must call eglMakeCurrent method.<br>2. return the textureid<br>3. use the textureid to create an texture and display it.<br> But can't identify what's it, except an image with unregular color.<div class="HOEnZb">
<div class="h5"><br></div></div></blockquote></div>