40 #define TEXTURE_BACKDROP &tex2d[TEX_BACKDROP] |
40 #define TEXTURE_BACKDROP &tex2d[TEX_BACKDROP] |
41 |
41 |
42 #define BACKDROP_SCENE asc_window_scene(0) |
42 #define BACKDROP_SCENE asc_window_scene(0) |
43 #define MAIN_SCENE asc_window_scene(1) |
43 #define MAIN_SCENE asc_window_scene(1) |
44 |
44 |
45 static void destroy_textures(void *dummy) { |
45 static void destroy_textures(__attribute__((__unused__)) void *dummy) { |
46 asc_texture_destroy(tex2d, TEX2D_COUNT); |
46 asc_texture_destroy(tex2d, TEX2D_COUNT); |
47 } |
47 } |
48 |
48 |
49 static void init_textures(void) { |
49 static void init_textures(void) { |
50 asc_texture_init_2d(tex2d, TEX2D_COUNT); |
50 asc_texture_init_2d(tex2d, TEX2D_COUNT); |
68 } |
68 } |
69 } |
69 } |
70 // tie to bottom right of the screen |
70 // tie to bottom right of the screen |
71 if (asc_test_flag(node->flags, ASC_SCENE_NODE_GRAPHICS_UPDATED) |
71 if (asc_test_flag(node->flags, ASC_SCENE_NODE_GRAPHICS_UPDATED) |
72 || asc_active_window->resized) { |
72 || asc_active_window->resized) { |
73 asc_vec2i bottom_right = asc_active_window->dimensions; |
73 asc_vec2u bottom_right = asc_active_window->dimensions; |
74 asc_vec2i scale = asc_get_scale2d(node); |
74 // TODO: replace scale with asc_text_get_size() |
|
75 asc_vec3f text_size = node->scale; |
75 asc_set_position2d( |
76 asc_set_position2d( |
76 node, |
77 node, |
77 bottom_right.x - scale.width - 10, |
78 (int)bottom_right.x - (int)text_size.width - 10, |
78 bottom_right.y - scale.height - 10 |
79 (int)bottom_right.y - (int)text_size.height - 10 |
79 ); |
80 ); |
80 } |
81 } |
81 } |
82 } |
82 |
83 |
83 static void scale_backdrop(AscSceneNode *node) { |
84 static void scale_backdrop(AscSceneNode *node) { |
84 // scale the backdrop to the size of the window |
85 // scale the backdrop to the size of the window |
85 if (asc_active_window->resized) { |
86 if (asc_active_window->resized) { |
86 asc_vec2i window_size = asc_active_window->dimensions; |
87 asc_vec2u window_size = asc_active_window->dimensions; |
87 asc_set_scale2d(node, window_size.width, window_size.height); |
88 // TODO: replace scale with asc_sprite_set_size() |
|
89 asc_set_scale(node, (float)window_size.width, (float)window_size.height, 1); |
88 // TODO: implement texture repetition |
90 // TODO: implement texture repetition |
89 } |
91 } |
90 } |
92 } |
91 |
93 |
92 static void create_backdrop(void) { |
94 static void create_backdrop(void) { |
124 asc_scene_add_node(MAIN_SCENE, sprite); |
126 asc_scene_add_node(MAIN_SCENE, sprite); |
125 |
127 |
126 // TODO: return something |
128 // TODO: return something |
127 } |
129 } |
128 |
130 |
129 static asc_recti update_viewport_for_window_resize(asc_vec2i window_size) { |
131 static asc_recti update_viewport_for_window_resize(asc_vec2u window_size) { |
130 // Compute scaling and offsets |
132 // Compute scaling and offsets |
131 int viewport_size, offset_x = 0, offset_y = 0; |
133 unsigned viewport_size, offset_x = 0, offset_y = 0; |
132 if (window_size.width > window_size.height) { |
134 if (window_size.width > window_size.height) { |
133 // Wider window: letterbox (black bars on top/bottom) |
135 // Wider window: letterbox (black bars on top/bottom) |
134 offset_x = (window_size.width - window_size.height) / 2; |
136 offset_x = (window_size.width - window_size.height) / 2; |
135 viewport_size = window_size.height; |
137 viewport_size = window_size.height; |
136 } else { |
138 } else { |
138 offset_y = (window_size.height - window_size.width) / 2; |
140 offset_y = (window_size.height - window_size.width) / 2; |
139 viewport_size = window_size.width; |
141 viewport_size = window_size.width; |
140 } |
142 } |
141 |
143 |
142 // Set the viewport to the scaled and centered region |
144 // Set the viewport to the scaled and centered region |
143 return (asc_recti){ |
145 return asc_recti_new(offset_x, offset_y, viewport_size, viewport_size); |
144 offset_x, |
146 } |
145 offset_y, |
147 |
146 viewport_size, |
148 int main(void) { |
147 viewport_size |
|
148 }; |
|
149 } |
|
150 |
|
151 int main(int argc, char** argv) { |
|
152 asc_context_initialize(); |
149 asc_context_initialize(); |
153 if (asc_has_error()) { |
150 if (asc_has_error()) { |
154 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, |
151 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, |
155 "Fatal Error",asc_get_error(), NULL); |
152 "Fatal Error",asc_get_error(), NULL); |
156 return 1; |
153 return 1; |
176 .type = ASC_CAMERA_ORTHO, |
173 .type = ASC_CAMERA_ORTHO, |
177 .projection_update_func = asc_camera_ortho_update_size |
174 .projection_update_func = asc_camera_ortho_update_size |
178 }); |
175 }); |
179 asc_scene_init(MAIN_SCENE, (AscCameraParams) { |
176 asc_scene_init(MAIN_SCENE, (AscCameraParams) { |
180 .type = ASC_CAMERA_ORTHO, |
177 .type = ASC_CAMERA_ORTHO, |
181 .ortho.rect = (asc_recti){0, 0, game_field_size, game_field_size}, |
178 .ortho.rect = asc_recti_new(0, 0, game_field_size, game_field_size), |
182 .viewport_update_func = update_viewport_for_window_resize |
179 .viewport_update_func = update_viewport_for_window_resize |
183 }); |
180 }); |
184 |
181 |
185 // backdrop for letterbox/pillarbox |
182 // backdrop for letterbox/pillarbox |
186 create_backdrop(); |
183 create_backdrop(); |