OpenGL shader: don't interpolate color

glsl, graphics, opengl

Solution

There are two options, which you choose will depend more on what you are doing.

First, you could simply make the colour constant for each vertex of your polygon when giving it to OpenGL.

Second, you can also mark a variable as `flat`:

flat in vec4 color;

and it will get its color from the provoking vertex. See this man page.

Problem

I'm trying out a really basic OpenGL example: rendering a single triangle. The triangle has three points and three different colors. Now OpenGL blends those colors together to create a gradient-like effect. I want to turn this off but I can't figure out how to do this. This is my fragment shader, it's really basic: ``` #version 150 in vec4 color; out vec4 outColor; void main() { outColor = color; } ```

Original source