main.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // ../../make --run
  2. function main() {
  3. let ops: iron_window_options_t = {
  4. title: "Empty",
  5. width: 1280,
  6. height: 720,
  7. x: -1,
  8. y: -1,
  9. features: window_features_t.RESIZABLE | window_features_t.MINIMIZABLE | window_features_t.MAXIMIZABLE,
  10. mode: window_mode_t.WINDOWED,
  11. frequency: 60,
  12. vsync: true,
  13. depth_bits: 32
  14. };
  15. sys_start(ops);
  16. ready();
  17. }
  18. function render_commands() {
  19. render_path_set_target("", null, null, clear_flag_t.COLOR | clear_flag_t.DEPTH, 0xff6495ed, 1.0);
  20. render_path_draw_meshes("mesh");
  21. }
  22. function ready() {
  23. render_path_commands = render_commands;
  24. let scene: scene_t = {
  25. name: "Scene",
  26. objects: [
  27. {
  28. name: "Cube",
  29. type: "mesh_object",
  30. data_ref: "cube.arm/Cube",
  31. material_refs: ["MyMaterial"],
  32. visible: true,
  33. spawn: true
  34. },
  35. {
  36. name: "Camera",
  37. type: "camera_object",
  38. data_ref: "MyCamera",
  39. visible: true,
  40. spawn: true
  41. }
  42. ],
  43. camera_datas: [
  44. {
  45. name: "MyCamera",
  46. near_plane: 0.1,
  47. far_plane: 100.0,
  48. fov: 0.85
  49. }
  50. ],
  51. camera_ref: "Camera",
  52. material_datas: [
  53. {
  54. name: "MyMaterial",
  55. shader: "MyShader",
  56. contexts: [
  57. {
  58. name: "mesh",
  59. bind_textures: [
  60. {
  61. name: "my_texture",
  62. file: "texture.k"
  63. }
  64. ]
  65. }
  66. ]
  67. }
  68. ],
  69. shader_datas: [
  70. {
  71. name: "MyShader",
  72. contexts: [
  73. {
  74. name: "mesh",
  75. vertex_shader: "mesh.vert",
  76. fragment_shader: "mesh.frag",
  77. compare_mode: "less",
  78. cull_mode: "clockwise",
  79. depth_write: true,
  80. vertex_elements: [
  81. {
  82. name: "pos",
  83. data: "short4norm"
  84. },
  85. {
  86. name: "tex",
  87. data: "short2norm"
  88. }
  89. ],
  90. constants: [
  91. {
  92. name: "WVP",
  93. type: "mat4",
  94. link: "_world_view_proj_matrix"
  95. }
  96. ],
  97. texture_units: [
  98. {
  99. name: "my_texture"
  100. }
  101. ]
  102. }
  103. ]
  104. }
  105. ]
  106. };
  107. map_set(data_cached_scene_raws, scene.name, scene);
  108. // Instantiate scene
  109. scene_create(scene);
  110. scene_ready();
  111. }
  112. function scene_ready() {
  113. // Set camera
  114. let t: transform_t = scene_camera.base.transform;
  115. t.loc = vec4_create(0, -6, 0);
  116. t.rot = quat_from_to(vec4_create(0, 0, 1), vec4_create(0, -1, 0));
  117. transform_build_matrix(t);
  118. // Rotate cube
  119. sys_notify_on_update(spin_cube);
  120. }
  121. function spin_cube() {
  122. let cube: object_t = scene_get_child("Cube");
  123. transform_rotate(cube.transform, vec4_create(0, 0, 1), 0.01);
  124. }
  125. function tr(id: string, vars: map_t<string, string> = null): string {}