Hi all.

I'm trying to use EGLImage on Android NDK.
I wrote a simple test code. but it doesn't work.
Somebody teach me what's wrong with my code????

They have EGL_KHR_gl_texture_2D_image and GL_OES_EGL_image extention.

Result on GalaxyS(SGX)
D/libEGL ( 8580): loaded /system/lib/egl/libEGL_POWERVR_SGX540_120.so
D/libEGL ( 8580): loaded /system/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
D/libEGL ( 8580): loaded /system/lib/egl/libGLESv2_POWERVR_SGX540_120.so
D/EGLT( 8580): EGLImageTest: glGenTextures: Good 100271!!
D/EGLT( 8580): EGLImageTest: eglCreateImageKHR: Good!!
D/EGLT( 8580): EGLImageTest: EGLImageTargetRenderbufferStorageOES: Bad!! 0502
D/EGLT( 8580): EGLImageTest: EGLImageTargetTexture2DOES: Good!!

Result on LT-NA75W(Tegra2)
D/libEGL (1138: loaded /system/lib/egl/libGLES_android.so
D/libEGL (1138: loaded /system/lib/egl/libEGL_tegra.so
D/libEGL (1138: loaded /system/lib/egl/libGLESv1_CM_tegra.so
D/libEGL (10590): loaded /system/lib/egl/libGLESv2_tegra.so
D/EGLT(10590): EGLImageTest: glGenTextures: Good 1!!
D/EGLT(10590): EGLImageTest: eglCreateImageKHR: Bad!!
D/EGLT(10590): EGLImageTest eglCreateImageKHR: EGL_BAD_PARAMETER
D/EGLT(10590): EGLImageTest: EGLImageTargetRenderbufferStorageOES: Bad!! 0501
D/EGLT(10590): EGLImageTest: EGLImageTargetTexture2DOES: Bad!! 0502


Code :
	{
		EGLImageKHR eimg;
		GLuint texid,fbo;
		GLint error;
		EGLint attr[] = { EGL_GL_TEXTURE_LEVEL_KHR, 0, EGL_NONE};
 
		glGenTextures(1,&texid);
		if( texid != 0 )
		{
			printf("EGLImageTest: glGenTextures: Good %d!!",texid); 
		}else{
			printf("EGLImageTest: glGenTextures: Bad %d!!",texid); 
		}
 
		glBindTexture(GL_TEXTURE_2D,texid);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 256,256, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );
		glBindTexture(GL_TEXTURE_2D,0);
		glFinish();
		eimg = eglCreateImageKHR(g_eglDisplay, g_eglMainContext, EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)texid, attr);
		if( eimg != NULL )
		{
			printf("EGLImageTest: eglCreateImageKHR: Good!!"); 
		}else{
			printf("EGLImageTest: eglCreateImageKHR: Bad!!");
			EGLint egl_error = eglGetError();
			switch(egl_error)
			{
			case EGL_NOT_INITIALIZED:
				printf("EGLImageTest eglCreateImageKHR: EGL_NOT_INITIALIZED\n");
				break;
			case EGL_BAD_ACCESS:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_ACCESS");
				break;
			case EGL_BAD_ALLOC:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_ALLOC\n");
				break;
			case EGL_BAD_CONFIG:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_CONFIG\n");
				break;
			case EGL_BAD_CONTEXT:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_CONTEXT\n");
				break;
			case EGL_BAD_CURRENT_SURFACE:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_CURRENT_SURFACE\n");
				break;
			case EGL_BAD_DISPLAY:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_DISPLAY\n");
				break;
			case EGL_BAD_MATCH:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_MATCH ");
				break;
			case EGL_BAD_NATIVE_PIXMAP:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_NATIVE_PIXMAP\n");
				break;
			case EGL_BAD_NATIVE_WINDOW:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_NATIVE_WINDOW\n");
				break;
			case EGL_BAD_PARAMETER:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_PARAMETER\n");
				break;
			case EGL_BAD_SURFACE:
				printf("EGLImageTest eglCreateImageKHR: EGL_BAD_SURFACE\n");
				break;
			case EGL_CONTEXT_LOST:
				printf("EGLImageTest eglCreateImageKHR: EGL_CONTEXT_LOST\n");
				break;
			default :
				printf("EGLImageTest eglCreateImageKHR: Unknown %04X\n",egl_error);
				break;
			}
		}
 
		error = glGetError();
 
		// Target for FBO
		glGenFramebuffersOES(1,&fbo);
		glBindFramebufferOES(GL_FRAMEBUFFER_OES,fbo);
		glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER_OES, eimg);
		error = glGetError();
		if( error != GL_NO_ERROR )
		{
			printf("EGLImageTest: EGLImageTargetRenderbufferStorageOES: Bad!! %04X",error);
		}else{
			printf("EGLImageTest: EGLImageTargetRenderbufferStorageOES: Good!!");
		}
		glBindFramebufferOES(GL_FRAMEBUFFER_OES,0);
 
		// Target for Texture
		glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,eimg);
		error = glGetError();
		if( error != GL_NO_ERROR )
		{
			printf("EGLImageTest: EGLImageTargetTexture2DOES: Bad!! %04X",error);
		}else{
			printf("EGLImageTest: EGLImageTargetTexture2DOES: Good!!");
		}
 
	}