GPU processing
This commit is contained in:
44
main.c
44
main.c
@ -41,7 +41,7 @@ void DrawLaserBeam(Vector2 start, Vector2 end, Color color, float thickness) {
|
||||
DrawLineEx(start, end, thickness, color);
|
||||
}
|
||||
|
||||
void DrawInterferenceView(Michelson *mic, Rectangle rec) {
|
||||
void DrawInterferenceViewCPU(Michelson *mic, Rectangle rec) {
|
||||
DrawRectangleRec((Rectangle){rec.x - 4, rec.y - 30, rec.width + 8, rec.height + 34}, COLOR_PANEL);
|
||||
//DrawText("ECRAN", rec.x, rec.y - 30, 20, WHITE);
|
||||
DrawText("ECRAN", rec.x, rec.y - 26, 20, COLOR_TEXT_DIM);
|
||||
@ -93,6 +93,40 @@ void DrawInterferenceView(Michelson *mic, Rectangle rec) {
|
||||
DrawLine(cx, cy - 10, cx, cy + 10, Fade(WHITE, 0.5f));
|
||||
}
|
||||
|
||||
void DrawInterferenceViewGPU(Michelson *mic, Rectangle rec, Shader shader) {
|
||||
|
||||
DrawRectangleRec((Rectangle){rec.x - 4, rec.y - 30, rec.width + 8, rec.height + 34}, COLOR_PANEL);
|
||||
DrawText("ECRAN", rec.x, rec.y - 26, 20, COLOR_TEXT_DIM);
|
||||
|
||||
// Shader glsl
|
||||
float centerX = rec.x + rec.width / 2.0f;
|
||||
float centerY = rec.y + rec.height / 2.0f;
|
||||
float center[2] = { centerX, centerY };
|
||||
float scrHeight = (float)GetScreenHeight();
|
||||
|
||||
//
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "center"), center, SHADER_UNIFORM_VEC2);
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "screenHeight"), &scrHeight, SHADER_UNIFORM_FLOAT);
|
||||
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "d1"), &mic->d1, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "d2"), &mic->d2, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "lambda"), &mic->lambda, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, GetShaderLocation(shader, "angleM1"), &mic->angleM1, SHADER_UNIFORM_FLOAT);
|
||||
|
||||
// GPU
|
||||
BeginShaderMode(shader);
|
||||
DrawRectangleRec(rec, WHITE);
|
||||
EndShaderMode();
|
||||
|
||||
DrawRectangleLinesEx(rec, 1, Fade(COLOR_ACCENT, 0.3f));
|
||||
DrawRectangleLinesEx(rec, 2, COLOR_PANEL);
|
||||
|
||||
int cx = rec.x + rec.width / 2;
|
||||
int cy = rec.y + rec.height / 2;
|
||||
DrawLine(cx - 10, cy, cx + 10, cy, Fade(WHITE, 0.5f));
|
||||
DrawLine(cx, cy - 10, cx, cy + 10, Fade(WHITE, 0.5f));
|
||||
}
|
||||
|
||||
void DrawMichelsonSchema (Michelson *mic) {
|
||||
Vector2 c = mic->center;
|
||||
Color laserColor = WavelengthToColor(mic->lambda);
|
||||
@ -231,6 +265,8 @@ int main () {
|
||||
InitWindow(1920, 1080, "Interferometre de Michelson");
|
||||
SetTargetFPS(144);
|
||||
|
||||
Shader shader = LoadShader(0, "michelson.fs");
|
||||
|
||||
Michelson mic = {0};
|
||||
mic.center = (Vector2){ UI_WIDTH + (1920 - UI_WIDTH) / 2.0f - 100, 1080 / 2.0f };
|
||||
mic.d1 = 250.0f;
|
||||
@ -245,12 +281,12 @@ int main () {
|
||||
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));
|
||||
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);
|
||||
DrawInterferenceView(&mic, screenViewBounds);
|
||||
DrawInterferenceViewGPU(&mic, screenViewBounds, shader);
|
||||
EndDrawing();
|
||||
}
|
||||
CloseWindow();
|
||||
|
||||
Reference in New Issue
Block a user