Mercurial > sdl-ios-xcode
annotate test/teststreaming.c @ 5259:f650566b2f51
Added a very simple example of texture streaming
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 11 Feb 2011 12:24:59 -0800 |
parents | |
children | b0f5108fda60 |
rev | line source |
---|---|
5259
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /******************************************************************************** |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 * * |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 * Running moose :) Coded by Mike Gorchak. * |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 * * |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 ********************************************************************************/ |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 #include <string.h> |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 #include "SDL.h" |
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 #define MOOSEPIC_W 64 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 #define MOOSEPIC_H 88 |
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 #define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H) |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 #define MOOSEFRAMES_COUNT 10 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 SDL_Color MooseColors[84] = { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 {49, 49, 49} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 , {66, 24, 0} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 , {66, 33, 0} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 , {66, 66, 66} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 {66, 115, 49} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 , {74, 33, 0} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 , {74, 41, 16} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 , {82, 33, 8} |
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 {82, 41, 8} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 , {82, 49, 16} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 , {82, 82, 82} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 , {90, 41, 8} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 {90, 41, 16} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 , {90, 57, 24} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 , {99, 49, 16} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 , {99, 66, 24} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 {99, 66, 33} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 , {99, 74, 33} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 , {107, 57, 24} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 , {107, 82, 41} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 {115, 57, 33} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 , {115, 66, 33} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 , {115, 66, 41} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 , {115, 74, 0} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 {115, 90, 49} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 , {115, 115, 115} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 , {123, 82, 0} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 , {123, 99, 57} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 {132, 66, 41} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 , {132, 74, 41} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 , {132, 90, 8} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 , {132, 99, 33} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 {132, 99, 66} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 , {132, 107, 66} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 , {140, 74, 49} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 , {140, 99, 16} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 {140, 107, 74} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 , {140, 115, 74} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 , {148, 107, 24} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 , {148, 115, 82} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 {148, 123, 74} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 , {148, 123, 90} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 , {156, 115, 33} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 , {156, 115, 90} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 {156, 123, 82} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 , {156, 132, 82} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 , {156, 132, 99} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 , {156, 156, 156} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 {165, 123, 49} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 , {165, 123, 90} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 , {165, 132, 82} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 , {165, 132, 90} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 {165, 132, 99} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 , {165, 140, 90} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 , {173, 132, 57} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 , {173, 132, 99} |
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 {173, 140, 107} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 , {173, 140, 115} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 , {173, 148, 99} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 , {173, 173, 173} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 {181, 140, 74} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 , {181, 148, 115} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 , {181, 148, 123} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 , {181, 156, 107} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 {189, 148, 123} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 , {189, 156, 82} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 , {189, 156, 123} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 , {189, 156, 132} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 {189, 189, 189} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 , {198, 156, 123} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 , {198, 165, 132} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 , {206, 165, 99} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 {206, 165, 132} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 , {206, 173, 140} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 , {206, 206, 206} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 , {214, 173, 115} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 {214, 173, 140} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 , {222, 181, 148} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 , {222, 189, 132} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 , {222, 189, 156} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 , |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 {222, 222, 222} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 , {231, 198, 165} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 , {231, 231, 231} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 , {239, 206, 173} |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 }; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 Uint8 MooseFrames[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE]; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 static void |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 quit(int rc) |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 SDL_Quit(); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 exit(rc); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 static void UpdateTexture(SDL_Texture *texture, int frame) |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 SDL_Color *color; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 Uint8 *src; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 Uint32 *dst; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 int row, col; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 void *pixels; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 int pitch; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 fprintf(stderr, "Couldn't lock texture: %s\n", SDL_GetError()); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 quit(5); |
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 src = MooseFrames[frame]; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 for (row = 0; row < MOOSEPIC_H; ++row) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 dst = (Uint32*)((Uint8*)pixels + row * pitch); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 for (col = 0; col < MOOSEPIC_W; ++col) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 color = &MooseColors[*src++]; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 *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
|
155 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 SDL_UnlockTexture(texture); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 } |
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 int |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 main(int argc, char **argv) |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 SDL_Window *window; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 SDL_Renderer *renderer; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 SDL_RWops *handle; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 SDL_Texture *MooseTexture; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 SDL_Event event; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 SDL_bool done = SDL_FALSE; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 int frame; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 return 1; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 /* load the moose images */ |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 handle = SDL_RWFromFile("moose.dat", "rb"); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 if (handle == NULL) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 fprintf(stderr, "Can't find the file moose.dat !\n"); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 quit(2); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 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
|
183 SDL_RWclose(handle); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 |
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 /* Create the window and renderer */ |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 window = SDL_CreateWindow("Happy Moose", |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 SDL_WINDOWPOS_UNDEFINED, |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 SDL_WINDOWPOS_UNDEFINED, |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 MOOSEPIC_W*4, MOOSEPIC_H*4, |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 if (!window) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 fprintf(stderr, "Couldn't set create window: %s\n", SDL_GetError()); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 quit(3); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 renderer = SDL_CreateRenderer(window, -1, 0); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 if (!renderer) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 fprintf(stderr, "Couldn't set create renderer: %s\n", SDL_GetError()); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 quit(4); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 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
|
204 if (!MooseTexture) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 fprintf(stderr, "Couldn't set create texture: %s\n", SDL_GetError()); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 quit(5); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 /* 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
|
210 frame = 0; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 while (!done) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 while (SDL_PollEvent(&event)) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 switch (event.type) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 case SDL_KEYDOWN: |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 if (event.key.keysym.sym == SDLK_ESCAPE) { |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 done = SDL_TRUE; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 break; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 case SDL_QUIT: |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 done = SDL_TRUE; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 break; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 frame = (frame + 1) % MOOSEFRAMES_COUNT; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 UpdateTexture(MooseTexture, frame); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 SDL_RenderClear(renderer); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 SDL_RenderCopy(renderer, MooseTexture, NULL, NULL); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 SDL_RenderPresent(renderer); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 SDL_DestroyRenderer(renderer); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 quit(0); |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 return 0; |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 } |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 |
f650566b2f51
Added a very simple example of texture streaming
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 /* vi: set ts=4 sw=4 expandtab: */ |