test/testrendertarget.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 7781 3023b0270c94
equal deleted inserted replaced
7638:783d1cff9b20 7639:9406b7dd2f2d
    44     SDL_Texture *texture;
    44     SDL_Texture *texture;
    45 
    45 
    46     /* Load the sprite image */
    46     /* Load the sprite image */
    47     temp = SDL_LoadBMP(file);
    47     temp = SDL_LoadBMP(file);
    48     if (temp == NULL) {
    48     if (temp == NULL) {
    49         fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
    49         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
    50         return NULL;
    50         return NULL;
    51     }
    51     }
    52 
    52 
    53     /* Set transparent pixel as the pixel at (0,0) */
    53     /* Set transparent pixel as the pixel at (0,0) */
    54     if (transparent) {
    54     if (transparent) {
    75     }
    75     }
    76 
    76 
    77     /* Create textures from the image */
    77     /* Create textures from the image */
    78     texture = SDL_CreateTextureFromSurface(renderer, temp);
    78     texture = SDL_CreateTextureFromSurface(renderer, temp);
    79     if (!texture) {
    79     if (!texture) {
    80         fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
    80         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
    81         SDL_FreeSurface(temp);
    81         SDL_FreeSurface(temp);
    82         return NULL;
    82         return NULL;
    83     }
    83     }
    84     SDL_FreeSurface(temp);
    84     SDL_FreeSurface(temp);
    85 
    85 
   112         SDL_SetRenderDrawColor(s->renderer, 0x00, 0x00, 0x00, 0x00);
   112         SDL_SetRenderDrawColor(s->renderer, 0x00, 0x00, 0x00, 0x00);
   113         SDL_RenderFillRect(s->renderer, NULL);
   113         SDL_RenderFillRect(s->renderer, NULL);
   114         SDL_RenderCopy(s->renderer, A, NULL, NULL);
   114         SDL_RenderCopy(s->renderer, A, NULL, NULL);
   115         SDL_RenderReadPixels(s->renderer, NULL, SDL_PIXELFORMAT_ARGB8888, &P, sizeof(P));
   115         SDL_RenderReadPixels(s->renderer, NULL, SDL_PIXELFORMAT_ARGB8888, &P, sizeof(P));
   116 
   116 
   117         printf("Blended pixel: 0x%8.8X\n", P);
   117         SDL_Log("Blended pixel: 0x%8.8X\n", P);
   118 
   118 
   119         SDL_DestroyTexture(A);
   119         SDL_DestroyTexture(A);
   120         SDL_DestroyTexture(B);
   120         SDL_DestroyTexture(B);
   121         blend_tested = SDL_TRUE;
   121         blend_tested = SDL_TRUE;
   122     }
   122     }
   216     SDL_Event event;
   216     SDL_Event event;
   217     int frames;
   217     int frames;
   218     Uint32 then, now;
   218     Uint32 then, now;
   219     SDL_bool test_composite = SDL_FALSE;
   219     SDL_bool test_composite = SDL_FALSE;
   220 
   220 
       
   221     /* Enable standard application logging */
       
   222     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
       
   223 
   221     /* Initialize test framework */
   224     /* Initialize test framework */
   222     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
   225     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
   223     if (!state) {
   226     if (!state) {
   224         return 1;
   227         return 1;
   225     }
   228     }
   233                 test_composite = SDL_TRUE;
   236                 test_composite = SDL_TRUE;
   234                 consumed = 1;
   237                 consumed = 1;
   235             }
   238             }
   236         }
   239         }
   237         if (consumed < 0) {
   240         if (consumed < 0) {
   238             fprintf(stderr,
   241             SDL_Log("Usage: %s %s [--composite]\n",
   239                     "Usage: %s %s [--composite]\n",
       
   240                     argv[0], SDLTest_CommonUsage(state));
   242                     argv[0], SDLTest_CommonUsage(state));
   241             quit(1);
   243             quit(1);
   242         }
   244         }
   243         i += consumed;
   245         i += consumed;
   244     }
   246     }
   287 
   289 
   288     /* Print out some timing information */
   290     /* Print out some timing information */
   289     now = SDL_GetTicks();
   291     now = SDL_GetTicks();
   290     if (now > then) {
   292     if (now > then) {
   291         double fps = ((double) frames * 1000) / (now - then);
   293         double fps = ((double) frames * 1000) / (now - then);
   292         printf("%2.2f frames per second\n", fps);
   294         SDL_Log("%2.2f frames per second\n", fps);
   293     }
   295     }
   294 
   296 
   295     SDL_stack_free(drawstates);
   297     SDL_stack_free(drawstates);
   296 
   298 
   297     quit(0);
   299     quit(0);