Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Is 'texture mapping' possible on Painter?
Is 'texture mapping' possible on Painter? [message #52982] |
Tue, 28 January 2020 15:32  |
Tom1
Messages: 1301 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi,
I would like to 'texture map' an image in a shape of a sector or fan. Is this possible in Painter, like it is in OpenGL using a triangle fan?
(I.e. by defining the center, radius and starting and ending angles of a sector and then fill the area with an Image having its top edge touching the center point and its lower edge touching the arc defined by the radius, stretching out between the starting and ending angles.)
I would like to avoid using OpenGL in this project, partly because this is "just a simple" 2D mapping. However, rendering speed may be a factor here as the data is updated quite frequently.
Best regards,
Tom
|
|
|
Re: Is 'texture mapping' possible on Painter? [message #52995 is a reply to message #52982] |
Fri, 31 January 2020 17:30   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
Tom1 wrote on Tue, 28 January 2020 15:32Hi,
I would like to 'texture map' an image in a shape of a sector or fan. Is this possible in Painter, like it is in OpenGL using a triangle fan?
(I.e. by defining the center, radius and starting and ending angles of a sector and then fill the area with an Image having its top edge touching the center point and its lower edge touching the arc defined by the radius, stretching out between the starting and ending angles.)
I would like to avoid using OpenGL in this project, partly because this is "just a simple" 2D mapping. However, rendering speed may be a factor here as the data is updated quite frequently.
Best regards,
Tom
Now that is an interesting task... I think individual triagles are still affine transformations, so IMO should be possible to do this.
EDIT:
Well, not affine after all, but IMO neither this it possible in OpenGL with simple texture mapping. IMO you need to add some advanced non-affine shaders to do this 100% correctly... Probably easier to do without the fan at that point, just pixel shader that maps the texture.
Mirek
[Updated on: Fri, 31 January 2020 17:38] Report message to a moderator
|
|
|
|
|
Re: Is 'texture mapping' possible on Painter? [message #53005 is a reply to message #53004] |
Tue, 04 February 2020 13:28   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
#include <CtrlLib/CtrlLib.h>
#include <plugin/jpg/jpg.h>
using namespace Upp;
Xform2D MapTriangle(Pointf s1, Pointf s2, Pointf s3)
{ // maps 0,0 -> s3, 1,0 -> s1, 0,1 -> s2
Xform2D s;
s.x.x = s1.x - s3.x;
s.y.x = s1.y - s3.y;
s.x.y = s2.x - s3.x;
s.y.y = s2.y - s3.y;
s.t = s3;
return s;
}
Xform2D MapTriangles(Pointf s1, Pointf s2, Pointf s3, Pointf t1, Pointf t2, Pointf t3)
{
return Inverse(MapTriangle(s1, s2, s3)) * MapTriangle(t1, t2, t3);
}
struct MyApp : TopWindow {
Image img;
virtual void Paint(Draw& dw)
{
Size sz = GetSize();
DrawPainter w(dw, sz);
w.Co();
w.DrawRect(sz, White());
Pointf center = (Point)sz / 2;
double radius = 0.95 * min(center.x, center.y);
Size isz = img.GetSize();
int steps = 200;
for(double i = 0; i < steps; i++) {
Pointf q = Polar(i * M_2PI / steps);
Pointf p1 = radius * q + center;
Pointf p2 = radius * Polar((i + 1) * M_2PI / steps + 0.4 / steps) + center;
Xform2D m = Xform2D::Scale(Distance(p1, p2) * steps / isz.cx, radius / isz.cy);
m = m * Xform2D::Rotation(Bearing(p2 - p1));
Pointf h = p1 - i * isz.cx / steps * Orthogonal(q);
m = m * Xform2D::Translation(h.x, h.y);
double x1 = i * isz.cx / steps;
double x2 = (i + 1) * isz.cx / steps;
double xc = (x1 + x2) / 2;
w.Move(center).Line(p1).Line(p2).Fill(img,
MapTriangles(Pointf(xc, isz.cy), Pointf(x1, 0), Pointf(x2, 0),
center, p1, p2));
}
w.Finish();
}
};
GUI_APP_MAIN
{
MyApp app;
app.img = StreamRaster::LoadFileAny("C:/xxx/aukro.jpg");
app.Run();
}
(Adding MapTriangles as Xform2D static method...)
|
|
|
|
|
Re: Is 'texture mapping' possible on Painter? [message #53010 is a reply to message #53007] |
Thu, 06 February 2020 20:40  |
Didier
Messages: 725 Registered: November 2008 Location: France
|
Contributor |
|
|
This sample code is very interesting,
I never took time to look at what Xform2D was used for (I never needed it) and when I see this example, it looks very powerful and easy to use
Maybe it could be included in the examples
|
|
|
Goto Forum:
Current Time: Mon Apr 28 19:14:24 CEST 2025
Total time taken to generate the page: 0.00516 seconds
|