test/testsprite2.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 17 Aug 2016 21:04:50 +0200
changeset 10275 ba7dc3ebb81e
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
Emscripten: Fixed opening previously closed joystick.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
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>
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
     3
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
     4
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
     6
  arising from the use of this software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
     7
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
    10
  freely.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5520
diff changeset
    11
*/
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
/* Simple program:  Move N sprites around on the screen as fast as possible */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
#include <stdlib.h>
1907
06c27a737b7a Streamlined the API a bit and optimized the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 1904
diff changeset
    15
#include <stdio.h>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
#include <time.h>
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    18
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    19
#include <emscripten/emscripten.h>
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    20
#endif
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    21
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
    22
#include "SDL_test.h"
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    23
#include "SDL_test_common.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
    25
#define NUM_SPRITES    100
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
    26
#define MAX_SPEED     1
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    28
static SDLTest_CommonState *state;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
static int num_sprites;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
    30
static SDL_Texture **sprites;
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
    31
static SDL_bool cycle_color;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
    32
static SDL_bool cycle_alpha;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
    33
static int cycle_direction = 1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
    34
static int current_alpha = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
    35
static int current_color = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
static SDL_Rect *positions;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
static SDL_Rect *velocities;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
static int sprite_w, sprite_h;
5140
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 5138
diff changeset
    39
static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
    41
/* Number of iterations to move sprites - used for visual tests. */
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
    42
/* -1: infinite random moves (default); >=0: enables N deterministic moves */
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
    43
static int iterations = -1;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
    44
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    45
int done;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    46
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
quit(int rc)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
{
7719
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7639
diff changeset
    51
    SDL_free(sprites);
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7639
diff changeset
    52
    SDL_free(positions);
31b5f9ff36ca Christoph Mallon: Remove pointless if (x) before SDL_free(x)
Sam Lantinga <slouken@libsdl.org>
parents: 7639
diff changeset
    53
    SDL_free(velocities);
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    54
    SDLTest_CommonQuit(state);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
    exit(rc);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
int
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7315
diff changeset
    59
LoadSprite(const char *file)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
    int i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
    SDL_Surface *temp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    /* Load the sprite image */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    temp = SDL_LoadBMP(file);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    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
    67
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
        return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
    sprite_w = temp->w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
    sprite_h = temp->h;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
    /* Set transparent pixel as the pixel at (0,0) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
    if (temp->format->palette) {
3560
5543db4239e6 The SDL 1.3 tests have been cleaned up not to include any 1.2 compatibility code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
    75
        SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
3183
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    76
    } else {
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    77
        switch (temp->format->BitsPerPixel) {
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    78
        case 15:
3560
5543db4239e6 The SDL 1.3 tests have been cleaned up not to include any 1.2 compatibility code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
    79
            SDL_SetColorKey(temp, 1, (*(Uint16 *) temp->pixels) & 0x00007FFF);
3183
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    80
            break;
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    81
        case 16:
3560
5543db4239e6 The SDL 1.3 tests have been cleaned up not to include any 1.2 compatibility code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
    82
            SDL_SetColorKey(temp, 1, *(Uint16 *) temp->pixels);
3183
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    83
            break;
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    84
        case 24:
3560
5543db4239e6 The SDL 1.3 tests have been cleaned up not to include any 1.2 compatibility code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
    85
            SDL_SetColorKey(temp, 1, (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
3183
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    86
            break;
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    87
        case 32:
3560
5543db4239e6 The SDL 1.3 tests have been cleaned up not to include any 1.2 compatibility code.
Sam Lantinga <slouken@libsdl.org>
parents: 3536
diff changeset
    88
            SDL_SetColorKey(temp, 1, *(Uint32 *) temp->pixels);
3183
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    89
            break;
d1436442215f Support for 15/16/24/32 bpps of icon.bmp has been added, in case if not an original icon.bmp (8bpp with palette) is used for tests.
Mike Gorchak <lestat@i.com.ua>
parents: 2884
diff changeset
    90
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    /* Create textures from the image */
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
    94
    for (i = 0; i < state->num_windows; ++i) {
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
    95
        SDL_Renderer *renderer = state->renderers[i];
5158
b3ccd1947786 Simplified and improved the process of creating a texture from a surface.
Sam Lantinga <slouken@libsdl.org>
parents: 5147
diff changeset
    96
        sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
3285
0d7b20a4a629 Fall back to opaque sprite if no formats with alpha are supported.
Sam Lantinga <slouken@libsdl.org>
parents: 3266
diff changeset
    97
        if (!sprites[i]) {
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
    98
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
            SDL_FreeSurface(temp);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
            return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
        }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   102
        SDL_SetTextureBlendMode(sprites[i], blendMode);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    SDL_FreeSurface(temp);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
    /* We're ready to roll. :) */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
    return (0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
void
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   111
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
{
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   113
    int i;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   114
    SDL_Rect viewport, temp;
2783
e33ad7ebb7eb Fixed Direct3D rendering
Sam Lantinga <slouken@libsdl.org>
parents: 2222
diff changeset
   115
    SDL_Rect *position, *velocity;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
    /* Query the sizes */
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   118
    SDL_RenderGetViewport(renderer, &viewport);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   120
    /* Cycle the color and alpha, if desired */
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   121
    if (cycle_color) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   122
        current_color += cycle_direction;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   123
        if (current_color < 0) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   124
            current_color = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   125
            cycle_direction = -cycle_direction;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   126
        }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   127
        if (current_color > 255) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   128
            current_color = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   129
            cycle_direction = -cycle_direction;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   130
        }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   131
        SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   132
                               (Uint8) current_color);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   133
    }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   134
    if (cycle_alpha) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   135
        current_alpha += cycle_direction;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   136
        if (current_alpha < 0) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   137
            current_alpha = 0;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   138
            cycle_direction = -cycle_direction;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   139
        }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   140
        if (current_alpha > 255) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   141
            current_alpha = 255;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   142
            cycle_direction = -cycle_direction;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   143
        }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   144
        SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   145
    }
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   146
3264
8fe0806637df Fixed bug #783
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   147
    /* Draw a gray background */
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   148
    SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   149
    SDL_RenderClear(renderer);
