|
| 1 | +/* |
| 2 | + * Copyright 2025 The Emscripten Authors. All rights reserved. |
| 3 | + * Emscripten is available under two separate licenses, the MIT license and the |
| 4 | + * University of Illinois/NCSA Open Source License. Both these licenses can be |
| 5 | + * found in the LICENSE file. |
| 6 | + */ |
| 7 | + |
| 8 | +#include <stdio.h> |
| 9 | +#include <SDL3/SDL.h> |
| 10 | +#include <SDL3/SDL_main.h> |
| 11 | +#include <SDL3_ttf/SDL_ttf.h> |
| 12 | + |
| 13 | +SDL_Window *window; |
| 14 | +SDL_Renderer *renderer; |
| 15 | +TTF_Font *font; |
| 16 | + |
| 17 | +#define WIDTH 640 |
| 18 | +#define HEIGHT 480 |
| 19 | + |
| 20 | +void render() { |
| 21 | + SDL_Color colorA = { 0xff, 0x99, 0x00, 0xff }; |
| 22 | + SDL_Color colorB = { 0x11, 0xff, 0xff, 0xff }; |
| 23 | + SDL_FRect upperRect = {0, 0, WIDTH, HEIGHT / 2}; |
| 24 | + SDL_FRect lowerRect = {0, HEIGHT / 2, WIDTH, HEIGHT / 2}; |
| 25 | + |
| 26 | + SDL_Surface *helloSurface = TTF_RenderText_Shaded(font, "hello", 0, colorA, colorB); |
| 27 | + SDL_Surface *worldSurface = TTF_RenderText_Shaded(font, "world", 0, colorB, colorA); |
| 28 | + SDL_Texture *helloTexture = SDL_CreateTextureFromSurface(renderer, helloSurface); |
| 29 | + SDL_Texture *worldTexture = SDL_CreateTextureFromSurface(renderer, worldSurface); |
| 30 | + |
| 31 | + SDL_SetRenderDrawColor(renderer, 0xcc, 0xcc, 0xcc, 0xff); |
| 32 | + SDL_RenderClear(renderer); |
| 33 | + SDL_RenderTexture(renderer, helloTexture, NULL, &upperRect); |
| 34 | + SDL_RenderTexture(renderer, worldTexture, NULL, &lowerRect); |
| 35 | + SDL_RenderPresent(renderer); |
| 36 | + |
| 37 | + SDL_DestroySurface(helloSurface); |
| 38 | + SDL_DestroySurface(worldSurface); |
| 39 | + SDL_DestroyTexture(helloTexture); |
| 40 | + SDL_DestroyTexture(worldTexture); |
| 41 | +} |
| 42 | + |
| 43 | +int main(int argc, char *argv[]) { |
| 44 | + SDL_Init(SDL_INIT_VIDEO); |
| 45 | + TTF_Init(); |
| 46 | + |
| 47 | + if (!SDL_CreateWindowAndRenderer("SDL3 TTF", WIDTH, HEIGHT, 0, &window, &renderer)) { |
| 48 | + printf("SDL_CreateWindowAndRenderer: %s\n", SDL_GetError()); |
| 49 | + return 1; |
| 50 | + } |
| 51 | + font = TTF_OpenFont("LiberationSansBold.ttf", 40); |
| 52 | + if (!font) { |
| 53 | + printf("TTF_OpenFont: %s\n", SDL_GetError()); |
| 54 | + return 1; |
| 55 | + } |
| 56 | + render(); |
| 57 | + |
| 58 | + return 0; |
| 59 | +} |
0 commit comments