Skip to main content

Game: texture

node.ex.texture.create - new texture

tex0:=node.ex.texture.create(u0, w,h);
tex0:=node.ex.texture.create.fmt(r0, tw,th, node.ex.texture.fmt.rgb565, 1);

texture parameters

 ex.texture.p {
# setters
filter.min 0;
filter.mag 1;
wrap.s 2;
wrap.t 3;
# getters
width 1000;
height 1000+1;
};
ex.texture.v {
filter.nearest 0;
filter.linear 1;
wrap.repeat 2;
wrap.clamp.to.edge 3;
wrap.mirrored.repeat 4;
};

node.ex.texture.get.param

node.ex.texture.get.param(u0, _0, node.ex.texture.p.width);

node.ex.texture.set.param

node.ex.texture.get.param(u0, _0, node.ex.texture.p.wrap.s, node.ex.texture.v.wrap.repeat);

node.texture.width

node.texture.width(tex0);

node.texture.height

node.texture.width(tex0);

filter

gl.texture.filter.nearest

gl.texture.filter.nearest(tex0);

gl.texture.filter.linear

gl.texture.filter.linear(tex0);

Example texture

Node texture

_ @4;

tex0 0;

if (r0) {
create.texture {
tex0:=node.ex.texture.create(u0, w,h);
node.value.s(u0, nid,0, tex0);
};
create.texture;
};

_ @sys.obj.key;
_ @sys.shader.ex;

shader.set.uniform.v2(nid, iResolution, w,h);

draw(r0, 900785);

Draw formula texture

### 900785 basic.ui.shader.node3.draw

_ @4;
_ @900776;
_ @1100;
_ @util.gl.std;

_ @sys.obj.key;
_ @sys.shader.ex;

tex0 r1;

vsh0 r2;
fsh0 r3;

node.ex.gl.fbo(u0, tex0);
node.ex.gl.clear(u0, 0,0,0,0);

gl.shader.use(vsh0,fsh0);

shader.load.uniforms(u0, nid);

gl.rect0(5, 0,0, w,h);
node.ex.gl.fbo(u0, -1);

gl.rect0.texture(5, 0,0, w,h, tex0);

texture loader

Load textures from storage

_ @sys.storage;

texture.loader {
load.texture {
# tex, pool,id,i
tex _0;
tex:=storage.image.load.texture(_1,_2,_3);
};
init {
# r0, tex, pool,id,i
if (_0) {
load.texture(_1, _2,_3,_4);
};
};
update {
# b0, tex, pool,id
l0 _0;
tex _1;
pool _2;
id _3;
l0:=storage.get.event(0);
if (l0==storage.e.new.file) {
load.texture(tex, o1,o2,o3);
};
};
};

load.texture {
# tex, pool,id,i
tex0 _0;
tex0:=storage.image.load.texture(_1,_2,_3);
};

tex0 0;

if (r0) {
load.texture(tex0, pool0,id0,i0);
};

draw texture

Draw

### 93323 nodes.image.draw 

_ @1010;
_ @sys.node;
_ @sys.display;
_ @1100;
_ @util.gl.std;

tex0 r5;

gl.draw.texture.rect0 {
# tex, x,y, w,h
gl.shader.use(70014,150015);
gl.shader.uniform.texture(0, tex0, 0);
gl.rect0(5, 0,h, w,-h);
};

gl.draw.texture.rect0(tex0, 0,0,w,h);

render children to fbo

node

### texture.node
tex0 r1;
req.update r2;

if (r0) {
tex0:=node.ex.texture.create(u0, w,h);

node.ex.child.draw.s(u0, 0);

req.update:=1;
};

draw

### texture.node.draw
_ @4;
_ @900776;
_ @1100;
_ @util.gl.std;

_ @sys.obj.key;
_ @sys.shader.ex;

tex0 r1;
req.update r2;

if (req.update>0) {
draw.to.fbo;
};

draw.to.fbo {
node.ex.gl.fbo(u0, tex0);
node.ex.gl.clear(u0, 0,0,req.update,0);

#gl.shader.use(vsh0,fsh0);
#shader.load.uniforms(u0, nid);
#gl.rect0(5, 0,0, w,h);

node.ex.gl.child.draw(u0);

node.ex.gl.fbo(u0, -1);
};

gl.rect0.texture(5, 0,0, w,h, tex0);

util

startup.clear.texture

startup.clear.texture {
# tex, r,g,b,a
tex _0;
r _1; g _2; b _3; a _4;
if (r0) {
node.ex.gl.fbo(u0, tex);
node.ex.gl.clear(u0, r,g,b,a);
node.ex.gl.fbo(u0, -1);
};
};

startup.clear.texture(tex0t, 1,0,1,1);

render node

new.hud.rt0 - add to render texture

# page47
hstack0:=xstack.add.hstack(vstack0, 0,0,1, 100,300, 1);

_ @ui.views;
_ @ui.recurse.view.acpul;
_ @core.hud;

sn0:=node.new.this.ex4(u0, ui.test.recurse.view.node, 0, 0,0,0);

new.hud.rt0(sn1, 0,0, 500,500);
node.change.parent(u0, sn1, sn0);

div0=xstack.add.div0(hstack0, sn1, 300,300);

util

center texture draw

# THE BEST CENTER TEXTURE CALC XYWH [

tex0 r1;

tw r2;
th r3;

# calc scale sw,sh
sw=w/tw;
sh=h/th;

# select min scale
s=min(sw, sh);

# calc w,h
w0=tw*s;
h0=th*s;

# calc x,y
x=(w-w0)/2;
y=(h-h0)/2;

draw.texure(tex0, 70212,70213, x,y, x+w0,y, x,y+h0, x+w0,y+h0);

# THE BEST CENTER TEXTURE CALC XYWH ]