Simple Directmedia Layer

examples now using SDL_ALPHA_OPAQUE(_FLOAT) for opaque alpha value

authored by

Michael Palomas and committed by
Sam Lantinga
21c91d55 63ef5a23

+38 -38
+1 -1
docs/README-wayland.md
··· 212 212 SDL_SetWindowSize(sdlWindow, SDL_lround(640. * scale), SDL_lround(480. * scale)); 213 213 214 214 if (qtWindow.isVisible()) { 215 - SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 255, 255); 215 + SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 255, SDL_ALPHA_OPAQUE); 216 216 SDL_RenderClear(sdlRenderer); 217 217 SDL_RenderPresent(sdlRenderer); 218 218 } else {
+1 -1
examples/camera/01-read-and-draw/read-and-draw.c
··· 93 93 SDL_ReleaseCameraFrame(camera, frame); 94 94 } 95 95 96 - SDL_SetRenderDrawColor(renderer, 0x99, 0x99, 0x99, 255); 96 + SDL_SetRenderDrawColor(renderer, 0x99, 0x99, 0x99, SDL_ALPHA_OPAQUE); 97 97 SDL_RenderClear(renderer); 98 98 if (texture) { /* draw the latest camera frame, if available. */ 99 99 SDL_RenderTexture(renderer, texture, NULL, NULL);
+4 -4
examples/game/01-snake/snake.c
··· 257 257 } 258 258 259 259 r.w = r.h = SNAKE_BLOCK_SIZE_IN_PIXELS; 260 - SDL_SetRenderDrawColor(as->renderer, 0, 0, 0, 255); 260 + SDL_SetRenderDrawColor(as->renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); 261 261 SDL_RenderClear(as->renderer); 262 262 for (i = 0; i < SNAKE_GAME_WIDTH; i++) { 263 263 for (j = 0; j < SNAKE_GAME_HEIGHT; j++) { ··· 266 266 continue; 267 267 set_rect_xy_(&r, i, j); 268 268 if (ct == SNAKE_CELL_FOOD) 269 - SDL_SetRenderDrawColor(as->renderer, 80, 80, 255, 255); 269 + SDL_SetRenderDrawColor(as->renderer, 80, 80, 255, SDL_ALPHA_OPAQUE); 270 270 else /* body */ 271 - SDL_SetRenderDrawColor(as->renderer, 0, 128, 0, 255); 271 + SDL_SetRenderDrawColor(as->renderer, 0, 128, 0, SDL_ALPHA_OPAQUE); 272 272 SDL_RenderFillRect(as->renderer, &r); 273 273 } 274 274 } 275 - SDL_SetRenderDrawColor(as->renderer, 255, 255, 0, 255); /*head*/ 275 + SDL_SetRenderDrawColor(as->renderer, 255, 255, 0, SDL_ALPHA_OPAQUE); /*head*/ 276 276 set_rect_xy_(&r, ctx->head_xpos, ctx->head_ypos); 277 277 SDL_RenderFillRect(as->renderer, &r); 278 278 SDL_RenderPresent(as->renderer);
+2 -2
examples/pen/01-drawing-lines/drawing-lines.c
··· 45 45 46 46 /* just blank the render target to gray to start. */ 47 47 SDL_SetRenderTarget(renderer, render_target); 48 - SDL_SetRenderDrawColor(renderer, 100, 100, 100, 255); 48 + SDL_SetRenderDrawColor(renderer, 100, 100, 100, SDL_ALPHA_OPAQUE); 49 49 SDL_RenderClear(renderer); 50 50 SDL_SetRenderTarget(renderer, NULL); 51 51 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); ··· 90 90 { 91 91 /* make sure we're drawing to the window and not the render target */ 92 92 SDL_SetRenderTarget(renderer, NULL); 93 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); 93 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); 94 94 SDL_RenderClear(renderer); /* just in case. */ 95 95 SDL_RenderTexture(renderer, render_target, NULL, NULL); 96 96 SDL_RenderPresent(renderer);
+1 -1
examples/renderer/01-clear/clear.c
··· 49 49 const float red = (float) (0.5 + 0.5 * SDL_sin(now)); 50 50 const float green = (float) (0.5 + 0.5 * SDL_sin(now + SDL_PI_D * 2 / 3)); 51 51 const float blue = (float) (0.5 + 0.5 * SDL_sin(now + SDL_PI_D * 4 / 3)); 52 - SDL_SetRenderDrawColorFloat(renderer, red, green, blue, 1.0f); /* new color, full alpha. */ 52 + SDL_SetRenderDrawColorFloat(renderer, red, green, blue, SDL_ALPHA_OPAQUE_FLOAT); /* new color, full alpha. */ 53 53 54 54 /* clear the window to the draw color. */ 55 55 SDL_RenderClear(renderer);
+5 -5
examples/renderer/02-primitives/primitives.c
··· 55 55 SDL_FRect rect; 56 56 57 57 /* as you can see from this, rendering draws over whatever was drawn before it. */ 58 - SDL_SetRenderDrawColor(renderer, 33, 33, 33, 255); /* dark gray, full alpha */ 58 + SDL_SetRenderDrawColor(renderer, 33, 33, 33, SDL_ALPHA_OPAQUE); /* dark gray, full alpha */ 59 59 SDL_RenderClear(renderer); /* start with a blank canvas. */ 60 60 61 61 /* draw a filled rectangle in the middle of the canvas. */ 62 - SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); /* blue, full alpha */ 62 + SDL_SetRenderDrawColor(renderer, 0, 0, 255, SDL_ALPHA_OPAQUE); /* blue, full alpha */ 63 63 rect.x = rect.y = 100; 64 64 rect.w = 440; 65 65 rect.h = 280; 66 66 SDL_RenderFillRect(renderer, &rect); 67 67 68 68 /* draw some points across the canvas. */ 69 - SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); /* red, full alpha */ 69 + SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE); /* red, full alpha */ 70 70 SDL_RenderPoints(renderer, points, SDL_arraysize(points)); 71 71 72 72 /* draw a unfilled rectangle in-set a little bit. */ 73 - SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); /* green, full alpha */ 73 + SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); /* green, full alpha */ 74 74 rect.x += 30; 75 75 rect.y += 30; 76 76 rect.w -= 60; ··· 78 78 SDL_RenderRect(renderer, &rect); 79 79 80 80 /* draw two lines in an X across the whole canvas. */ 81 - SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255); /* yellow, full alpha */ 81 + SDL_SetRenderDrawColor(renderer, 255, 255, 0, SDL_ALPHA_OPAQUE); /* yellow, full alpha */ 82 82 SDL_RenderLine(renderer, 0, 0, 640, 480); 83 83 SDL_RenderLine(renderer, 0, 480, 640, 0); 84 84
+4 -4
examples/renderer/03-lines/lines.c
··· 56 56 }; 57 57 58 58 /* as you can see from this, rendering draws over whatever was drawn before it. */ 59 - SDL_SetRenderDrawColor(renderer, 100, 100, 100, 255); /* grey, full alpha */ 59 + SDL_SetRenderDrawColor(renderer, 100, 100, 100, SDL_ALPHA_OPAQUE); /* grey, full alpha */ 60 60 SDL_RenderClear(renderer); /* start with a blank canvas. */ 61 61 62 62 /* You can draw lines, one at a time, like these brown ones... */ 63 - SDL_SetRenderDrawColor(renderer, 127, 49, 32, 255); 63 + SDL_SetRenderDrawColor(renderer, 127, 49, 32, SDL_ALPHA_OPAQUE); 64 64 SDL_RenderLine(renderer, 240, 450, 400, 450); 65 65 SDL_RenderLine(renderer, 240, 356, 400, 356); 66 66 SDL_RenderLine(renderer, 240, 356, 240, 450); 67 67 SDL_RenderLine(renderer, 400, 356, 400, 450); 68 68 69 69 /* You can also draw a series of connected lines in a single batch... */ 70 - SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); 70 + SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); 71 71 SDL_RenderLines(renderer, line_points, SDL_arraysize(line_points)); 72 72 73 73 /* here's a bunch of lines drawn out from a center point in a circle. */ ··· 76 76 const float size = 30.0f; 77 77 const float x = 320.0f; 78 78 const float y = 95.0f - (size / 2.0f); 79 - SDL_SetRenderDrawColor(renderer, SDL_rand(256), SDL_rand(256), SDL_rand(256), 255); 79 + SDL_SetRenderDrawColor(renderer, SDL_rand(256), SDL_rand(256), SDL_rand(256), SDL_ALPHA_OPAQUE); 80 80 SDL_RenderLine(renderer, x, y, x + SDL_sinf((float) i) * size, y + SDL_cosf((float) i) * size); 81 81 } 82 82
+2 -2
examples/renderer/04-points/points.c
··· 97 97 last_time = now; 98 98 99 99 /* as you can see from this, rendering draws over whatever was drawn before it. */ 100 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 100 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 101 101 SDL_RenderClear(renderer); /* start with a blank canvas. */ 102 - SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); /* white, full alpha */ 102 + SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ 103 103 SDL_RenderPoints(renderer, points, SDL_arraysize(points)); /* draw all the points! */ 104 104 105 105 /* You can also draw single points with SDL_RenderPoint(), but it's
+5 -5
examples/renderer/05-rectangles/rectangles.c
··· 55 55 const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; 56 56 57 57 /* as you can see from this, rendering draws over whatever was drawn before it. */ 58 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 58 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 59 59 SDL_RenderClear(renderer); /* start with a blank canvas. */ 60 60 61 61 /* Rectangles are comprised of set of X and Y coordinates, plus width and ··· 66 66 /* Let's draw a single rectangle (square, really). */ 67 67 rects[0].x = rects[0].y = 100; 68 68 rects[0].w = rects[0].h = 100 + (100 * scale); 69 - SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); /* red, full alpha */ 69 + SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE); /* red, full alpha */ 70 70 SDL_RenderRect(renderer, &rects[0]); 71 71 72 72 /* Now let's draw several rectangles with one function call. */ ··· 76 76 rects[i].x = (WINDOW_WIDTH - rects[i].w) / 2; /* center it. */ 77 77 rects[i].y = (WINDOW_HEIGHT - rects[i].h) / 2; /* center it. */ 78 78 } 79 - SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); /* green, full alpha */ 79 + SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); /* green, full alpha */ 80 80 SDL_RenderRects(renderer, rects, 3); /* draw three rectangles at once */ 81 81 82 82 /* those were rectangle _outlines_, really. You can also draw _filled_ rectangles! */ ··· 84 84 rects[0].y = 50; 85 85 rects[0].w = 100 + (100 * scale); 86 86 rects[0].h = 50 + (50 * scale); 87 - SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); /* blue, full alpha */ 87 + SDL_SetRenderDrawColor(renderer, 0, 0, 255, SDL_ALPHA_OPAQUE); /* blue, full alpha */ 88 88 SDL_RenderFillRect(renderer, &rects[0]); 89 89 90 90 /* ...and also fill a bunch of rectangles at once... */ ··· 96 96 rects[i].w = w; 97 97 rects[i].h = h; 98 98 } 99 - SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); /* white, full alpha */ 99 + SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ 100 100 SDL_RenderFillRects(renderer, rects, SDL_arraysize(rects)); 101 101 102 102 SDL_RenderPresent(renderer); /* put it all on the screen! */
+1 -1
examples/renderer/06-textures/textures.c
··· 86 86 const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; 87 87 88 88 /* as you can see from this, rendering draws over whatever was drawn before it. */ 89 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 89 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 90 90 SDL_RenderClear(renderer); /* start with a blank canvas. */ 91 91 92 92 /* Just draw the static texture a few times. You can think of it like a
+1 -1
examples/renderer/07-streaming-textures/streaming-textures.c
··· 83 83 } 84 84 85 85 /* as you can see from this, rendering draws over whatever was drawn before it. */ 86 - SDL_SetRenderDrawColor(renderer, 66, 66, 66, 255); /* grey, full alpha */ 86 + SDL_SetRenderDrawColor(renderer, 66, 66, 66, SDL_ALPHA_OPAQUE); /* grey, full alpha */ 87 87 SDL_RenderClear(renderer); /* start with a blank canvas. */ 88 88 89 89 /* Just draw the static texture a few times. You can think of it like a
+1 -1
examples/renderer/08-rotating-textures/rotating-textures.c
··· 86 86 const float rotation = (((float) ((int) (now % 2000))) / 2000.0f) * 360.0f; 87 87 88 88 /* as you can see from this, rendering draws over whatever was drawn before it. */ 89 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 89 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 90 90 SDL_RenderClear(renderer); /* start with a blank canvas. */ 91 91 92 92 /* Center this one, and draw it with some rotation so it spins! */
+1 -1
examples/renderer/09-scaling-textures/scaling-textures.c
··· 86 86 const float scale = ((float) (((int) (now % 1000)) - 500) / 500.0f) * direction; 87 87 88 88 /* as you can see from this, rendering draws over whatever was drawn before it. */ 89 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 89 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 90 90 SDL_RenderClear(renderer); /* start with a blank canvas. */ 91 91 92 92 /* center this one and make it grow and shrink. */
+1 -1
examples/renderer/10-geometry/geometry.c
··· 89 89 int i; 90 90 91 91 /* as you can see from this, rendering draws over whatever was drawn before it. */ 92 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 92 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 93 93 SDL_RenderClear(renderer); /* start with a blank canvas. */ 94 94 95 95 /* Draw a single triangle with a different color at each vertex. Center this one and make it grow and shrink. */
+1 -1
examples/renderer/11-color-mods/color-mods.c
··· 86 86 const float blue = (float) (0.5 + 0.5 * SDL_sin(now + SDL_PI_D * 4 / 3)); 87 87 88 88 /* as you can see from this, rendering draws over whatever was drawn before it. */ 89 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 89 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 90 90 SDL_RenderClear(renderer); /* start with a blank canvas. */ 91 91 92 92 /* Just draw the static texture a few times. You can think of it like a
+1 -1
examples/renderer/14-viewport/viewport.c
··· 86 86 window. It does _not_ scale rendering to fit the viewport. */ 87 87 88 88 /* as you can see from this, rendering draws over whatever was drawn before it. */ 89 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 89 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 90 90 SDL_RenderClear(renderer); /* start with a blank canvas. */ 91 91 92 92 /* Draw once with the whole window as the viewport. */
+1 -1
examples/renderer/15-cliprect/cliprect.c
··· 116 116 /* okay, now draw! */ 117 117 118 118 /* Note that SDL_RenderClear is _not_ affected by the clipping rectangle! */ 119 - SDL_SetRenderDrawColor(renderer, 33, 33, 33, 255); /* grey, full alpha */ 119 + SDL_SetRenderDrawColor(renderer, 33, 33, 33, SDL_ALPHA_OPAQUE); /* grey, full alpha */ 120 120 SDL_RenderClear(renderer); /* start with a blank canvas. */ 121 121 122 122 /* stretch the texture across the entire window. Only the piece in the
+1 -1
examples/renderer/17-read-pixels/read-pixels.c
··· 96 96 const float rotation = (((float) ((int) (now % 2000))) / 2000.0f) * 360.0f; 97 97 98 98 /* as you can see from this, rendering draws over whatever was drawn before it. */ 99 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 99 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 100 100 SDL_RenderClear(renderer); /* start with a blank canvas. */ 101 101 102 102 /* Center this one, and draw it with some rotation so it spins! */
+4 -4
examples/renderer/18-debug-text/debug-text.c
··· 47 47 SDL_AppResult SDL_AppIterate(void *appstate) 48 48 { 49 49 /* as you can see from this, rendering draws over whatever was drawn before it. */ 50 - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */ 50 + SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); /* black, full alpha */ 51 51 SDL_RenderClear(renderer); /* start with a blank canvas. */ 52 52 53 - SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); /* white, full alpha */ 53 + SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ 54 54 SDL_RenderDebugText(renderer, 272, 100, "Hello world!"); 55 55 SDL_RenderDebugText(renderer, 224, 150, "This is some debug text."); 56 56 57 - SDL_SetRenderDrawColor(renderer, 51, 102, 255, 255); /* light blue, full alpha */ 57 + SDL_SetRenderDrawColor(renderer, 51, 102, 255, SDL_ALPHA_OPAQUE); /* light blue, full alpha */ 58 58 SDL_RenderDebugText(renderer, 184, 200, "You can do it in different colors."); 59 - SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); /* white, full alpha */ 59 + SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); /* white, full alpha */ 60 60 61 61 SDL_SetRenderScale(renderer, 4.0f, 4.0f); 62 62 SDL_RenderDebugText(renderer, 14, 65, "It can be scaled.");