OpenGL vertex color interpolation from center (how to?) -


here's image show mean:

enter image description here

i've assigned blue top, , red bottom.

how make entire top half blue, start interpolating bottom?

there's 2 solutions.

either render blue rectangle top half, , blue-->red rectangle bottom half:

float vertices[] {     -1,  0,  0,  0,  0,  1,      1,  0,  0,  0,  0,  1,      1,  1,  0,  0,  0,  1,     -1,  1,  0,  0,  0,  1,     -1, -1,  0,  1,  0,  0,      1, -1,  0,  1,  0,  0,      1,  0,  0,  0,  0,  1,     -1,  0,  0,  0,  0,  1 }; 

or write fragment shader manually interpolation you.

#version 450  //we're assuming these normalized [0,1]. in vec2 texturecoord;  out vec4 color;  void main() {     if(texturecoord.y >= 0.5)          color = vec4(0, 0, 1, 1);     else {         float factor = 1 - (texturecoord.y * 2);         color = vec4(1, 0, 0, 1) * factor + vec4(0, 0, 1, 1) * (1 - factor);     } } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -