Mercurial > sdl-ios-xcode
comparison Xcode-iPhoneOS/Demos/src/touch.c @ 3685:64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 21 Jan 2010 06:21:52 +0000 |
parents | 20326ba2bda2 |
children | 06c7423f8c60 |
comparison
equal
deleted
inserted
replaced
3684:cc564f08884f | 3685:64ce267332c6 |
---|---|
9 #include "common.h" | 9 #include "common.h" |
10 | 10 |
11 #define BRUSH_SIZE 32 /* width and height of the brush */ | 11 #define BRUSH_SIZE 32 /* width and height of the brush */ |
12 #define PIXELS_PER_ITERATION 5 /* number of pixels between brush blots when forming a line */ | 12 #define PIXELS_PER_ITERATION 5 /* number of pixels between brush blots when forming a line */ |
13 | 13 |
14 static SDL_TextureID brushID = 0; /* texture for the brush */ | 14 static SDL_Texture *brush = 0; /* texture for the brush */ |
15 | 15 |
16 /* | 16 /* |
17 draws a line from (startx, starty) to (startx + dx, starty + dy) | 17 draws a line from (startx, starty) to (startx + dx, starty + dy) |
18 this is accomplished by drawing several blots spaced PIXELS_PER_ITERATION apart | 18 this is accomplished by drawing several blots spaced PIXELS_PER_ITERATION apart |
19 */ | 19 */ |
41 dstRect.y = y; | 41 dstRect.y = y; |
42 /* shift x and y for next sprite location */ | 42 /* shift x and y for next sprite location */ |
43 x += dx_prime; | 43 x += dx_prime; |
44 y += dy_prime; | 44 y += dy_prime; |
45 /* draw brush blot */ | 45 /* draw brush blot */ |
46 SDL_RenderCopy(brushID, NULL, &dstRect); | 46 SDL_RenderCopy(brush, NULL, &dstRect); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 /* | 50 /* |
51 loads the brush texture | 51 loads the brush texture |
56 SDL_Surface *bmp_surface; | 56 SDL_Surface *bmp_surface; |
57 bmp_surface = SDL_LoadBMP("stroke.bmp"); | 57 bmp_surface = SDL_LoadBMP("stroke.bmp"); |
58 if (bmp_surface == NULL) { | 58 if (bmp_surface == NULL) { |
59 fatalError("could not load stroke.bmp"); | 59 fatalError("could not load stroke.bmp"); |
60 } | 60 } |
61 brushID = | 61 brush = |
62 SDL_CreateTextureFromSurface(SDL_PIXELFORMAT_ABGR8888, bmp_surface); | 62 SDL_CreateTextureFromSurface(SDL_PIXELFORMAT_ABGR8888, bmp_surface); |
63 SDL_FreeSurface(bmp_surface); | 63 SDL_FreeSurface(bmp_surface); |
64 if (brushID == 0) { | 64 if (brush == 0) { |
65 fatalError("could not create brush texture"); | 65 fatalError("could not create brush texture"); |
66 } | 66 } |
67 /* additive blending -- laying strokes on top of eachother makes them brighter */ | 67 /* additive blending -- laying strokes on top of eachother makes them brighter */ |
68 SDL_SetTextureBlendMode(brushID, SDL_BLENDMODE_ADD); | 68 SDL_SetTextureBlendMode(brush, SDL_BLENDMODE_ADD); |
69 /* set brush color (red) */ | 69 /* set brush color (red) */ |
70 SDL_SetTextureColorMod(brushID, 255, 100, 100); | 70 SDL_SetTextureColorMod(brush, 255, 100, 100); |
71 } | 71 } |
72 | 72 |
73 int | 73 int |
74 main(int argc, char *argv[]) | 74 main(int argc, char *argv[]) |
75 { | 75 { |
76 | 76 |
77 int x, y, dx, dy; /* mouse location */ | 77 int x, y, dx, dy; /* mouse location */ |
78 Uint8 state; /* mouse (touch) state */ | 78 Uint8 state; /* mouse (touch) state */ |
79 SDL_Event event; | 79 SDL_Event event; |
80 SDL_WindowID windowID; /* main window */ | 80 SDL_Window *window; /* main window */ |
81 int done; /* does user want to quit? */ | 81 int done; /* does user want to quit? */ |
82 | 82 |
83 /* initialize SDL */ | 83 /* initialize SDL */ |
84 if (SDL_Init(SDL_INIT_VIDEO) < 0) { | 84 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
85 fatalError("Could not initialize SDL"); | 85 fatalError("Could not initialize SDL"); |
86 } | 86 } |
87 | 87 |
88 /* create main window and renderer */ | 88 /* create main window and renderer */ |
89 windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, | 89 window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, |
90 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | | 90 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | |
91 SDL_WINDOW_BORDERLESS); | 91 SDL_WINDOW_BORDERLESS); |
92 SDL_CreateRenderer(windowID, 0, 0); | 92 SDL_CreateRenderer(window, 0, 0); |
93 | 93 |
94 /*load brush texture */ | 94 /*load brush texture */ |
95 initializeTexture(); | 95 initializeTexture(); |
96 | 96 |
97 /* fill canvass initially with all black */ | 97 /* fill canvass initially with all black */ |
116 break; | 116 break; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 /* cleanup */ | 120 /* cleanup */ |
121 SDL_DestroyTexture(brushID); | 121 SDL_DestroyTexture(brush); |
122 SDL_Quit(); | 122 SDL_Quit(); |
123 | 123 |
124 return 0; | 124 return 0; |
125 } | 125 } |