openglnoob
Posts: 3
Joined: Fri May 30, 2014 9:46 pm

Draw to a texture using OpenVG

Wed Jun 25, 2014 9:37 pm

I'm using both OpenGL and OpenVG on my application, and i'm using the VGFONT native implementation to draw texts.

Everything was wokring fine until now, cause i've been rendering directly on the screen, into a window surface. But now I need to draw a text into an OpenGL texture instead.

Since I can't use fbo's with OpenVG i thought that I could use the EGL pbuffers instead, since I'd be using only openVG and EGL. However I'm getting an EGL_BAD_MATCH error when I try to make the pbuffer the current surface.

The code uses two EGLContexts, one for the OpenGL part and one that is part of the VGFONT implementation. The same pbuffer needs to access both contexts. When i use window surfaces, this works perfectly, but I just can't get it working for the pbuffers.

I've modified the create_context method on VGFONT to use pbuffers like this:

Code: Select all

  attribs[n++] = EGL_RENDERABLE_TYPE; attribs[n++] = EGL_OPENVG_BIT;
   //attribs[n++] = EGL_SURFACE_TYPE;    attribs[n++] = EGL_WINDOW_BIT;
   attribs[n++] = EGL_SURFACE_TYPE;    attribs[n++] = EGL_PBUFFER_BIT;

   attribs[n] = EGL_NONE;*/
the EGLContext is created without errors.

The pbuffers are created successfully by

Code: Select all

EGLBoolean esCreatePbuffer(ESContext *esContext, EGLSurface *surface, int width, int height)
{
	/*static const EGLint attribListPbuffer[] =
	{
	    EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
	    EGL_RED_SIZE, 5,
	    EGL_GREEN_SIZE, 6,
	    EGL_BLUE_SIZE, 5,
	    EGL_ALPHA_SIZE, 0,
	    EGL_DEPTH_SIZE, 16,
	    EGL_STENCIL_SIZE, 0,
	    EGL_NONE
	};*/


	EGLint srfPbufferAttr[] =
	{
	    EGL_WIDTH, width,
	    EGL_HEIGHT, height,
	   // EGL_COLORSPACE, GL_RGB,
	   // EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
	   // EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
	    EGL_LARGEST_PBUFFER, EGL_TRUE,
	    EGL_NONE
	};


	    *surface = eglCreatePbufferSurface(esContext->eglDisplay,
	                        esContext->eglConfig,srfPbufferAttr);

	    if ( *surface == EGL_NO_SURFACE )
	  	   {
	    	_findEGLError2(574);
	  	   }

	    esMakeCurrent(esContext, *surface);
}
However the method gx_priv_save() on VGFONT fails when it calls eglMakeCurrent().

Does anyone know what I'm doing wrong, or have a better solution for drawing into an OpenGL texture using OpenVG?

User avatar
hanzelpeter
Posts: 75
Joined: Mon Jul 09, 2012 11:56 am

Re: Draw to a texture using OpenVG

Thu Aug 21, 2014 5:24 pm

Hello.

Looks I finally made it. Attached is source code and picture of rotating tiger on rotating 3d cube.
The trick was to use vgImage, eglCreateImageKHR and glEGLImageTargetTexture2DOES.
Attachments
tiger_on_cube.png
tiger_on_cube.png (38.55 KiB) Viewed 2370 times
vg_gles.tgz
(59.79 KiB) Downloaded 384 times

Return to “OpenVG”