Thanks for ur tip. And it is perfectly ok with me if I can use low level API.
But the problem is I am not able to find even the Low level APIs needed to
do this (or say morphing) thing in Real Time.
Here are the steps to get smooth blending:
I assume two triangles ABC and MNO. And the new Triangle is PQR.
And this whole thing is going on in 2D space. My questions are in
enclosed in << and >>
- I have used the linear Interpolation for calculating the vertices of new Triangle PQR.
Which is quite easy to do.
- Next we can either go by Backward Warping or Forward Warping.
I list the steps for Backward warping.
A. For every pixel in triangle PQR,
I calcualate the corresponding pixel coordinates in
triangles ABC and MNO, let the points be X(in triangle ABC ) and Y
( in triangle MNO).
(<<i.e. We have to use a triangle
filling algorithm, DOES openGL has
ANY triangle filling API which returns
the x,y coordinate pair of each
pixel in that triangle?>> )
B. I have used the baryo centric method for this calculation. It
is a calculation intensive method. But gives accurate result.
(<<Does openGL api has support of
baryo centric / any other method
by use of which I can calculate
the correspoindg point in other
triangle, if vertices are assumed
to be matched?>> )
C. For each such X and Y point, get the color at that point. Now X and Y ususally have
the coordinates in floating point values, So to get the color at these points means I have
to used some Interpolation, and I used the simplest possible, Bilinear interpolation.
Bilinear Interpolation :: Say I have a pt (10.3, 10.6). The color at this pt will
be dependent upon the color of point (10, 10) (10,11) (11,11) and (11,10).
Let Color(x,y) be a function which returns the color at point (x,y).
So the Color(10.3, 10.6) = ( 1 - 0.3 ) * ( 1 - 0.6 ) * Color(10,10) +
( 0.3 ) * (1 - 0.6) * Color(10,11) +
( 0.3 ) * ( 0.6 ) * Color(11,11) +
( 1 - 0.3 ) * ( 0.6 ) * Color(11,10)
(<< Does openGL support this method in LOW Level API or any similar method?>> )
D. In last step I mix the color of Point X and Y using linear interpolation.
i.e. if my triangle PQR is at distance 0.3 from triangle ABC and at 0.7 from triangle
MNO, then the color of each pixel in triangle PQR will be:
color(each Pixel in PQR) = [0.7 * color(X) * (Area of ABC) +
0.3 * color(Y) * (Area of MNO) ] /
(Area of ABC + Area of MNO);
– where both the color of X and Y are calculated using step C
– X and Y themselves are calcualted using step B.
– each pixel in PQR is calculated in step A.
All of the above steps are quite simple to code,
– when you have to do step A for each triangle,
– step B for each pixel in each triangle,
– step C for each point calculated in step B,
– and Point D for each pixel in each triangle,
for 1000 triangles, in real time (i.e. 16 frames
at least), computer (even the pentinum 500) simply
fails to cope up.
Any openGL API at any step will save time? Any ideas?
Originally posted by coco:
OpenGL can be seen as an interface between hardware graphics and your app. In fact, it’s quite low-level, and doesn’t support this kind of things directly.
cards such as the NVIDIA GeForce and ATi Radeon have multiple modelview matrix extensions, that can let you do such things in hardware, so check with them. Otherwise, do your own morphing before sending vertices to OpenGL (that’s the way most, if not all, games do today).