i made a simple opengl program, it shows a big cube where you can move through by using the arrow keys. i’ve used my own matrices and i initialised opengl in the same way as the rasonly.c sample.
the problem is that opengl does clip the triangle when it leaves the screen left and right, but it doesn’t do this when the triangle becomes too near (z<1.0). i’ve solved this by using my own clipping code, everthing works well, except for the colors, they look a bit different after the triangle has been clipped.
the way i’m doing it now is this:
if A is the point that has a good z-value(z>1.0) and B and C are the points that are too near, then:
this calculates how much closer B has got towards A
f = (Az-Bz)/(1.0-Bz)
the difference between the colors of point A and B
r = (Ar - Br)
g = (Ag - Bg)
b = (Ab - Bb)
the new colors would be:
nr = Br + fr;
ng = Bg + fg;
nb = Bb + f*b;
is there anybody who knows what i’am doing wrong? if you like i could sent the .exe so that you can see how the colors are now.