Mercurial > sdl-ios-xcode
comparison test/automated/render/render.c @ 3596:f638ded38b8a
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine().
Added API for rectangle drawing (as opposed to filling)
Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay.
Optimized software line drawing quite a bit.
Added support for Wu's anti-aliased line drawing, currently disabled by default.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 23 Dec 2009 01:55:00 +0000 |
parents | 5f038ec1a1af |
children | 64ce267332c6 |
comparison
equal
deleted
inserted
replaced
3595:b7c6828d4039 | 3596:f638ded38b8a |
---|---|
339 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 339 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
340 return -1; | 340 return -1; |
341 */ | 341 */ |
342 | 342 |
343 /* Clear screen. */ | 343 /* Clear screen. */ |
344 ret = SDL_RenderRect( NULL ); | 344 ret = SDL_RenderFillRect( NULL ); |
345 /* | 345 /* |
346 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 346 if (SDL_ATassert( "SDL_RenderFillRect", ret == 0)) |
347 return -1; | 347 return -1; |
348 */ | 348 */ |
349 | 349 |
350 /* Set defaults. */ | 350 /* Set defaults. */ |
351 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); | 351 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); |
411 rect.w = 40; | 411 rect.w = 40; |
412 rect.h = 80; | 412 rect.h = 80; |
413 ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE ); | 413 ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE ); |
414 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 414 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
415 return -1; | 415 return -1; |
416 ret = SDL_RenderRect( &rect ); | 416 ret = SDL_RenderFillRect( &rect ); |
417 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 417 if (SDL_ATassert( "SDL_RenderFillRect", ret == 0)) |
418 return -1; | 418 return -1; |
419 | 419 |
420 /* Draw a rectangle. */ | 420 /* Draw a rectangle. */ |
421 rect.x = 10; | 421 rect.x = 10; |
422 rect.y = 10; | 422 rect.y = 10; |
423 rect.w = 60; | 423 rect.w = 60; |
424 rect.h = 40; | 424 rect.h = 40; |
425 ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE ); | 425 ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE ); |
426 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 426 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
427 return -1; | 427 return -1; |
428 ret = SDL_RenderRect( &rect ); | 428 ret = SDL_RenderFillRect( &rect ); |
429 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 429 if (SDL_ATassert( "SDL_RenderFillRect", ret == 0)) |
430 return -1; | 430 return -1; |
431 | 431 |
432 /* Draw some points like so: | 432 /* Draw some points like so: |
433 * X.X.X.X.. | 433 * X.X.X.X.. |
434 * .X.X.X.X. | 434 * .X.X.X.X. |
437 x = y % 2; | 437 x = y % 2; |
438 for (; x<80; x+=2) { | 438 for (; x<80; x+=2) { |
439 ret = SDL_SetRenderDrawColor( x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE ); | 439 ret = SDL_SetRenderDrawColor( x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE ); |
440 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 440 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
441 return -1; | 441 return -1; |
442 ret = SDL_RenderPoint( x, y ); | 442 ret = SDL_RenderDrawPoint( x, y ); |
443 if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) | 443 if (SDL_ATassert( "SDL_RenderDrawPoint", ret == 0)) |
444 return -1; | 444 return -1; |
445 } | 445 } |
446 } | 446 } |
447 | 447 |
448 /* Draw some lines. */ | 448 /* Draw some lines. */ |
449 ret = SDL_SetRenderDrawColor( 0, 255, 0, SDL_ALPHA_OPAQUE ); | 449 ret = SDL_SetRenderDrawColor( 0, 255, 0, SDL_ALPHA_OPAQUE ); |
450 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 450 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
451 return -1; | 451 return -1; |
452 ret = SDL_RenderLine( 0, 30, 80, 30 ); | 452 ret = SDL_RenderDrawLine( 0, 30, 80, 30 ); |
453 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 453 if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0)) |
454 return -1; | 454 return -1; |
455 ret = SDL_SetRenderDrawColor( 55, 55, 5, SDL_ALPHA_OPAQUE ); | 455 ret = SDL_SetRenderDrawColor( 55, 55, 5, SDL_ALPHA_OPAQUE ); |
456 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 456 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
457 return -1; | 457 return -1; |
458 ret = SDL_RenderLine( 40, 30, 40, 60 ); | 458 ret = SDL_RenderDrawLine( 40, 30, 40, 60 ); |
459 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 459 if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0)) |
460 return -1; | 460 return -1; |
461 ret = SDL_SetRenderDrawColor( 5, 105, 105, SDL_ALPHA_OPAQUE ); | 461 ret = SDL_SetRenderDrawColor( 5, 105, 105, SDL_ALPHA_OPAQUE ); |
462 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 462 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
463 return -1; | 463 return -1; |
464 ret = SDL_RenderLine( 0, 0, 29, 29 ); | 464 ret = SDL_RenderDrawLine( 0, 0, 29, 29 ); |
465 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 465 if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0)) |
466 return -1; | 466 return -1; |
467 ret = SDL_RenderLine( 29, 30, 0, 59 ); | 467 ret = SDL_RenderDrawLine( 29, 30, 0, 59 ); |
468 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 468 if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0)) |
469 return -1; | 469 return -1; |
470 ret = SDL_RenderLine( 79, 0, 50, 29 ); | 470 ret = SDL_RenderDrawLine( 79, 0, 50, 29 ); |
471 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 471 if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0)) |
472 return -1; | 472 return -1; |
473 ret = SDL_RenderLine( 79, 59, 50, 30 ); | 473 ret = SDL_RenderDrawLine( 79, 59, 50, 30 ); |
474 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 474 if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0)) |
475 return -1; | 475 return -1; |
476 | 476 |
477 /* See if it's the same. */ | 477 /* See if it's the same. */ |
478 if (render_compare( "Primitives output not the same.", &img_primitives, ALLOWABLE_ERROR_OPAQUE )) | 478 if (render_compare( "Primitives output not the same.", &img_primitives, ALLOWABLE_ERROR_OPAQUE )) |
479 return -1; | 479 return -1; |
504 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 504 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
505 return -1; | 505 return -1; |
506 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); | 506 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); |
507 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 507 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
508 return -1; | 508 return -1; |
509 ret = SDL_RenderRect( NULL ); | 509 ret = SDL_RenderFillRect( NULL ); |
510 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 510 if (SDL_ATassert( "SDL_RenderFillRect", ret == 0)) |
511 return -1; | 511 return -1; |
512 rect.x = 10; | 512 rect.x = 10; |
513 rect.y = 25; | 513 rect.y = 25; |
514 rect.w = 40; | 514 rect.w = 40; |
515 rect.h = 25; | 515 rect.h = 25; |
517 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 517 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
518 return -1; | 518 return -1; |
519 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); | 519 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); |
520 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 520 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
521 return -1; | 521 return -1; |
522 ret = SDL_RenderRect( &rect ); | 522 ret = SDL_RenderFillRect( &rect ); |
523 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 523 if (SDL_ATassert( "SDL_RenderFillRect", ret == 0)) |
524 return -1; | 524 return -1; |
525 rect.x = 30; | 525 rect.x = 30; |
526 rect.y = 40; | 526 rect.y = 40; |
527 rect.w = 45; | 527 rect.w = 45; |
528 rect.h = 15; | 528 rect.h = 15; |
530 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 530 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
531 return -1; | 531 return -1; |
532 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); | 532 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); |
533 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 533 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
534 return -1; | 534 return -1; |
535 ret = SDL_RenderRect( &rect ); | 535 ret = SDL_RenderFillRect( &rect ); |
536 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 536 if (SDL_ATassert( "SDL_RenderFillRect", ret == 0)) |
537 return -1; | 537 return -1; |
538 rect.x = 25; | 538 rect.x = 25; |
539 rect.y = 25; | 539 rect.y = 25; |
540 rect.w = 25; | 540 rect.w = 25; |
541 rect.h = 25; | 541 rect.h = 25; |
543 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 543 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
544 return -1; | 544 return -1; |
545 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); | 545 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); |
546 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 546 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
547 return -1; | 547 return -1; |
548 ret = SDL_RenderRect( &rect ); | 548 ret = SDL_RenderFillRect( &rect ); |
549 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 549 if (SDL_ATassert( "SDL_RenderFillRect", ret == 0)) |
550 return -1; | 550 return -1; |
551 | 551 |
552 /* Draw blended lines, lines for everyone. */ | 552 /* Draw blended lines, lines for everyone. */ |
553 for (i=0; i<SCREEN_W; i+=2) { | 553 for (i=0; i<SCREEN_W; i+=2) { |
554 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); | 554 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); |
556 return -1; | 556 return -1; |
557 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : | 557 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : |
558 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); | 558 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); |
559 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 559 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
560 return -1; | 560 return -1; |
561 ret = SDL_RenderLine( 0, 0, i, 59 ); | 561 ret = SDL_RenderDrawLine( 0, 0, i, 59 ); |
562 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 562 if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0)) |
563 return -1; | 563 return -1; |
564 } | 564 } |
565 for (i=0; i<SCREEN_H; i+=2) { | 565 for (i=0; i<SCREEN_H; i+=2) { |
566 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); | 566 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); |
567 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 567 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
568 return -1; | 568 return -1; |
569 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : | 569 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : |
570 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); | 570 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); |
571 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 571 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
572 return -1; | 572 return -1; |
573 ret = SDL_RenderLine( 0, 0, 79, i ); | 573 ret = SDL_RenderDrawLine( 0, 0, 79, i ); |
574 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 574 if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0)) |
575 return -1; | 575 return -1; |
576 } | 576 } |
577 | 577 |
578 /* Draw points. */ | 578 /* Draw points. */ |
579 for (j=0; j<SCREEN_H; j+=3) { | 579 for (j=0; j<SCREEN_H; j+=3) { |
583 return -1; | 583 return -1; |
584 ret = SDL_SetRenderDrawBlendMode( ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND : | 584 ret = SDL_SetRenderDrawBlendMode( ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND : |
585 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); | 585 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); |
586 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 586 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
587 return -1; | 587 return -1; |
588 ret = SDL_RenderPoint( i, j ); | 588 ret = SDL_RenderDrawPoint( i, j ); |
589 if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) | 589 if (SDL_ATassert( "SDL_RenderDrawPoint", ret == 0)) |
590 return -1; | 590 return -1; |
591 } | 591 } |
592 } | 592 } |
593 | 593 |
594 /* See if it's the same. */ | 594 /* See if it's the same. */ |