web compilation

This commit is contained in:
2025-12-29 13:43:05 +01:00
parent adb6b8b315
commit fa9d871479
11 changed files with 1976 additions and 23 deletions

68
main.c
View File

@ -2,6 +2,9 @@
#include <math.h>
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
#define UI_WIDTH 450
#define COLOR_BG (Color){ 25, 25, 30, 255 }
@ -450,14 +453,44 @@ void DrawControlPanel(Michelson *mic) {
DrawText(TextFormat("%i FPS", fps), startX + 100, bottomY + 12, 20, fpsColor);
}
Michelson mic = {0};
Shader shader;
bool isFullscreen = false;
Rectangle normalBounds = {0};
Rectangle fullScreenBounds = {0};
void UpdateDrawFrame(void) {
if (IsKeyPressed(KEY_F)) {
isFullscreen = !isFullscreen;
}
Rectangle currentViewBounds = isFullscreen ? fullScreenBounds : normalBounds;
BeginDrawing();
ClearBackground(COLOR_BG);
// Grille fond
for(int i = UI_WIDTH; i < 1920; i += 100) DrawLine(i, 0, i, 1080, Fade(WHITE, 0.05f));
for(int i = 0; i < 1080; i += 100) DrawLine(UI_WIDTH, i, 1920, i, Fade(WHITE, 0.05f));
DrawMichelsonSchema(&mic);
DrawControlPanel(&mic);
DrawInterferenceViewGPU(&mic, currentViewBounds, shader, &isFullscreen);
EndDrawing();
}
int main () {
//SetConfigFlags(FLAG_MSAA_4X_HINT);
#if !defined(PLATFORM_WEB)
SetConfigFlags(FLAG_MSAA_4X_HINT);
#endif
InitWindow(1920, 1080, "Interferometre de Michelson");
SetTargetFPS(144);
Shader shader = LoadShader(0, "michelson.frag");
#if defined(PLATFORM_WEB)
shader = LoadShader(0, "michelson_web.frag");
#else
shader = LoadShader(0, "michelson.frag");
#endif
Michelson mic = {0};
mic.center = (Vector2){ UI_WIDTH + (1920 - UI_WIDTH) / 2.0f - 100, 1080 / 2.0f };
mic.d1 = 250.0f;
mic.d2 = 250.0f;
@ -469,28 +502,17 @@ int main () {
mic.nGaz = 1.0f;
mic.gaz = false;
bool isFullscreen = false;
Rectangle normalBounds = {1920 - 530, 50, 500, 500};
Rectangle fullScreenBounds = {UI_WIDTH + 10, 40, 1920 - UI_WIDTH - 20, 1030};
//Rectangle screenViewBounds = {400, 0, 1080, 1080};
while (!WindowShouldClose()) {
if (IsKeyPressed(KEY_F)) {
isFullscreen = !isFullscreen;
normalBounds = (Rectangle){1920 - 530, 50, 500, 500};
fullScreenBounds = (Rectangle){UI_WIDTH + 10, 40, 1920 - UI_WIDTH - 20, 1030};
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else
while (!WindowShouldClose()) {
UpdateDrawFrame();
}
Rectangle currentViewBounds = isFullscreen ? fullScreenBounds : normalBounds;
BeginDrawing();
ClearBackground(COLOR_BG);
// Grille fond
for(int i = UI_WIDTH; i < 1920; i += 100) DrawLine(i, 0, i, 1080, Fade(WHITE, 0.05f));
for(int i = 0; i < 1080; i += 100) DrawLine(UI_WIDTH, i, 1920, i, Fade(WHITE, 0.05f));
DrawMichelsonSchema(&mic);
DrawControlPanel(&mic);
DrawInterferenceViewGPU(&mic, currentViewBounds, shader, &isFullscreen);
EndDrawing();
}
#endif
CloseWindow();
return 0;
}