test/testrendercopyex.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     1
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9922
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     3
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     6
  arising from the use of this software.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     7
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    10
  freely.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    11
*/
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    12
/* Simple program:  Move N sprites around on the screen as fast as possible */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    13
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    14
#include <stdlib.h>
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    15
#include <stdio.h>
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    16
#include <time.h>
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    17
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
    18
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
    19
#include <emscripten/emscripten.h>
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
    20
#endif
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
    21
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6320
diff changeset
    22
#include "SDL_test_common.h"
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    23
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    24
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6320
diff changeset
    25
static SDLTest_CommonState *state;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    26
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    27
typedef struct {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    28
    SDL_Window *window;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    29
    SDL_Renderer *renderer;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    30
    SDL_Texture *background;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    31
    SDL_Texture *sprite;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    32
    SDL_Rect sprite_rect;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    33
    int scale_direction;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    34
} DrawState;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    35
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
    36
DrawState *drawstates;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
    37
int done;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
    38
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    39
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    40
static void
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    41
quit(int rc)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    42
{
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6320
diff changeset
    43
    SDLTest_CommonQuit(state);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    44
    exit(rc);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    45
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    46
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    47
SDL_Texture *
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    48
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    49
{
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    50
    SDL_Surface *temp;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    51
    SDL_Texture *texture;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    52
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    53
    /* Load the sprite image */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    54
    temp = SDL_LoadBMP(file);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    55
    if (temp == NULL) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    56
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    57
        return NULL;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    58
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    59
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    60
    /* Set transparent pixel as the pixel at (0,0) */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    61
    if (transparent) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    62
        if (temp->format->palette) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    63
            SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    64
        } else {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    65
            switch (temp->format->BitsPerPixel) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    66
            case 15:
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    67
                SDL_SetColorKey(temp, SDL_TRUE,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    68
                                (*(Uint16 *) temp->pixels) & 0x00007FFF);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    69
                break;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    70
            case 16:
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    71
                SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    72
                break;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    73
            case 24:
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    74
                SDL_SetColorKey(temp, SDL_TRUE,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    75
                                (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    76
                break;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    77
            case 32:
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    78
                SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    79
                break;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    80
            }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    81
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    82
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    83
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    84
    /* Create textures from the image */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    85
    texture = SDL_CreateTextureFromSurface(renderer, temp);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    86
    if (!texture) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    87
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    88
        SDL_FreeSurface(temp);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    89
        return NULL;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    90
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    91
    SDL_FreeSurface(temp);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    92
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    93
    /* We're ready to roll. :) */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    94
    return texture;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    95
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    96
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    97
void
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    98
Draw(DrawState *s)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    99
{
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   100
    SDL_Rect viewport;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   101
    SDL_Texture *target;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   102
    SDL_Point *center=NULL;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   103
    SDL_Point origin = {0,0};
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   104
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   105
    SDL_RenderGetViewport(s->renderer, &viewport);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   106
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   107
    target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   108
    SDL_SetRenderTarget(s->renderer, target);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   109
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   110
    /* Draw the background */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   111
    SDL_RenderCopy(s->renderer, s->background, NULL, NULL);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   112
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   113
    /* Scale and draw the sprite */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   114
    s->sprite_rect.w += s->scale_direction;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   115
    s->sprite_rect.h += s->scale_direction;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   116
    if (s->scale_direction > 0) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   117
        center = &origin;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   118
        if (s->sprite_rect.w >= viewport.w || s->sprite_rect.h >= viewport.h) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   119
            s->scale_direction = -1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   120
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   121
    } else {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   122
        if (s->sprite_rect.w <= 1 || s->sprite_rect.h <= 1) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   123
            s->scale_direction = 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   124
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   125
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   126
    s->sprite_rect.x = (viewport.w - s->sprite_rect.w) / 2;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   127
    s->sprite_rect.y = (viewport.h - s->sprite_rect.h) / 2;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   128
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   129
    SDL_RenderCopyEx(s->renderer, s->sprite, NULL, &s->sprite_rect, (double)s->sprite_rect.w, center, s->scale_direction);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   130
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   131
    SDL_SetRenderTarget(s->renderer, NULL);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   132
    SDL_RenderCopy(s->renderer, target, NULL, NULL);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   133
    SDL_DestroyTexture(target);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   134
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   135
    /* Update the screen! */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   136
    SDL_RenderPresent(s->renderer);
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   137
    /* SDL_Delay(10); */
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   138
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   139
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   140
void loop()
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   141
{
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   142
    int i;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   143
    SDL_Event event;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   144
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   145
    /* Check for events */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   146
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   147
    while (SDL_PollEvent(&event)) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   148
        SDLTest_CommonEvent(state, &event, &done);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   149
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   150
    for (i = 0; i < state->num_windows; ++i) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   151
        if (state->windows[i] == NULL)
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   152
            continue;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   153
        Draw(&drawstates[i]);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   154
    }
9607
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   155
#ifdef __EMSCRIPTEN__
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   156
    if (done) {
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   157
        emscripten_cancel_main_loop();
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   158
    }
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   159
#endif
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   160
}
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   161
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   162
int
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   163
main(int argc, char *argv[])
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   164
{
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   165
    int i;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   166
    int frames;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   167
    Uint32 then, now;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   168
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   169
    /* Enable standard application logging */
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   170
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   171
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   172
    /* Initialize test framework */
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6320
diff changeset
   173
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   174
    if (!state) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   175
        return 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   176
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   177
    for (i = 1; i < argc;) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   178
        int consumed;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   179
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6320
diff changeset
   180
        consumed = SDLTest_CommonArg(state, i);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   181
        if (consumed == 0) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   182
            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   183
            return 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   184
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   185
        i += consumed;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   186
    }
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6320
diff changeset
   187
    if (!SDLTest_CommonInit(state)) {
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   188
        quit(2);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   189
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   190
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   191
    drawstates = SDL_stack_alloc(DrawState, state->num_windows);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   192
    for (i = 0; i < state->num_windows; ++i) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   193
        DrawState *drawstate = &drawstates[i];
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   194
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   195
        drawstate->window = state->windows[i];
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   196
        drawstate->renderer = state->renderers[i];
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   197
        drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   198
        drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   199
        if (!drawstate->sprite || !drawstate->background) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   200
            quit(2);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   201
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   202
        SDL_QueryTexture(drawstate->sprite, NULL, NULL,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   203
                         &drawstate->sprite_rect.w, &drawstate->sprite_rect.h);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   204
        drawstate->scale_direction = 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   205
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   206
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   207
    /* Main render loop */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   208
    frames = 0;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   209
    then = SDL_GetTicks();
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   210
    done = 0;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   211
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   212
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   213
    emscripten_set_main_loop(loop, 0, 1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   214
#else
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   215
    while (!done) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   216
        ++frames;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   217
        loop();
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   218
        }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8851
diff changeset
   219
#endif
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   220
    /* Print out some timing information */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   221
    now = SDL_GetTicks();
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   222
    if (now > then) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   223
        double fps = ((double) frames * 1000) / (now - then);
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
   224
        SDL_Log("%2.2f frames per second\n", fps);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   225
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   226
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   227
    SDL_stack_free(drawstates);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   228
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   229
    quit(0);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   230
    return 0;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   231
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   232
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   233
/* vi: set ts=4 sw=4 expandtab: */