3264
8fe0806637df Fixed bug #783
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   150
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   151
    /* Test points */
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   152
    SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   153
    SDL_RenderDrawPoint(renderer, 0, 0);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   154
    SDL_RenderDrawPoint(renderer, viewport.w-1, 0);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   155
    SDL_RenderDrawPoint(renderer, 0, viewport.h-1);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   156
    SDL_RenderDrawPoint(renderer, viewport.w-1, viewport.h-1);
3264
8fe0806637df Fixed bug #783
Sam Lantinga <slouken@libsdl.org>
parents: 3186
diff changeset
   157
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   158
    /* Test horizontal and vertical lines */
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   159
    SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   160
    SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   161
    SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   162
    SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   163
    SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   164
3266
7856dfe3a44f More test coverage
Sam Lantinga <slouken@libsdl.org>
parents: 3265
diff changeset
   165
    /* Test fill and copy */
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   166
    SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
3266
7856dfe3a44f More test coverage
Sam Lantinga <slouken@libsdl.org>
parents: 3265
diff changeset
   167
    temp.x = 1;
7856dfe3a44f More test coverage
Sam Lantinga <slouken@libsdl.org>
parents: 3265
diff changeset
   168
    temp.y = 1;
7856dfe3a44f More test coverage
Sam Lantinga <slouken@libsdl.org>
parents: 3265
diff changeset
   169
    temp.w = sprite_w;
7856dfe3a44f More test coverage
Sam Lantinga <slouken@libsdl.org>
parents: 3265
diff changeset
   170
    temp.h = sprite_h;
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   171
    SDL_RenderFillRect(renderer, &temp);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   172
    SDL_RenderCopy(renderer, sprite, NULL, &temp);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   173
    temp.x = viewport.w-sprite_w-1;
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   174
    temp.y = 1;
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   175
    temp.w = sprite_w;
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   176
    temp.h = sprite_h;
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   177
    SDL_RenderFillRect(renderer, &temp);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   178
    SDL_RenderCopy(renderer, sprite, NULL, &temp);
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   179
    temp.x = 1;
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   180
    temp.y = viewport.h-sprite_h-1;
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   181
    temp.w = sprite_w;
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   182
    temp.h = sprite_h;
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   183
    SDL_RenderFillRect(renderer, &temp);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   184
    SDL_RenderCopy(renderer, sprite, NULL, &temp);
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   185
    temp.x = viewport.w-sprite_w-1;
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   186
    temp.y = viewport.h-sprite_h-1;
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   187
    temp.w = sprite_w;
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   188
    temp.h = sprite_h;
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   189
    SDL_RenderFillRect(renderer, &temp);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   190
    SDL_RenderCopy(renderer, sprite, NULL, &temp);
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   191
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   192
    /* Test diagonal lines */
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   193
    SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   194
    SDL_RenderDrawLine(renderer, sprite_w, sprite_h,
5297
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   195
                       viewport.w-sprite_w-2, viewport.h-sprite_h-2);
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   196
    SDL_RenderDrawLine(renderer, viewport.w-sprite_w-2, sprite_h,
1800dc39b74c Changed the concept of a render clip rect to a render viewport.
Sam Lantinga <slouken@libsdl.org>
parents: 5184
diff changeset
   197
                       sprite_w, viewport.h-sprite_h-2);
