-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_aimg.m
More file actions
43 lines (34 loc) · 1.53 KB
/
upload_aimg.m
File metadata and controls
43 lines (34 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
:- module upload_aimg.
%==============================================================================%
% Helper glue between AImg and OpenGL.
:- interface.
%==============================================================================%
:- use_module io.
:- use_module opengl.
:- use_module mglow.
:- use_module aimg.
%------------------------------------------------------------------------------%
:- type result ---> ok(opengl.texture) ; nofile ; badfile.
:- pred load(io.io::di, io.io::uo, string::in, result::out,
mglow.window::di, mglow.window::uo) is det.
:- pred upload(aimg.texture::in, opengl.texture::out,
mglow.window::di, mglow.window::uo) is det.
:- pred load(aimg.result::in, result::out,
mglow.window::di, mglow.window::uo) is det.
%==============================================================================%
:- implementation.
%==============================================================================%
load(aimg.nofile, nofile, !Window).
load(aimg.badfile, badfile, !Window).
load(aimg.ok(AImgTex), ok(GLTex), !Window) :- upload(AImgTex, GLTex, !Window).
load(!IO, Path, Result, !Window) :-
aimg.load(!IO, Path, AImgResult),
load(AImgResult, Result, !Window).
upload(AImgTex, Tex, !Window) :-
Pix = aimg.pixels(AImgTex),
W = aimg.width(AImgTex),
H = aimg.height(AImgTex),
opengl.upload_texture(Tex, Pix, W, H, !Window),
opengl.bind_texture(Tex, !Window),
opengl.texture_filter(opengl.min_filter, opengl.linear, !Window),
opengl.texture_filter(opengl.mag_filter, opengl.linear, !Window).