Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asymmetric coloring of quads in opengl

Tags:

opengl

I need to color some points of a surface consisting of multiple quadrilaterals. The problem is that the color is not symmetric distributed around the point, see image where only the lower right corner of the left square is red while the red color seems to be pulled towards the right upper corner in the right square).

enter image description here

code:

glBegin (GL_QUAD_STRIP);
glVertex3f (1., 0., 0)
glVertex3f (1., 1., 0)
glColor3f(1, 0, 0)
glVertex3f (0., 0., 0)
glColor3f(0, 0, 1)
glVertex3f (0., 1., 0)
glVertex3f (-1., 0., 0)
glVertex3f (-1., 1., 0)
glEnd ();

If you make two individual quads and define one clockwise and the other counter clockwise then the color will be symmetric around the point, but different from the color distribution around adjacent points(if they are colored instead).

So how can I color arbitrary points with a symmetric color distribution?

EDIT:

I would like to visualize e.g. the temperature of the surface based on the temperature at each vertex, something like the image below (yellow=0, orange=0.5 and red=1):

enter image description here

like image 285
Mads M Pedersen Avatar asked Jan 28 '26 20:01

Mads M Pedersen


1 Answers

By default OpenGL uses a barycentric linear interpolation over each triangle. Which causes exactly what you see. The simplemost solution would be write a set of vertex and fragment shaders that implement a distance based gradient.

The details depend on your specific needs.

like image 117
datenwolf Avatar answered Jan 31 '26 20:01

datenwolf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!