2

I'm writing a program with OpenTK in C# and I currently tried to get a texture on a group of cubes.

My problem is that when i use the given texture with 3 pixels in it and give the bitmap into my shader to a sampler2d it interpolates the colors of the texture while rendering instead of giving me 3 lines with the 3 colors on each side of each cube.

To give it into the shader i used the code similar to the one given on this side.

Here the exact code in my fragment shader:

#version 430 core

uniform sampler2D materialTexture;

in vec2 uvPos;

out vec4 color;

void main() 
{
    vec4 materialColor = texture2D(materialTexture, uvPos);
    color = materialColor;
}

Here the image used as texture shown in gimp: The 3 pixel texture

Here the current result The result after rendering

What would i have to do so the image would be rendered on the cubes without interpolating? Are there maybe any flags or calls in OpenTK i can set to prevent this?

M. Mettenleiter
  • 105
  • 1
  • 9

1 Answers1

4

You need to use nearest-neighbor filtering for the magnification function.

You have a 3x1 texture here, which needs to be magnified to stretch across your scene. The default magnification filter (GL_TEXTURE_MAG_FILTER) in OpenGL is GL_LINEAR, which interpolates the four closest texels.

GL_NEAREST will produce the behaivor you want. Minification (when your texture resolution is too high) does not apply here, but also defaults to linear filtering.

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • So... how do you use that filtering mode? Obviously, I know the answer to that, but my point is that the OP didn't even know what filtering modes were. So he probably doesn't know how to set them. – Nicol Bolas Aug 17 '16 at 17:25
  • @NicolBolas: Search me, the question is discussing a particular framework that obviously encapsulates texture loading. I opted only to explain the terms necessary to search for. – Andon M. Coleman Aug 17 '16 at 17:30