3265
8f534bf37bef Added more tests for the different primitive types
Sam Lantinga <slouken@libsdl.org>
parents: 3264
diff changeset
   198
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   199
    /* Conditionally move the sprites, bounce at the wall */
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   200
    if (iterations == -1 || iterations > 0) {
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   201
        for (i = 0; i < num_sprites; ++i) {
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   202
            position = &positions[i];
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   203
            velocity = &velocities[i];
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   204
            position->x += velocity->x;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   205
            if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   206
                velocity->x = -velocity->x;
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   207
                position->x += velocity->x;
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   208
            }
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   209
            position->y += velocity->y;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   210
            if ((position->y < 0) || (position->y >= (viewport.h - sprite_h))) {
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   211
                velocity->y = -velocity->y;
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   212
                position->y += velocity->y;
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   213
            }
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   214
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   215
        }
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   216
        
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   217
        /* Countdown sprite-move iterations and disable color changes at iteration end - used for visual tests. */
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   218
        if (iterations > 0) {
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   219
            iterations--;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   220
            if (iterations == 0) {
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   221
                cycle_alpha = SDL_FALSE;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   222
                cycle_color = SDL_FALSE;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   223
            }
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   224
        }
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   225
    }
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   226
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   227
    /* Draw sprites */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
    for (i = 0; i < num_sprites; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
        position = &positions[i];
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   230
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
        /* Blit the sprite onto the screen */
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   232
        SDL_RenderCopy(renderer, sprite, NULL, position);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
    /* Update the screen! */
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   236
    SDL_RenderPresent(renderer);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   239
void
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   240
loop()
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   241
{
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   242
    int i;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   243
    SDL_Event event;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   244
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   245
    /* Check for events */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   246
    while (SDL_PollEvent(&event)) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   247
        SDLTest_CommonEvent(state, &event, &done);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   248
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   249
    for (i = 0; i < state->num_windows; ++i) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   250
        if (state->windows[i] == NULL)
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   251
            continue;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   252
        MoveSprites(state->renderers[i], sprites[i]);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   253
    }
9607
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   254
#ifdef __EMSCRIPTEN__
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   255
    if (done) {
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   256
        emscripten_cancel_main_loop();
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   257
    }
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   258
#endif
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   259
}
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   260
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
main(int argc, char *argv[])
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
{
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   264
    int i;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
    Uint32 then, now, frames;
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   266
    Uint64 seed;
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7315
diff changeset
   267
    const char *icon = "icon.bmp";
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   269
    /* Initialize parameters */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    num_sprites = NUM_SPRITES;
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   271
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   272
    /* 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: 5535
diff changeset
   273
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   274
    if (!state) {
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   275
        return 1;
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   276
    }
5520
09b500e0656d Added orientation rotation for iOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 5297
diff changeset
   277
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   278
    for (i = 1; i < argc;) {
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   279
        int consumed;
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   280
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   281
        consumed = SDLTest_CommonArg(state, i);
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
   282
        if (consumed == 0) {
1916
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   283
            consumed = -1;
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   284
            if (SDL_strcasecmp(argv[i], "--blend") == 0) {
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   285
                if (argv[i + 1]) {
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   286
                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2834
diff changeset
   287
                        blendMode = SDL_BLENDMODE_NONE;
1916
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   288
                        consumed = 2;
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   289
                    } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2834
diff changeset
   290
                        blendMode = SDL_BLENDMODE_BLEND;
1916
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   291
                        consumed = 2;
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   292
                    } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
2884
9dde605c7540 Date: Fri, 19 Dec 2008 20:17:35 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2834
diff changeset
   293
                        blendMode = SDL_BLENDMODE_ADD;
1916
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   294
                        consumed = 2;
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5158
diff changeset
   295
                    } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5158
diff changeset
   296
                        blendMode = SDL_BLENDMODE_MOD;
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5158
diff changeset
   297
                        consumed = 2;
1916
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   298
                    }
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   299
                }
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   300
            } else if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   301
                if (argv[i + 1]) {
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   302
                    iterations = SDL_atoi(argv[i + 1]);
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   303
                    if (iterations < -1) iterations = -1;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   304
                    consumed = 2;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   305
                }
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   306
            } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   307
                cycle_color = SDL_TRUE;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   308
                consumed = 1;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   309
            } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   310
                cycle_alpha = SDL_TRUE;
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1965
diff changeset
   311
                consumed = 1;
1916
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   312
            } else if (SDL_isdigit(*argv[i])) {
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   313
                num_sprites = SDL_atoi(argv[i]);
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   314
                consumed = 1;
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7315
diff changeset
   315
            } else if (argv[i][0] != '-') {
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7315
diff changeset
   316
                icon = argv[i];
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7315
diff changeset
   317
                consumed = 1;
1916
c773b0c0ac89 Implemented blend modes in the D3D renderer
Sam Lantinga <slouken@libsdl.org>
parents: 1915
diff changeset
   318
            }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
   319
        }
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   320
        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
   321
            SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   322
                    argv[0], SDLTest_CommonUsage(state));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
            quit(1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
        }
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   325
        i += consumed;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
    }
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   327
    if (!SDLTest_CommonInit(state)) {
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   328
        quit(2);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
    /* Create the windows, initialize the renderers, and load the textures */
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   332
    sprites =
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3596
diff changeset
   333
        (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   334
    if (!sprites) {
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
   335
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
        quit(2);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    }
1914
051df511279c Added a test program framework for easy initialization.
Sam Lantinga <slouken@libsdl.org>
parents: 1907
diff changeset
   338
    for (i = 0; i < state->num_windows; ++i) {
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   339
        SDL_Renderer *renderer = state->renderers[i];
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   340
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   341
        SDL_RenderClear(renderer);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
    }
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7315
diff changeset
   343
    if (LoadSprite(icon) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
        quit(2);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    /* Allocate memory for the sprite info */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
    positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
    velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
    if (!positions || !velocities) {
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
   351
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
        quit(2);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
    }
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   354
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   355
    /* Position sprites and set their velocities using the fuzzer */ 
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   356
    if (iterations >= 0) {
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   357
        /* Deterministic seed - used for visual tests */
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   358
        seed = (Uint64)iterations;
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   359
    } else {
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   360
        /* Pseudo-random seed generated from the time */
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   361
        seed = (Uint64)time(NULL);
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   362
    }
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   363
    SDLTest_FuzzerInit(seed);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
    for (i = 0; i < num_sprites; ++i) {
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   365
        positions[i].x = SDLTest_RandomIntegerInRange(0, state->window_w - sprite_w);
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   366
        positions[i].y = SDLTest_RandomIntegerInRange(0, state->window_h - sprite_h);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
        positions[i].w = sprite_w;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   368
        positions[i].h = sprite_h;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   369
        velocities[i].x = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
        velocities[i].y = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
        while (!velocities[i].x && !velocities[i].y) {
7315
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   372
            velocities[i].x = SDLTest_RandomIntegerInRange(-MAX_SPEED, MAX_SPEED);
417fa81cf17e Update testsprite2 for visual testing: user fuzzer and add --iteration parameter to enable deterministic screen end-state
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6785
diff changeset
   373
            velocities[i].y = SDLTest_RandomIntegerInRange(-MAX_SPEED, MAX_SPEED);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   375
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   376
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1914
diff changeset
   377
    /* Main render loop */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   378
    frames = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   379
    then = SDL_GetTicks();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   380
    done = 0;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   381
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   382
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   383
    emscripten_set_main_loop(loop, 0, 1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   384
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   385
    while (!done) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   386
        ++frames;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   387
        loop();
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   388
    }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   389
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   390
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   391
    /* Print out some timing information */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   392
    now = SDL_GetTicks();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   393
    if (now > then) {
2786
Sam Lantinga <slouken@libsdl.org>
parents: 2783
diff changeset
   394
        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
   395
        SDL_Log("%2.2f frames per second\n", fps);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   396
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   397
    quit(0);
5147
ad50b3db78bd The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
   398
    return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
/* vi: set ts=4 sw=4 expandtab: */