Commit 2e54e7da authored by Craig Everett's avatar Craig Everett
Browse files

Update OpenGL and WX routines to work on R23 and R24

parent dc625e38
......@@ -3,6 +3,6 @@
{registered,[]},
{included_applications,[]},
{applications,[stdlib,kernel]},
{vsn,"0.1.2"},
{vsn,"0.1.3"},
{modules,[barnsley_fern,bf_con,bf_gui,bf_matrix,bf_sup]},
{mod,{barnsley_fern,[]}}]}.
......@@ -3,7 +3,7 @@
%%% @end
-module(barnsley_fern).
-vsn("0.1.2").
-vsn("0.1.3").
-behavior(application).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
......
......@@ -5,7 +5,7 @@
%%% @end
-module(bf_con).
-vsn("0.1.2").
-vsn("0.1.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("MIT").
......
......@@ -7,7 +7,7 @@
%%% @end
-module(bf_gui).
-vsn("0.1.2").
-vsn("0.1.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("MIT").
......@@ -24,6 +24,7 @@
-record(s,
{frame = none :: none | wx:wx_object(),
gl = new :: old | new,
slider = none :: none | wx:wx_object(),
button = none :: none | wx:wx_object(),
button_id = 0 :: integer(),
......@@ -31,10 +32,10 @@
points = [] :: [{number(), number()}],
tpin = none :: none | pin(),
rpin = none :: none | pin(),
tx = -2 :: number(),
ty = -2 :: number(),
rx = 0 :: number(),
ry = 0 :: number()}).
tx = -2.0 :: float(),
ty = -2.0 :: float(),
rx = 0.0 :: float(),
ry = 0.0 :: float()}).
-type state() :: term().
......@@ -101,18 +102,27 @@ init(Title) ->
ok = wxFrame:connect(Frame, command_button_clicked),
ok = wxFrame:center(Frame),
true = wxFrame:show(Frame),
ok = wxGLCanvas:setCurrent(Canvas),
GL =
case erlang:system_info(otp_release) >= "24" of
true ->
true = wxGLCanvas:setCurrent(Canvas, wxGLContext:new(Canvas)),
new;
false ->
ok = wxGLCanvas:setCurrent(Canvas),
old
end,
ok = gl:enable(?GL_DEPTH_TEST),
ok = gl:depthFunc(?GL_LESS),
ok = gl:enable(?GL_CULL_FACE),
ok = gl:enable(?GL_MULTISAMPLE),
ok = gl:cullFace(?GL_BACK),
State = #s{frame = Frame,
gl = GL,
slider = Slider,
button = Button,
button_id = ButtonID,
canvas = Canvas},
ok = draw(State),
_ = draw(State),
{Frame, State}.
draw(#s{frame = Frame, canvas = Canvas, points = Points,
......@@ -123,19 +133,19 @@ draw(#s{frame = Frame, canvas = Canvas, points = Points,
ok = gl:viewport(0, 0, W, H),
ok = gl:matrixMode(?GL_PROJECTION),
ok = gl:loadIdentity(),
ok = gl:ortho(-3, 3, -3 * H / W, 3 * H / W, -20, 20),
ok = gl:ortho(-3.0, 3.0, -3.0 * H / W, 3 * H / W, -20.0, 20.0),
ok = gl:matrixMode(?GL_MODELVIEW),
ok = gl:loadIdentity(),
ok = gl:clear(?GL_COLOR_BUFFER_BIT bor ?GL_DEPTH_BUFFER_BIT),
ok = gl:translatef(TX, TY, -3),
ok = gl:rotatef(-45, 0, 0, 1),
ok = gl:rotatef(RY, 1, 0, 0),
ok = gl:rotatef(RX, 0, 1, 0),
ok = gl:translatef(TX, TY, -3.0),
ok = gl:rotatef(-45.0, 0.0, 0.0, 1.0),
ok = gl:rotatef(RY, 1.0, 0.0, 0.0),
ok = gl:rotatef(RX, 0.0, 1.0, 0.0),
ok = gl:'begin'(?GL_LINES),
ok = gl:'end'(),
ok = gl:'begin'(?GL_POINTS),
ok = gl:color3f(1, 1, 1),
T = fun({X, Y}) -> gl:vertex3f(X / 2, Y / 2, 0) end,
ok = gl:color3f(1.0, 1.0, 1.0),
T = fun({X, Y}) -> gl:vertex3f(X / 2, Y / 2, 0.0) end,
L = fun(Ps) -> lists:foreach(T, Ps) end,
ok = lists:foreach(L, Points),
ok = gl:'end'(),
......@@ -167,7 +177,7 @@ handle_call(Unexpected, From, State) ->
handle_cast({show, Points, Iterations}, State) ->
NewState = do_show(Points, Iterations, State),
ok = draw(NewState),
_ = draw(NewState),
{noreply, NewState};
handle_cast(Unexpected, State) ->
ok = log(warning, "Unexpected cast: ~tp~n", [Unexpected]),
......@@ -200,12 +210,12 @@ handle_event(#wx{id = ButtonID, event = #wxCommand{type = command_button_clicked
ok = do_iterate(Slider),
{noreply, State};
handle_event(#wx{event = #wxPaint{}}, State) ->
ok = draw(State),
_ = draw(State),
{noreply, State};
handle_event(#wx{event = #wxMouse{type = motion, leftDown = true, x = X, y = Y}},
State) ->
NewState = do_traverse(X, Y, State),
ok = draw(NewState),
_ = draw(NewState),
{noreply, NewState};
handle_event(#wx{event = #wxMouse{type = motion, leftDown = false}},
State = #s{tpin = {_, _, _, _}}) ->
......@@ -213,7 +223,7 @@ handle_event(#wx{event = #wxMouse{type = motion, leftDown = false}},
handle_event(#wx{event = #wxMouse{type = motion, rightDown = true, x = X, y = Y}},
State) ->
NewState = do_rotate(X, Y, State),
ok = draw(NewState),
_ = draw(NewState),
{noreply, NewState};
handle_event(#wx{event = #wxMouse{type = motion, rightDown = false}},
State = #s{rpin = {_, _, _, _}}) ->
......
......@@ -6,7 +6,7 @@
%%% @end
-module(bf_matrix).
-vsn("0.1.2").
-vsn("0.1.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("MIT").
......
......@@ -12,7 +12,7 @@
%%% @end
-module(bf_sup).
-vsn("0.1.2").
-vsn("0.1.3").
-behaviour(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
......
......@@ -9,7 +9,7 @@
{license,"MIT"}.
{modules,[]}.
{name,"Barnsley's Fern"}.
{package_id,{"otpr","barnsley_fern",{0,1,2}}}.
{package_id,{"otpr","barnsley_fern",{0,1,3}}}.
{prefix,"bf"}.
{repo_url,"https://gitlab.com/zxq9/barnsleys-fern"}.
{tags,["fractal","gui","toy","fractals"]}.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment