test/teststreaming.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: 5255
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: 5255
diff changeset
     3
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5255
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: 5255
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: 5255
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: 5255
diff changeset
     7
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5255
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: 5255
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: 5255
diff changeset
    10
  freely.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5255
diff changeset
    11
*/
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
/********************************************************************************
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
 *                                                                              *
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
 * Running moose :) Coded by Mike Gorchak.                                      *
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
 *                                                                              *
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
 ********************************************************************************/
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
#include <stdlib.h>
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
#include <stdio.h>
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    21
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    22
#include <emscripten/emscripten.h>
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    23
#endif
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    24
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL.h"
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#define MOOSEPIC_W 64
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#define MOOSEPIC_H 88
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#define MOOSEFRAMES_COUNT 10
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
SDL_Color MooseColors[84] = {
9101
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    34
    {49, 49, 49, 255}, {66, 24, 0, 255}, {66, 33, 0, 255}, {66, 66, 66, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    35
    {66, 115, 49, 255}, {74, 33, 0, 255}, {74, 41, 16, 255}, {82, 33, 8, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    36
    {82, 41, 8, 255}, {82, 49, 16, 255}, {82, 82, 82, 255}, {90, 41, 8, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    37
    {90, 41, 16, 255}, {90, 57, 24, 255}, {99, 49, 16, 255}, {99, 66, 24, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    38
    {99, 66, 33, 255}, {99, 74, 33, 255}, {107, 57, 24, 255}, {107, 82, 41, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    39
    {115, 57, 33, 255}, {115, 66, 33, 255}, {115, 66, 41, 255}, {115, 74, 0, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    40
    {115, 90, 49, 255}, {115, 115, 115, 255}, {123, 82, 0, 255}, {123, 99, 57, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    41
    {132, 66, 41, 255}, {132, 74, 41, 255}, {132, 90, 8, 255}, {132, 99, 33, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    42
    {132, 99, 66, 255}, {132, 107, 66, 255}, {140, 74, 49, 255}, {140, 99, 16, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    43
    {140, 107, 74, 255}, {140, 115, 74, 255}, {148, 107, 24, 255}, {148, 115, 82, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    44
    {148, 123, 74, 255}, {148, 123, 90, 255}, {156, 115, 33, 255}, {156, 115, 90, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    45
    {156, 123, 82, 255}, {156, 132, 82, 255}, {156, 132, 99, 255}, {156, 156, 156, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    46
    {165, 123, 49, 255}, {165, 123, 90, 255}, {165, 132, 82, 255}, {165, 132, 90, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    47
    {165, 132, 99, 255}, {165, 140, 90, 255}, {173, 132, 57, 255}, {173, 132, 99, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    48
    {173, 140, 107, 255}, {173, 140, 115, 255}, {173, 148, 99, 255}, {173, 173, 173, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    49
    {181, 140, 74, 255}, {181, 148, 115, 255}, {181, 148, 123, 255}, {181, 156, 107, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    50
    {189, 148, 123, 255}, {189, 156, 82, 255}, {189, 156, 123, 255}, {189, 156, 132, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    51
    {189, 189, 189, 255}, {198, 156, 123, 255}, {198, 165, 132, 255}, {206, 165, 99, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    52
    {206, 165, 132, 255}, {206, 173, 140, 255}, {206, 206, 206, 255}, {214, 173, 115, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    53
    {214, 173, 140, 255}, {222, 181, 148, 255}, {222, 189, 132, 255}, {222, 189, 156, 255},
f0c55792deed Fixed warnings about missing initializers in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8149
diff changeset
    54
    {222, 222, 222, 255}, {231, 198, 165, 255}, {231, 231, 231, 255}, {239, 206, 173, 255}
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
};
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
Uint8 MooseFrames[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE];
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    59
SDL_Renderer *renderer;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    60
int frame;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    61
SDL_Texture *MooseTexture;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    62
SDL_bool done = SDL_FALSE;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    63
5255
b0f5108fda60 Cleaned up the file a bit for tutorial viewing
Sam Lantinga <slouken@libsdl.org>
parents: 5254
diff changeset
    64
void quit(int rc)
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
{
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    SDL_Quit();
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
    exit(rc);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
}
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
5255
b0f5108fda60 Cleaned up the file a bit for tutorial viewing
Sam Lantinga <slouken@libsdl.org>
parents: 5254
diff changeset
    70
void UpdateTexture(SDL_Texture *texture, int frame)
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
{
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
    SDL_Color *color;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
    Uint8 *src;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
    Uint32 *dst;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
    int row, col;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
    void *pixels;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    int pitch;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
    if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 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
    80
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError());
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
        quit(5);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    }
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
    src = MooseFrames[frame];
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    for (row = 0; row < MOOSEPIC_H; ++row) {
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
        dst = (Uint32*)((Uint8*)pixels + row * pitch);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
        for (col = 0; col < MOOSEPIC_W; ++col) {
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
            color = &MooseColors[*src++];
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
            *dst++ = (0xFF000000|(color->r<<16)|(color->g<<8)|color->b);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
        }
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    }
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    SDL_UnlockTexture(texture);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
}
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    94
void
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    95
loop()
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    96
{
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    97
    SDL_Event event;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    98
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
    99
    while (SDL_PollEvent(&event)) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   100
        switch (event.type) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   101
        case SDL_KEYDOWN:
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   102
            if (event.key.keysym.sym == SDLK_ESCAPE) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   103
                done = SDL_TRUE;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   104
            }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   105
            break;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   106
        case SDL_QUIT:
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   107
            done = SDL_TRUE;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   108
            break;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   109
        }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   110
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   111
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   112
    frame = (frame + 1) % MOOSEFRAMES_COUNT;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   113
    UpdateTexture(MooseTexture, frame);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   114
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   115
    SDL_RenderClear(renderer);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   116
    SDL_RenderCopy(renderer, MooseTexture, NULL, NULL);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   117
    SDL_RenderPresent(renderer);
9607
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   118
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   119
#ifdef __EMSCRIPTEN__
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   120
    if (done) {
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   121
        emscripten_cancel_main_loop();
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   122
    }
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   123
#endif
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   124
}
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   125
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
int
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
main(int argc, char **argv)
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
{
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
    SDL_Window *window;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    SDL_RWops *handle;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   132
    /* 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
   133
    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
   134
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
    if (SDL_Init(SDL_INIT_VIDEO) < 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
   136
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
        return 1;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    }
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    /* load the moose images */
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
    handle = SDL_RWFromFile("moose.dat", "rb");
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
    if (handle == 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
   143
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
        quit(2);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    }
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
    SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
    SDL_RWclose(handle);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    /* Create the window and renderer */
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
    window = SDL_CreateWindow("Happy Moose",
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
                              SDL_WINDOWPOS_UNDEFINED,
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
                              SDL_WINDOWPOS_UNDEFINED,
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
                              MOOSEPIC_W*4, MOOSEPIC_H*4,
7478
0d02f6a323f5 Removed not needed SDL_WINDOW_SHOWN from test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 5535
diff changeset
   155
                              SDL_WINDOW_RESIZABLE);
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
    if (!window) {
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
   157
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
        quit(3);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
    }
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    renderer = SDL_CreateRenderer(window, -1, 0);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    if (!renderer) {
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
   163
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
        quit(4);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
    }
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
    if (!MooseTexture) {
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
   169
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
        quit(5);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
    }
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
    /* Loop, waiting for QUIT or the escape key */
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
    frame = 0;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   175
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   176
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   177
    emscripten_set_main_loop(loop, 0, 1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   178
#else
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
    while (!done) {
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   180
        loop();
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
        }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 9101
diff changeset
   182
#endif
5254
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
    SDL_DestroyRenderer(renderer);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
    quit(0);
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
    return 0;
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
}
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
f650566b2f51 Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
/* vi: set ts=4 sw=4 expandtab: */