Black texture

Tagged: , ,

This topic contains 4 replies, has 2 voices, and was last updated by  Joe Davis 4 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #31514

    petrs
    Member

    Hi, i have a simple app displaying 3d model of a building with one texture, on galaxy note and my pc it’s displayed correctly but on galaxy tab 3 10.1 texture is just black…
    fragment shader:


    varying vec2 texCoord;
    uniform sampler2D texture;
    void main (void)
    {
    gl_FragColor = texture2D(texture, texCoord);
    }

    texture setup:


    GLuint createTexture(unsigned int* data, int w, int h)
    {
    GLuint t;
    glGenTextures(1, &t);
    glBindTexture(GL_TEXTURE_2D, t);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
    glBindTexture(GL_TEXTURE_2D, 0);
    return t;
    }

    tracer doesn’t show any error + texture is there:

    galaxy note :

    vs
    galaxy tab 3 :

    #38118

    Joe Davis
    Member

    Hi,

    Can you try using the following shader instead?

    varying mediump vec2 texCoord;
    uniform sampler2D texture;
    void main (void)
    {
    gl_FragColor.rgb = texture2D(texture, texCoord).rgb;
    gl_FragColor.a = 1.0;
    }

    Even if your application doesn’t use the alpha channel, the compositor on the device may interpret a non-1.0 value to mean that pixel in the surface should be blended out (hence the black).

    Regards,
    Joe

    #38119

    petrs
    Member

    Hi Joe, thanks for the answer but this is not the case same result as before, I’m completely certain texture2D is the problem (always returns vec4(0, 0, 0, ?)) to prove this here’s simple shading shader

    fragment:


    precision highp float;
    varying vec4 color;
    varying vec2 texCoord;
    uniform sampler2D texture;

    bool iskeycolor(vec4 c)
    {
    return c.r > 0.6 && c.g 0.6;
    }

    void main (void)
    {
    vec4 tc = texture2D(texture, texCoord);
    if(iskeycolor(tc))
    discard;
    gl_FragColor = vec4(tc.rg, 1.0, 1.0) * color;
    }

    vertex:


    uniform mat4 MVP;
    attribute vec4 vbo_Vertex;
    attribute vec3 vbo_Normal;
    attribute vec2 vbo_TexCoord;
    varying vec2 texCoord;
    varying vec4 color;

    void main(void)
    {
    float d = min(max(dot(vbo_Normal, vec3(1.0, 1.0, 1.0)), 0.5), 1.0);
    color = vec4(d, d, d, 1.0);
    texCoord = vbo_TexCoord;
    gl_Position = MVP * vbo_Vertex;
    }

    results in:

    as you can see there’s no component other than blue…

    Maybe it’s caused by x86 architecture??
    here’s the code for jpeg loading but I think it’s ok because I could see the texture data in tracer


    static unsigned int make8888(int red, int green, int blue, int alpha)
    {
    return (unsigned int)(((alpha << 24) & 0xff000000) | ((blue << 16) & 0x00ff0000) | ((green << 8) & 0x0000ff00) | ( red & 0x000000ff));
    }

    unsigned int* readJPEG(const char* name, int& width, int& height)
    {
    FH* f = fsopen(name, "rb");
    if(!f)
    return NULL;
    int size = fssize(f);
    unsigned char* buffer = (unsigned char *)malloc(size);
    fsread(f, buffer, size);
    fsclose(f);

    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr error;
    cinfo.err = jpeg_std_error(&error);
    error.error_exit = JPEGError;
    jpeg_create_decompress(&cinfo);
    jpeg_mem_src(&cinfo, buffer, size);
    jpeg_read_header(&cinfo, true);
    jpeg_start_decompress(&cinfo);
    width = cinfo.output_width;
    height = cinfo.output_height;
    int rstride = width * cinfo.output_components;
    unsigned int* data = (unsigned int*)calloc(sizeof(unsigned int), width * height);
    unsigned int* res = data + (width * height) - width;
    JSAMPARRAY rbuffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, rstride, 1);
    while (cinfo.output_scanline < height)
    {
    jpeg_read_scanlines(&cinfo, rbuffer, 1);
    for(int i = 0, pi = 0; pi < width; i += 3, pi++)
    {
    //debug("rgb(%d, %d) : %d %d %d", pi, cinfo.output_scanline, rbuffer[0], rbuffer[0], rbuffer[0]);
    res[pi] = make8888(rbuffer[0]
    , rbuffer[0], rbuffer[0], 0xFF);
    }
    res -= width;
    }
    jpeg_finish_decompress(&cinfo);
    jpeg_destroy_decompress(&cinfo);
    free(buffer);
    return data;
    }

    regards, Petr

    #38120

    petrs
    Member

    Ok I found the problem… test above make think there might be a problem with sampler itself and ye it is…
    I binded uniform location instead of texture object so on other platforms it was just a luck because usually new texture index starts from 0 but on this powervr chip it starts from 70000


    glActiveTexture(GL_TEXTURE0 + 0);
    glBindTexture(GL_TEXTURE_2D, texUniform);

    correct:


    glActiveTexture(GL_TEXTURE0 + 0);
    glBindTexture(GL_TEXTURE_2D, texObject);
    #38121

    Joe Davis
    Member

    Glad to hear you’ve found the cause 🙂

    Joe

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.