Skip to content

Instantly share code, notes, and snippets.

@ljmccarthy
Created September 20, 2024 09:05
Show Gist options
  • Save ljmccarthy/a08a8ad0cf6853cbb0805ac4592f8135 to your computer and use it in GitHub Desktop.
Save ljmccarthy/a08a8ad0cf6853cbb0805ac4592f8135 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <inttypes.h>
#include <SDL2/SDL.h>
int main()
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow("SDL Test", 0, 0, 320, 240, SDL_WINDOW_SHOWN);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, 8, 8);
SDL_RendererInfo info;
SDL_GetRendererInfo(renderer, &info);
printf("Name: %s\n", info.name);
printf("Flags: 0x%08x\n", info.flags);
printf("Max Texture Size: %d x %d\n", info.max_texture_width, info.max_texture_height);
printf("Texture Formats:\n");
for (Uint32 i = 0; i < info.num_texture_formats; i++) {
Uint32 fmt = info.texture_formats[i];
printf(" %"PRIx32" bpp:%d layout:%d order:%d type:%d flag:%d\n",
fmt,
SDL_BITSPERPIXEL(fmt),
SDL_PIXELLAYOUT(fmt),
SDL_PIXELORDER(fmt),
SDL_PIXELTYPE(fmt),
SDL_PIXELFLAG(fmt));
}
printf("SDL_PIXELFORMAT_RGB888 = %"PRIx32"\n", SDL_PIXELFORMAT_RGB888);
printf("SDL_PIXELFORMAT_RGBA8888 = %"PRIx32"\n", SDL_PIXELFORMAT_RGBA8888);
printf("SDL_PIXELFORMAT_ARGB8888 = %"PRIx32"\n", SDL_PIXELFORMAT_ARGB8888);
printf("SDL_PIXELFORMAT_RGBX8888 = %"PRIx32"\n", SDL_PIXELFORMAT_RGBX8888);
printf("SDL_PIXELFORMAT_XRGB8888 = %"PRIx32"\n", SDL_PIXELFORMAT_XRGB8888);
Uint32 format;
int access, w, h;
SDL_QueryTexture(texture, &format, &access, &w, &h);
printf("Texture format: %"PRIx32"\n", format);
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment