Changeset 3926
 Timestamp:
 Nov 18, 2009, 12:25:58 PM (11 years ago)
 Location:
 libcaca/trunk
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/XCode/libcacaXCode.xcodeproj/project.pbxproj
r3911 r3926 62 62 E6DB663610AECCD700B6F924 /* mygetopt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mygetopt.h; path = ../src/mygetopt.h; sourceTree = SOURCE_ROOT; }; 63 63 E6DB663710AECCD700B6F924 /* texture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = texture.h; path = ../src/texture.h; sourceTree = SOURCE_ROOT; }; 64 E6DB663910AECD1F00B6F924 /* trifiller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = trifiller.c; path = ../examples/trifiller.c; sourceTree = SOURCE_ROOT; };64 E6DB663910AECD1F00B6F924 /* trifiller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = trifiller.c; path = ../examples/trifiller.c; sourceTree = SOURCE_ROOT; wrapsLines = 0; }; 65 65 E6DB663B10AECDF500B6F924 /* blit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = blit.c; path = ../examples/blit.c; sourceTree = SOURCE_ROOT; }; 66 66 E6DB663C10AECDF500B6F924 /* canvas.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = canvas.c; path = ../examples/canvas.c; sourceTree = SOURCE_ROOT; }; 
libcaca/trunk/caca/caca.h
r3909 r3926 339 339 __extern int caca_fill_triangle(caca_canvas_t *, int, int, int, int, int, 340 340 int, uint32_t); 341 __extern int caca_fill_triangle_textured(caca_canvas_t *, 342 int , int , 343 int , int , 344 int , int , 345 float , float , 346 float , float , 347 float , float , 348 caca_canvas_t *); 341 __extern int caca_fill_triangle_textured(caca_canvas_t *cv, 342 int coords[6], 343 caca_canvas_t *tex, 344 float uv[6]); 349 345 /* @} */ 350 346 
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 
libcaca/trunk/examples/trifiller.c
r3909 r3926 50 50 51 51 52 float square[ 4][2] = {52 float square[6][2] = { 53 53 {SQUARE_SIZE, SQUARE_SIZE}, 54 54 { SQUARE_SIZE, SQUARE_SIZE}, … … 56 56 {SQUARE_SIZE, SQUARE_SIZE}, 57 57 }; 58 float uv1[6] = { 59 0, 0, 60 1, 0, 61 1, 1 62 }; 63 float uv2[6] = { 64 0, 0, 65 1, 1, 66 0, 1 67 }; 68 58 69 59 70 float rotated[4][2]; 71 int coords1[6], coords2[6]; 60 72 61 73 /* Create displayed canvas */ … … 75 87 } 76 88 77 89 /* Open window */ 78 90 dp = caca_create_display(cv); 79 91 if(!dp) … … 194 206 for(p=0; p<4; p++) 195 207 { 196 197 208 rotated[p][0] = square[p][0] * cos(angle*M_PI/180.0f)  square[p][1] * sin(angle*M_PI/180.0f); 209 rotated[p][1] = square[p][0] * sin(angle*M_PI/180.0f) + square[p][1] * cos(angle*M_PI/180.0f); 198 210 199 211 rotated[p][0] += ww/2 + px; … … 203 215 angle+=1.0f; 204 216 217 218 /* Reaarange coordinates to fit libcaca's format */ 219 coords1[0] = rotated[0][0]; coords1[1] = rotated[0][1]; 220 coords1[2] = rotated[1][0]; coords1[3] = rotated[1][1]; 221 coords1[4] = rotated[2][0]; coords1[5] = rotated[2][1]; 222 223 coords2[0] = rotated[0][0]; coords2[1] = rotated[0][1]; 224 coords2[2] = rotated[2][0]; coords2[3] = rotated[2][1]; 225 coords2[4] = rotated[3][0]; coords2[5] = rotated[3][1]; 226 205 227 /* Display two triangles */ 228 caca_fill_triangle_textured(cv, /* canvas */ 229 coords1, /* triangle coordinates */ 230 tex, /* texture canvas */ 231 uv1); /* texture coordinates */ 206 232 caca_fill_triangle_textured(cv, 207 /* triangle screen coordinates */ 208 rotated[0][0], rotated[0][1], 209 rotated[1][0], rotated[1][1], 210 rotated[2][0], rotated[2][1], 211 /* texture coordinates */ 212 0, 0, 213 1, 0, 214 1, 1, 215 tex); 216 217 caca_fill_triangle_textured(cv, 218 /* triangle screen coordinates */ 219 rotated[0][0], rotated[0][1], 220 rotated[2][0], rotated[2][1], 221 rotated[3][0], rotated[3][1], 222 /* texture coordinates */ 223 0, 0, 224 1, 1, 225 0, 1, 226 tex); 233 coords2, 234 tex, 235 uv2); 227 236 228 237 /* Refresh display and clear for next frame */
Note: See TracChangeset
for help on using the changeset viewer.