Sign in Join
Wiki copytemporary

BGRABitmap tutorial 10/es: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11Esta tutoría muestra como usar mapeo de texturas.
22
33### Crear un nuevo proyecto
44
55Crea un nuevo proyecto y añade referencia a [[BGRABitmap]], de la misma forma que en [[BGRABitmap tutorial/es|la primer tutoría]].
66
77### Usando mapeo no particular
88
99Veamos que pasa cuando dibujamos un polígono con una textura usando el mapeo predeterminado :
1010
1111``` pascal
1212procedure TForm1.FormPaint(Sender: TObject);
1313var image: TBGRABitmap;
1414 tex: TBGRABitmap;
1515begin
1616 //black background
1717 image := TBGRABitmap.Create(ClientWidth,ClientHeight, BGRABlack );
1818
1919 tex:= TBGRABitmap.Create('image.png'); //cargar un bitmap
2020 image.FillPolyAntialias( [PointF(110,10), PointF(250,10), PointF(350,160), PointF(10,160)], tex);
2121 tex.Free;
2222
2323 image.Draw(Canvas,0,0,True); //dibujar en la pantalla
2424 image.free;
2525end;
2626```
2727
2828### Ejecuta el programa
2929
3030Deberías obtener algo parecido a esto :
3131
32-<figure>
33-<img src="BGRATutorial10a.png" title="BGRATutorial10a.png" />
34-<figcaption>BGRATutorial10a.png</figcaption>
35-</figure>
32+![](/wiki-images/7/7e/BGRATutorial10a.png)
3633
3734Como puedes ver la imágen no es deformada.
3835
3936### Transformación afín
4037
4138Podemos aplicar transformación afín como esta :
4239
4340``` pascal
4441uses BGRABitmap, BGRABitmapTypes, BGRATransform;
4542
4643procedure TForm1.PaintImage;
4744var image: TBGRABitmap;
4845 tex: TBGRABitmap;
4946 affine: TBGRAAffineBitmapTransform;
5047
5148begin
5249 //fondo negro
5350 image := TBGRABitmap.Create(ClientWidth,ClientHeight, BGRABlack );
5451
5552 tex:= TBGRABitmap.Create('image.png'); //load a bitmap
5653
5754 //crear rotación de 45°
5855 affine := TBGRAAffineBitmapTransform.Create(tex,True);
5956 affine.RotateDeg(45);
6057
6158 //usar esta transformación como parámetro en vez de tex
6259 image.FillPolyAntialias( [PointF(110,10), PointF(250,10), PointF(350,160), PointF(10,160)], affine);
6360
6461 affine.Free;
6562 tex.Free;
6663
6764 image.Draw(Canvas,0,0,True); //dibujar en la pantalla
6865 image.free;
6966end;
7067```
7168
7269### Ejecutar el programa
7370
7471Deberías obtener una imágen rotada en el polígono :
7572
76-<figure>
77-<img src="BGRATutorial10b.png" title="BGRATutorial10b.png" />
78-<figcaption>BGRATutorial10b.png</figcaption>
79-</figure>
73+![](/wiki-images/2/2a/BGRATutorial10b.png)
8074
8175### Mapeo de texturas
8276
8377Ahora, si queremos que la textura sea alineada con el borde del polígono, podemos usar mapeo de texturas.
8478
8579#### Mapeo linear
8680
8781Mapeo linear ajusta la imágen linearmente a traves de los bordes. Para hacer esto :
8882
8983``` pascal
9084procedure TForm1.PaintImage;
9185var image: TBGRABitmap;
9286 tex: TBGRABitmap;
9387begin
9488 image := TBGRABitmap.Create(ClientWidth,ClientHeight, BGRABlack );
9589
9690 tex:= TBGRABitmap.Create('image.png');
9791 image.FillPolyLinearMapping( [PointF(110,10), PointF(250,10), PointF(350,160), PointF(10,160)], tex,
9892 [PointF(0,0), PointF(tex.width-1,0), PointF(tex.Width-1,tex.Height-1), PointF(0,tex.Height-1)], true);
9993 tex.Free;
10094
10195 image.Draw(Canvas,0,0,True);
10296 image.free;
10397end;
10498```
10599
106100Para hacer el mapeo, usamos FillPolyLinearMapping. Algunos nuevos parámetros aparecen. Las coordenadas de la textura definen, para cada punto del polígono, la posición en la textura. La opción de interpolación es usada para mejor calidad.
107101
108102#### Ejecuta el programa
109103
110104Ahora la textura es deformada de acuerdo a la figura poligonal.
111105
112-<figure>
113-<img src="BGRATutorial10c.png" title="BGRATutorial10c.png" />
114-<figcaption>BGRATutorial10c.png</figcaption>
115-</figure>
106+![](/wiki-images/f/f3/BGRATutorial10c.png)
116107
117108#### Mapeo de perspectiva
118109
119110El mapeo de perspectiva permita cambiar la profundidad de cada punto.
120111
121112``` pascal
122113procedure TForm1.PaintImage;
123114var image: TBGRABitmap;
124115 tex: TBGRABitmap;
125116begin
126117 image := TBGRABitmap.Create(ClientWidth,ClientHeight, BGRABlack );
127118
128119 tex:= TBGRABitmap.Create('image.png');
129120 image.FillPolyPerspectiveMapping( [PointF(110,10), PointF(250,10), PointF(350,160), PointF(10,160)],
130121 [75, 75, 50, 50],
131122 tex, [PointF(0,0), PointF(tex.width-1,0), PointF(tex.Width-1,tex.Height-1), PointF(0,tex.Height-1)], true);
132123 tex.Free;
133124
134125 image.Draw(Canvas,0,0,True);
135126 image.free;
136127end;
137128```
138129
139130Aquí la profundidad es 75 para la parte superior del polígono y 50 para la parte inferior del polígono. Esto significa que la parte inferior está mas cerca del observador, como si fuera horizontal, como un suelo.
140131
141132#### Ejecuta el programa
142133
143134Ahora parece que esto es un polígono 3D :
144135
145-<figure>
146-<img src="BGRATutorial10d.png" title="BGRATutorial10d.png" />
147-<figcaption>BGRATutorial10d.png</figcaption>
148-</figure>
136+![](/wiki-images/6/67/BGRATutorial10d.png)
149137
150138### Conclusion
151139
152140Usando estas técnicas, es posible deformar una imágen, como en la herramienta de LazPaint "grid deformation", o para renderizar objetos 3D con texturas, como en los test 19-21 de testbgrafunc (también en el archivo de LazPaint).
153141
154142[[BGRABitmap tutorial 9/es|Tutoría anterior (phong shading y texturas)]] \| [[BGRABitmap tutorial 11/es|Siguiente tutoría (combinando transformaciones)]]
155143
156144---
157145*From the Free Pascal wiki, page "BGRABitmap tutorial 10/es", as it stood on 2020-02-09 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
158146Category: Castellano
159147Category: Español

Back to history