Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

weird line pattern when rendering big images

i’m trying to render a font, but when i’m rendering it small relative to the texture (the texture is 2048×2048 one channel, but it’s a full bitmap, so every character is small in the image) it creates a weird squares/lines pattern.

enter image description here

(the texture is blurry because it’s sdf, but i’ve used a normal shader for debugging)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

vertex shader: very visible on the ‘e’ and ‘p’

#version 330 core
in vec4 vertex;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

out vec2 TexCoord;

void main()
{
    gl_Position = projection * view * model * vec4(vertex.xy, 0.0, 1.0);
    TexCoord = vertex.zw;
}

fragment shader:

#version 330 core
out vec4 FragColor;

in vec2 TexCoord;

uniform sampler2D ourTexture;

void main()
{
    FragColor = vec4(1.0, 1.0, 1.0, texture(ourTexture, TexCoord).r);
}

texture code:

int width, height, nrChannels;
    unsigned char *img_data = stbi_load(image, &width, &height, &nrChannels, 1);

    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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glBindTexture(GL_TEXTURE_2D, font->texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, img_data);
    glGenerateMipmap(GL_TEXTURE_2D);

(yes, the image only has one channel)

that effect is very anoying and doesn’t seem to go away.
it persists even when GL_TEXTURE_MIN_FILTER is set to GL_LINEAR

>Solution :

glTexParameteri sets a parameter of the currently bound texture. Therefore you have to call glTexParameteri after glBindTexture. e.g.:

glBindTexture(GL_TEXTURE_2D, font->texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading