u/muehsam

▲ 6 r/opengl

Can't use ivec2 for vertex position

I have the following vertex shader to draw things in window coordinates:

#version 330 core

layout(location = 0) in vec2 pos;

uniform ivec2 window_size;

void main() {
    float x = float(pos.x) / window_size.x * 2.0 - 1.0;
    float y = float(pos.y) / window_size.y * -2.0 + 1.0;
    gl_Position = vec4(x, y, 0.0, 1.0);
}

It works fine. However, when I change the type of pos from vec2 to ivec2, it misbehaves. The vertex coordinates are defined as GLint anyway, so I'm a bit confused that I need to use them as floating point in the shader. It isn't a problem (the shader needs to convert them to float anyway), but I would still like an explanation why it doesn't work. It seems like I've misunderstood something.

reddit.com
u/muehsam — 4 days ago