2323#include "music_data.h"
2424#endif
2525
26- #define WIDTH 800
27- #define HEIGHT 600
26+ /* Base dimensions - can be overridden at runtime */
27+ static int WIDTH = 800 ;
28+ static int HEIGHT = 600 ;
29+
2830#define PI 3.14159265358979323846
2931#define NUM_STARS 200
3032#define MAX_LOGO_PARTICLES 8192
@@ -1128,15 +1130,25 @@ int main(int argc, char *argv[])
11281130 int scene_list [6 ];
11291131 int num_scenes = 0 ;
11301132
1133+ /* Window/display settings */
1134+ int fullscreen = 0 ;
1135+ int window_width = 0 ; /* 0 = auto-detect */
1136+ int window_height = 0 ;
1137+ int scale_factor = 1 ;
1138+ int auto_resolution = 1 ; /* Auto-detect and adapt resolution */
1139+
11311140 /* Parse command-line arguments */
11321141 ctx .scene_duration = 15000 ; /* Default: 15 seconds per scene */
11331142
11341143 for (int i = 1 ; i < argc ; i ++ ) {
11351144 if (strcmp (argv [i ], "--help" ) == 0 || strcmp (argv [i ], "-h" ) == 0 ) {
11361145 printf ("Usage: %s [OPTIONS] [SCENE...]\n" , argv [0 ]);
11371146 printf ("\nOptions:\n" );
1138- printf (" -h, --help Show this help message\n" );
1147+ printf (" -h, --help Show this help message\n" );
11391148 printf (" -d, --duration SEC Set scene duration in seconds (default: 15)\n" );
1149+ printf (" -f, --fullscreen Run in fullscreen mode\n" );
1150+ printf (" -w, --window WxH Set window size (e.g., 1920x1080)\n" );
1151+ printf (" -s, --scale N Integer scaling factor (e.g., 2 = 1600x1200)\n" );
11401152 printf ("\nScenes:\n" );
11411153 printf (" 0 - Starfield\n" );
11421154 printf (" 1 - Plasma\n" );
@@ -1175,6 +1187,49 @@ int main(int argc, char *argv[])
11751187 return 1 ;
11761188 }
11771189 }
1190+ else if (strcmp (argv [i ], "-f" ) == 0 || strcmp (argv [i ], "--fullscreen" ) == 0 ) {
1191+ fullscreen = 1 ;
1192+ }
1193+ else if (strcmp (argv [i ], "-w" ) == 0 || strcmp (argv [i ], "--window" ) == 0 ) {
1194+ if (i + 1 >= argc ) {
1195+ fprintf (stderr , "Error: %s requires an argument\n" , argv [i ]);
1196+ IMG_Quit ();
1197+ TTF_Quit ();
1198+ SDL_Quit ();
1199+ return 1 ;
1200+ }
1201+ if (sscanf (argv [++ i ], "%dx%d" , & window_width , & window_height ) != 2 ) {
1202+ fprintf (stderr , "Error: Invalid window size '%s'. Use format WxH (e.g., 1920x1080)\n" , argv [i ]);
1203+ IMG_Quit ();
1204+ TTF_Quit ();
1205+ SDL_Quit ();
1206+ return 1 ;
1207+ }
1208+ /* Adapt render resolution to match aspect ratio */
1209+ float aspect = (float )window_width / window_height ;
1210+ WIDTH = 800 ;
1211+ HEIGHT = (int )(800.0f / aspect );
1212+ auto_resolution = 0 ; /* Manual window size disables auto-detection */
1213+ }
1214+ else if (strcmp (argv [i ], "-s" ) == 0 || strcmp (argv [i ], "--scale" ) == 0 ) {
1215+ if (i + 1 >= argc ) {
1216+ fprintf (stderr , "Error: %s requires an argument\n" , argv [i ]);
1217+ IMG_Quit ();
1218+ TTF_Quit ();
1219+ SDL_Quit ();
1220+ return 1 ;
1221+ }
1222+ scale_factor = atoi (argv [++ i ]);
1223+ if (scale_factor < 1 ) {
1224+ fprintf (stderr , "Error: Invalid scale factor '%s'. Must be >= 1\n" , argv [i ]);
1225+ IMG_Quit ();
1226+ TTF_Quit ();
1227+ SDL_Quit ();
1228+ return 1 ;
1229+ }
1230+ window_width = WIDTH * scale_factor ;
1231+ window_height = HEIGHT * scale_factor ;
1232+ }
11781233 else {
11791234 /* Non-option argument - treat as scene number */
11801235 int scene = atoi (argv [i ]);
@@ -1219,11 +1274,52 @@ int main(int argc, char *argv[])
12191274 ctx .current_scene = ctx .scene_list [0 ];
12201275 }
12211276
1277+ /* Set scaling quality hint before creating renderer */
1278+ SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY , "1" );
1279+
1280+ /* Auto-detect display resolution and adapt if needed */
1281+ if (auto_resolution || fullscreen ) {
1282+ SDL_DisplayMode dm ;
1283+ if (SDL_GetCurrentDisplayMode (0 , & dm ) == 0 ) {
1284+ if (fullscreen ) {
1285+ /* Use native display resolution */
1286+ window_width = dm .w ;
1287+ window_height = dm .h ;
1288+ } else if (window_width == 0 ) {
1289+ /* Auto-size window to 80% of display */
1290+ window_width = dm .w * 0.8 ;
1291+ window_height = dm .h * 0.8 ;
1292+ }
1293+
1294+ /* Adapt internal resolution to match display aspect ratio */
1295+ float display_aspect = (float )dm .w / dm .h ;
1296+
1297+ /* Always adapt to match display aspect ratio */
1298+ WIDTH = 800 ;
1299+ HEIGHT = (int )(800.0f / display_aspect );
1300+
1301+ /* fprintf(stderr, "Display: %dx%d (aspect %.2f), Internal: %dx%d\n", */
1302+ /* dm.w, dm.h, display_aspect, WIDTH, HEIGHT); */
1303+ }
1304+ }
1305+
1306+ /* Default window size if not set */
1307+ if (window_width == 0 ) window_width = WIDTH ;
1308+ if (window_height == 0 ) window_height = HEIGHT ;
1309+
1310+ /* fprintf(stderr, "Window: %dx%d, Render: %dx%d\n", */
1311+ /* window_width, window_height, WIDTH, HEIGHT); */
1312+
1313+ Uint32 window_flags = SDL_WINDOW_SHOWN ;
1314+ if (fullscreen ) {
1315+ window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP ;
1316+ }
1317+
12221318 ctx .window = SDL_CreateWindow ("Infix Container Demo" ,
12231319 SDL_WINDOWPOS_CENTERED ,
12241320 SDL_WINDOWPOS_CENTERED ,
1225- WIDTH , HEIGHT ,
1226- SDL_WINDOW_SHOWN );
1321+ window_width , window_height ,
1322+ window_flags );
12271323
12281324 if (!ctx .window ) {
12291325 fprintf (stderr , "Window creation failed: %s\n" , SDL_GetError ());
@@ -1234,6 +1330,10 @@ int main(int argc, char *argv[])
12341330
12351331 ctx .renderer = SDL_CreateRenderer (ctx .window , -1 ,
12361332 SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
1333+
1334+ /* Set logical rendering size - render at adapted resolution, display scales automatically */
1335+ SDL_RenderSetLogicalSize (ctx .renderer , WIDTH , HEIGHT );
1336+
12371337 ctx .texture = SDL_CreateTexture (ctx .renderer ,
12381338 SDL_PIXELFORMAT_ARGB8888 ,
12391339 SDL_TEXTUREACCESS_STREAMING ,
0 commit comments