opengl es 2.0 - GlTexImage2D is doing nothing -


i've been trying million of combinations pass texture shader without success. here code should add second texture on video (oes_external_texture). there no gl error (i've verified calls). external texture displayed (the video), other texture black in shader (0, 0, 0, 1f).

this how i'm initiating 'overlay' texture.

            _texs = new int[1];             gles20.glgentextures (1, _texs, 0);             _overlayid = _texs [0];              gles20.gltexparameteri(gles20.gltexture2d, gles20.gltextureminfilter,                 gles20.glnearest);             gles20.gltexparameteri(gles20.gltexture2d, gles20.gltexturemagfilter,                 gles20.gllinear);             gles20.gltexparameteri(gles20.gltexture2d, gles20.gltexturewraps,                 gles20.glclamptoedge);             gles20.gltexparameteri(gles20.gltexture2d, gles20.gltexturewrapt,                 gles20.glclamptoedge);              gles20.glbindtexture(gles20.gltexture2d, _overlayid);              gles20.glteximage2d (gles20.gltexture2d, 0, gles20.glrgb, textureside, textureside, 0, gles20.glrgb, gles20.glunsignedbyte, bytebuffer.wrap(pixels));             _overlayposition = gles20.glgetuniformlocation (_glprogram, "overlay");             gles20.gluniform1i (_overlayposition, _overlayid);              gles20.glbindtexture (gles20.gltexture2d, 0); 

and how i'm drawing:

            gles20.glbindtexture(gles20.gltexture2d, _overlayid);             _overlayposition = gles20.glgetuniformlocation (_glprogram, "overlay");             gles20.gluniform1i (_overlayposition, _overlayid);              gles20.glbindtexture(gl_texture_external_oes, _textureid    );             _trianglevertices.position (triangle_vertices_data_pos_offset);             gles20.glvertexattribpointer (_apositionhandle, 3, gles20.glfloat, false, triangle_vertices_data_stride_bytes, _trianglevertices);             gles20.glenablevertexattribarray (_apositionhandle);              _texturevertices.position (triangle_vertices_data_uv_offset);             gles20.glvertexattribpointer (_atexturecoord, 2, gles20.glfloat, false, texture_vertices_data_stride_bytes, _texturevertices);             gles20.glenablevertexattribarray (_atexturecoord);              android.opengl.matrix.setidentitym (_mvpmatrix, 0);             gles20.gluniformmatrix4fv (_umvpmatrixhandle, 1, false, _mvpmatrix, 0);             gles20.gluniformmatrix4fv (_ustmatrixhandle, 1, false, _stmatrix, 0);              gles20.gldrawarrays(gles20.gltrianglestrip, 0, 4); 

[edit]

finally got sampler2d texture work by:

(in texture initialization part) creating texture:

            _texs = new int[1];             gles20.glgentextures (1, _texs, 0);             _overlaytextureid = _texs [0]; 

getting uniform location:

            _overlaytextureuniform = gles20.glgetuniformlocation (_glprogram, "overlay"); 

these params needed, nothing more:

            gles20.gltexparameteri(gles20.gltexture2d, gles20.gltextureminfilter, gles20.glnearest);             gles20.gltexparameteri(gles20.gltexture2d, gles20.gltexturemagfilter, gles20.gllinear); 

creating texture bitmap:

            glutils.teximage2d (gles20.gltexture2d, 0, mybitmap, 0); 

setting texture in opengl context. helper.

            settexture2d (_overlaytextureunit, _overlaytextureid, _overlaytextureuniform);  

freeing bitmap:

            source.recycle (); 

=end of texture initialization=

here's code of helper:

       void settexture2d(int textureunit, int textureid, int uniformid) {             gles20.glactivetexture(gles20.gltexture0 + textureunit);             gles20.glbindtexture(gles20.gltexture2d, textureid);             gles20.gluniform1i(uniformid, textureunit);         } 

anything special code? no. former attempt well-coded? no. 2 things helped lot: 1. small helper above, used set oes , 2d textures in initialization , in ondrawframe. 2. debugging image passing glteximage2d method, happened black. changed pixels float int, , casting int before being done arithmetics, having either 0 or 255 values.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -