Hello everyone, this is the first time I have been here.
Just gotten into OpenGL around half a month, and it is definitely difficult on understanding some of the concepts, and definitely got lost in the buffer part, but I know learning OpenGL takes a lot time before I can do something useful while I want to create something with it, so I accept the challenge.
I am currently learning it using OpenGL SuperBible 7th edition, trying to port the C++ code into zig, but I have stuck at the “Simple Texture” part, not because I can’t reproduce the texture using a different language, but I don’t understand the texelFetch() function in the fragment shader, where I don’t seem to see even the official example use this function to draw the texture although the book say so.
I have followed a GitHub example, using texture() in the fragment shader:
#version 450 core
uniform sampler2D s;
out vec4 color;
void main(void)
{
color = color = texture(s, gl_FragCoord.xy / textureSize(s, 0));
}
Everything works as intended where the program generated, grid like texture is properly filled (left image). However, when I followed the book and replaced the texture function as the following:
color = texelFetch(s, ivec2(gl_FragCoord.xy), 0);
Considering the resolution and color of the texture, seems that only the texture at the bottom left are generated, but beyond a certain point, the function stops drawing the texture (right image):
I heard about the difference between texture and texelFetch is that the coordination is normalized for texelFetch(), not for the texture(), but why is that causing texelFetch() drawing part of the texture? Or did I misunderstood these two functions?
