128 asc_scene_add_node(MAIN_SCENE, sprite); |
128 asc_scene_add_node(MAIN_SCENE, sprite); |
129 |
129 |
130 // TODO: return something |
130 // TODO: return something |
131 } |
131 } |
132 |
132 |
133 static asc_recti update_viewport_for_window_resize(asc_vec2u window_size) { |
133 static asc_rect update_viewport_for_window_resize(asc_vec2u window_size) { |
134 // Compute scaling and offsets |
134 // Compute scaling and offsets |
135 unsigned viewport_size, offset_x = 0, offset_y = 0; |
135 unsigned viewport_size, offset_x = 0, offset_y = 0; |
136 if (window_size.width > window_size.height) { |
136 if (window_size.width > window_size.height) { |
137 // Wider window: letterbox (black bars on top/bottom) |
137 // Wider window: letterbox (black bars on top/bottom) |
138 offset_x = (window_size.width - window_size.height) / 2; |
138 offset_x = (window_size.width - window_size.height) / 2; |
142 offset_y = (window_size.height - window_size.width) / 2; |
142 offset_y = (window_size.height - window_size.width) / 2; |
143 viewport_size = window_size.width; |
143 viewport_size = window_size.width; |
144 } |
144 } |
145 |
145 |
146 // Set the viewport to the scaled and centered region |
146 // Set the viewport to the scaled and centered region |
147 return ASC_RECTI(offset_x, offset_y, viewport_size, viewport_size); |
147 return ASC_RECT(offset_x, offset_y, viewport_size, viewport_size); |
148 } |
148 } |
149 |
149 |
150 int main(void) { |
150 int main(void) { |
151 asc_context_initialize(); |
151 asc_context_initialize(); |
152 if (asc_has_error()) { |
152 if (asc_has_error()) { |
177 .projection_update_func = asc_camera_ortho_update_size |
177 .projection_update_func = asc_camera_ortho_update_size |
178 ); |
178 ); |
179 asc_ink_rgb(0, 128, 90); |
179 asc_ink_rgb(0, 128, 90); |
180 asc_scene_init(MAIN_SCENE, |
180 asc_scene_init(MAIN_SCENE, |
181 .type = ASC_CAMERA_ORTHO, |
181 .type = ASC_CAMERA_ORTHO, |
182 .ortho.rect = ASC_RECTI(0, 0, game_field_size, game_field_size), |
182 .ortho.rect = ASC_RECT(0, 0, game_field_size, game_field_size), |
183 .viewport_clear = true, |
183 .viewport_clear = true, |
184 .viewport_update_func = update_viewport_for_window_resize |
184 .viewport_update_func = update_viewport_for_window_resize |
185 ); |
185 ); |
186 |
186 |
187 // backdrop for letterbox/pillarbox |
187 // backdrop for letterbox/pillarbox |