java - OpenGlES2.0 Texture issue -


i new opengl, trying apply texture 3d figure ,but getting glgetuniformlocation: glerror 1282 error,please me this, searched online couldn't rectify it.would happy if explains issue also.

my shaders:

private final string vertexshadercode =         "uniform mat4 umvpmatrix;" +                 "attribute vec4 vposition;" +                 "attribute vec2 texcoord;" +                 "varying vec2 texcoordout;" +                 "void main() {" +                 "  gl_position = umvpmatrix * vposition;" +                 "  texcoordout = texcoord;" +                 "}";  private final string fragmentshadercode =         "precision mediump float;" +                 "uniform vec4 texcolor"+                 "varying vec2 texcoordout;" +                 "uniform sampler2d texture;" +                 "void main() {" +                 " texcolor = texture2d(texture, texcoordout);" +                 "  gl_fragcolor = texcolor;" +                 "}"; 

draw method:

public void draw1(float[] mvpmatrix) {     // add program opengl environment     gles20.gluseprogram(mprogram);      // handle vertex shader's vposition member     mpositionhandle = gles20.glgetattriblocation(mprogram, "vposition");      mmvpmatrixhandle = gles20.glgetuniformlocation(mprogram, "umvpmatrix");     myglrenderer.checkglerror("glgetuniformlocation");      // apply projection , view transformation     gles20.gluniformmatrix4fv(mmvpmatrixhandle, 1, false, mvpmatrix, 0);     myglrenderer.checkglerror("gluniformmatrix4fv");      vstexturecoord = gles20.glgetattriblocation(mprogram, "texcoord");     fstexture = gles20.glgetuniformlocation(mprogram, "texture");     // enable handle triangle vertices     gles20.glenablevertexattribarray(mpositionhandle);      // prepare triangle coordinate data     gles20.glvertexattribpointer(             mpositionhandle, coords_per_vertex,             gles20.gl_float, false,             vertexstride, vertexbuffer);     gles20.glenablevertexattribarray(vstexturecoord);      gles20.glvertexattribpointer(vstexturecoord, coords_per_texture,             gles20.gl_float, false,             texturestride, texbuffer);      // handle shape's transformation matrix     gles20.glactivetexture(gles20.gl_texture0);     gles20.glbindtexture(gles20.gl_texture_2d, textures[0]);     gles20.gluniform1i(fstexture, 0);      // draw triangle     gles20.gldrawarrays(gles20.gl_triangles, 0, tablelamp21numverts);      // disable vertex array     gles20.gldisablevertexattribarray(mpositionhandle);     gles20.gldisablevertexattribarray(vstexturecoord);  } 

loadtexture:

public void loadgltexture(context context) {     gles20.glgentextures(4, textures, 0);     bitmap bitmap = null;     (int i=0;i<4;i++)     {         // create bitmap         bitmap = bitmapfactory.decoderesource(context.getresources(), resourceids[i]);         //...and bind our array         gles20.glbindtexture(gles20.gl_texture_2d, textures[i]);         //create nearest filtered texture         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.gltexparameterf(gles20.gl_texture_2d, gles20.gl_texture_wrap_s, gles20.gl_clamp_to_edge);         gles20.gltexparameterf(gles20.gl_texture_2d, gles20.gl_texture_wrap_t, gles20.gl_clamp_to_edge);         //use android glutils specify two-dimensional texture image our bitmap         glutils.teximage2d(gles20.gl_texture_2d, 0, bitmap, 0);         //clean         bitmap = null;     } } 

you shouldn't able compile shaders in first place.

in fragment shader, you've declared sampler2d variable texture, you're using u_texture sample it. use same variable name in both places, should same

private final string vertexshadercode =     "uniform mat4 umvpmatrix;" +             "attribute vec4 vposition;" +             "attribute vec2 texcoord;" +             "varying vec2 texcoordout;" +             "void main() {" +             "  gl_position = umvpmatrix * vposition;" +             "  texcoordout = texcoord;" +             "}";   private final string fragmentshadercode =     "precision mediump float;" +             "uniform vec4 texccolor"+             "varying vec2 texcoordout;" +             "uniform sampler2d u_texture;" +             "void main() {" +             " texcolor = texture2d(u_texture, texcoordout);" +             "  gl_fragcolor = texcolor;" +             "}"; 

and in gles code,

 fstexture = gles20.glgetuniformlocation(mprogram, "u_texture"); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -