Changeset 3926 for libcaca/trunk/caca/triangle.c
 Timestamp:
 Nov 18, 2009, 12:25:58 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/caca/triangle.c
r3925 r3926 156 156 } 157 157 158 /** \brief Fill a triangle on the canvas using an arbitrarysized texture. 159 * 160 * This function fails if one or both the canvas are missing 161 * 162 * \param cv The handle to the libcaca canvas. 163 * \param x1 X coordinate of the first point. 164 * \param y1 Y coordinate of the first point. 165 * \param x2 X coordinate of the second point. 166 * \param y2 Y coordinate of the second point. 167 * \param x3 X coordinate of the third point. 168 * \param y3 Y coordinate of the third point. 169 * \param u1 U texture coordinate of the first point. 170 * \param v1 V texture coordinate of the first point. 171 * \param u2 U texture coordinate of the second point. 172 * \param v2 V texture coordinate of the second point. 173 * \param u3 U texture coordinate of the third point. 174 * \param v3 V texture coordinate of the third point. 175 * \param tex The handle of the canvas texture. 176 * \return This function return 0 if ok, 1 if canvas or texture are missing. 177 */ 178 int caca_fill_triangle_textured(caca_canvas_t *cv, 179 int x1, int y1, 158 /* This function actually renders the triangle, 159 * but is not exported due to sam's pedantic will. */ 160 static int caca_fill_triangle_textured_l(caca_canvas_t *cv, 161 int x1, int y1, 180 162 int x2, int y2, 181 int x3, int y3, 182 float u1, float v1, 163 int x3, int y3, 164 caca_canvas_t *tex, 165 float u1, float v1, 183 166 float u2, float v2, 184 float u3, float v3 ,185 caca_canvas_t *tex)167 float u3, float v3) 168 186 169 { 187 170 uint32_t savedattr; … … 201 184 /* Bubblesort y1 <= y2 <= y3 */ 202 185 if(y1 > y2) 203 return caca_fill_triangle_textured (cv,204 x2, y2, x1, y1, x3, y3,205 u2, v2, u1, v1, u3, v3,206 tex);186 return caca_fill_triangle_textured_l(cv, 187 x2, y2, x1, y1, x3, y3, 188 tex, 189 u2, v2, u1, v1, u3, v3); 207 190 if(y2 > y3) 208 return caca_fill_triangle_textured (cv,209 x1, y1, x3, y3, x2, y2,210 u1, v1, u3, v3, u2, v2,211 tex);212 191 return caca_fill_triangle_textured_l(cv, 192 x1, y1, x3, y3, x2, y2, 193 tex, 194 u1, v1, u3, v3, u2, v2); 195 213 196 savedattr = caca_get_attr(cv, 1, 1); 214 197 215 198 /* Clip texture coordinates */ 216 199 if(u1<0.0f) u1 = 0.0f; if(v1<0.0f) v1 = 0.0f; 217 200 if(u2<0.0f) u2 = 0.0f; if(v2<0.0f) v2 = 0.0f; 218 201 if(u3<0.0f) u3 = 0.0f; if(v3<0.0f) v3 = 0.0f; 219 220 221 202 if(u1>1.0f) u1 = 1.0f; if(v1>1.0f) v1 = 1.0f; 203 if(u2>1.0f) u2 = 1.0f; if(v2>1.0f) v2 = 1.0f; 204 if(u3>1.0f) u3 = 1.0f; if(v3>1.0f) v3 = 1.0f; 222 205 223 206 /* Convert relative tex coordinates to absolute */ 224 207 int tw = caca_get_canvas_width(tex); 225 208 int th = caca_get_canvas_height(tex); 226 209 227 u1*=(float)tw; u2*=(float)tw; u3*=(float)tw; 228 v1*=(float)th; v2*=(float)th; v3*=(float)th; 210 u1*=(float)tw; u2*=(float)tw; u3*=(float)tw; 211 v1*=(float)th; v2*=(float)th; v3*=(float)th; 229 212 230 213 int x, y; … … 252 235 float u, v; 253 236 254 237 int s = 0; 255 238 256 239 /* Top */ 257 for(y = y1 ; y < y2; y++) 240 for(y = y1 ; y < y2; y++) 258 241 { 259 242 … … 273 256 274 257 /* scanline */ 275 for(x = xa ; x < xb; x++)258 for(x = xa ; x < xb; x++) 276 259 { 277 260 u+=tus; 278 261 v+=tvs; 279 262 /* FIXME: use caca_get_canvas_attrs / caca_get_canvas_chars */ 280 263 uint32_t attr = caca_get_attr(tex, u, v); 281 264 uint32_t c = caca_get_char(tex, u, v); 282 265 caca_set_attr(cv, attr); … … 291 274 } 292 275 293 if(s) 276 if(s) 294 277 { 295 278 SWAP_F(xb, xa); 296 279 SWAP_F(sl13, sl12); 297 280 SWAP_F(ua, ub); 298 SWAP_F(va, vb); 281 SWAP_F(va, vb); 299 282 SWAP_F(usl13, usl12); 300 283 SWAP_F(vsl13, vsl12); … … 315 298 } 316 299 317 for(y = y2 ; y < y3; y++) 318 { 319 if(xb <= xa) 300 for(y = y2 ; y < y3; y++) 301 { 302 if(xb <= xa) 320 303 { 321 SWAP_F(xb, xa); 304 SWAP_F(xb, xa); 322 305 SWAP_F(sl13, sl23); 323 306 SWAP_F(ua, ub); 324 SWAP_F(va, vb); 307 SWAP_F(va, vb); 325 308 SWAP_F(usl13, usl23); 326 309 SWAP_F(vsl13, vsl23); … … 332 315 333 316 /* scanline */ 334 for(x = xa ; x < xb; x++)317 for(x = xa ; x < xb; x++) 335 318 { 336 319 u+=tus; … … 339 322 uint32_t attr = caca_get_attr(tex, u, v); 340 323 uint32_t c = caca_get_char(tex, u, v); 341 caca_set_attr(cv, attr); 342 caca_put_char(cv, x, y, c); 343 } 344 324 caca_set_attr(cv, attr); 325 caca_put_char(cv, x, y, c); 326 } 327 345 328 xa+=sl13; 346 329 xb+=sl23; 347 330 348 331 ua+=usl13; va+=vsl13; 349 ub+=usl23; vb+=vsl23; 332 ub+=usl23; vb+=vsl23; 350 333 } 351 334 … … 354 337 return 0; 355 338 } 339 340 /** \brief Fill a triangle on the canvas using an arbitrarysized texture. 341 * 342 * This function fails if one or both the canvas are missing 343 * 344 * \param cv The handle to the libcaca canvas. 345 * \param coords The coordinates of the triangle (3{x,y}) 346 * \param tex The handle of the canvas texture. 347 * \param uv The coordinates of the texture (3{u,v}) 348 * \return This function return 0 if ok, 1 if canvas or texture are missing. 349 */ 350 int caca_fill_triangle_textured(caca_canvas_t *cv, 351 int coords[6], 352 caca_canvas_t *tex, 353 float uv[6]) { 354 355 return caca_fill_triangle_textured_l(cv, 356 coords[0], coords[1], 357 coords[2], coords[3], 358 coords[4], coords[5], 359 tex, 360 uv[0], uv[1], 361 uv[2], uv[3], 362 uv[4], uv[5]); 363 } 364 356 365 357 366
Note: See TracChangeset
for help on using the changeset viewer.