Skip to content

Commit

Permalink
fix: use double functions and cast floats where necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Jabolol committed Jan 17, 2025
1 parent c9d4b28 commit cece586
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions examples/graphical.ff → examples/mobius.ff
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
%%
% MacOS:
% ./glados -i examples/graphical.ff -o mobius.ll
% clang mobius.ll -o mobius -I/opt/homebrew/include -L/opt/homebrew/lib -lsdl2 -framework OpenGL
% ./mobius
%
% Linux:
% TODO(jabolo): Test this on Linux
% SDL2 + OpenGL example of a 3D Möbius Strip
%%

%%
% Standard Library
%%
import "std/io.ff"
import "std/lib.ff"
Expand All @@ -17,6 +15,11 @@ WIDTH: int = 800
HEIGHT: int = 600
PI: double = 3,14159265359

%%
% Function to draw a 3D Möbius Strip
%
% A Möbius Strip is a surface with only one side and only one boundary.
%%
draw_mobius_strip: double -> never = time {
u_steps: int = 100
v_steps: int = 50
Expand Down Expand Up @@ -52,14 +55,17 @@ draw_mobius_strip: double -> never = time {
g: double = 0,5 + 0,5 * sin(e)
b: double = 0,7

glColor3f(r g b)
glVertex3f(x y z)
glColor3d(r g b)
glVertex3d(x y z)
}
}
glEnd()
}
}

%%
% Function to initialize OpenGL
%%
init_open_gl: never -> never = {
SCREEN_RATIO: double = @double(WIDTH) / @double(HEIGHT)

Expand All @@ -71,9 +77,13 @@ init_open_gl: never -> never = {
gluPerspective(45,0 SCREEN_RATIO 0,1 100,0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glClearColor(0,2 0,3 0,3 1,0)

glClearColor(@float(0,2) @float(0,3) @float(0,3) @float(1,0))
}

%%
% Main function
%%
main: never -> int = {
if SDL_Init(SDL_INIT_VIDEO) < 0 {
ret 1
Expand Down Expand Up @@ -135,8 +145,8 @@ main: never -> int = {
glLoadIdentity()

gluLookAt(0,0 0,0 5,0 0,0 0,0 0,0 0,0 1,0 0,0)
glRotatef(angle_y 0,0 1,0 0,0)
glRotatef(angle_x 1,0 0,0 0,0)
glRotated(angle_y 0,0 1,0 0,0)
glRotated(angle_x 1,0 0,0 0,0)

draw_mobius_strip(time)

Expand Down

0 comments on commit cece586

Please # to comment.