mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-12 07:44:03 +09:00
new mono texture format for gl
This commit is contained in:
0
assets/disk0/home/calc.js
Normal file
0
assets/disk0/home/calc.js
Normal file
@@ -16,6 +16,15 @@ GL.Texture = function(w, h, bytes) {
|
|||||||
throw "Texture data is not an instance of array";
|
throw "Texture data is not an instance of array";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
GL.MonoTex = function(w, h, bits) {
|
||||||
|
this.width = w;
|
||||||
|
this.height = h;
|
||||||
|
this.texData = bits;
|
||||||
|
|
||||||
|
if (!Array.isArray(bits) && !bits.toString().startsWith("[B")) {
|
||||||
|
throw "Texture data is not an instance of array";
|
||||||
|
}
|
||||||
|
};
|
||||||
GL.SpriteSheet = function(tilew, tileh, tex) {
|
GL.SpriteSheet = function(tilew, tileh, tex) {
|
||||||
this.tileWidth = tilew;
|
this.tileWidth = tilew;
|
||||||
this.tileHeight = tileh;
|
this.tileHeight = tileh;
|
||||||
@@ -37,46 +46,65 @@ GL.SpriteSheet = function(tilew, tileh, tex) {
|
|||||||
return ty;
|
return ty;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
GL.drawTexPattern = function(texture, x, y, width, height) {
|
GL.drawTexPattern = function(texture, x, y, width, height, fgcol, bgcol) {
|
||||||
for (var yy = 0; yy < height; yy++) {
|
if (!(texture instanceof GL.Texture) && !(texture instanceof GL.MonoTex)) throw Error("Texture is not a GL Texture types");
|
||||||
for (var xx = 0; xx < width; xx++) {
|
|
||||||
var tx = xx % texture.width;
|
for (let yy = 0; yy < height; yy++) {
|
||||||
var ty = yy % texture.height;
|
for (let xx = 0; xx < width;) {
|
||||||
var c = texture.texData[ty * texture.width + tx];
|
let tx = xx % texture.width;
|
||||||
graphics.plotPixel(x + xx, y + yy, c);
|
let ty = yy % texture.height;
|
||||||
|
if (texture instanceof GL.Texture) {
|
||||||
|
let c = texture.texData[ty * texture.width + tx];
|
||||||
|
graphics.plotPixel(x + xx, y + yy, c);
|
||||||
|
}
|
||||||
|
else if (texture instanceof GL.MonoTex) {
|
||||||
|
let octet = texture.texData[ty * (texture.width >> 3) + (tx >> 3)];
|
||||||
|
for (let i = 0; i < 8; i++) {
|
||||||
|
let bit = ((octet >>> (7 - i)) & 1 != 0)
|
||||||
|
graphics.plotPixel(x + xx + i, y + yy, bit ? bgcol : fgcol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xx += (texture instanceof GL.MonoTex) ? 8 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
GL.drawTexPatternOver = function(texture, x, y, width, height) {
|
GL.drawTexPatternOver = function(texture, x, y, width, height, fgcol) {
|
||||||
for (var yy = 0; yy < height; yy++) {
|
if (!(texture instanceof GL.Texture) && !(texture instanceof GL.MonoTex)) throw Error("Texture is not a GL Texture types");
|
||||||
for (var xx = 0; xx < width; xx++) {
|
|
||||||
var tx = xx % texture.width;
|
for (let yy = 0; yy < height; yy++) {
|
||||||
var ty = yy % texture.height;
|
for (let xx = 0; xx < width;) {
|
||||||
var c = texture.texData[ty * texture.width + tx];
|
let tx = xx % texture.width;
|
||||||
if ((c & 255) != 255) {
|
let ty = yy % texture.height;
|
||||||
graphics.plotPixel(x + xx, y + yy, c);
|
if (texture instanceof GL.Texture) {
|
||||||
|
if ((c & 255) != 255) {
|
||||||
|
let c = texture.texData[ty * texture.width + tx];
|
||||||
|
graphics.plotPixel(x + xx, y + yy, c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if (texture instanceof GL.MonoTex) {
|
||||||
|
let octet = texture.texData[ty * (texture.width >> 3) + (tx >> 3)];
|
||||||
|
for (let i = 0; i < 8; i++) {
|
||||||
|
let bit = ((octet >>> (7 - i)) & 1 != 0)
|
||||||
|
if (bit) graphics.plotPixel(x + xx + i, y + yy, fgcol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xx += (texture instanceof GL.MonoTex) ? 8 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* Draws a texture verbatim - color of 255 will be written to the screen buffer
|
* Draws a texture verbatim - color of 255 will be written to the screen buffer
|
||||||
*/
|
*/
|
||||||
GL.drawTexImage = function(texture, x, y) {
|
GL.drawTexImage = function(texture, x, y, fgcol, bgcol) {
|
||||||
GL.drawTexPattern(texture, x, y, texture.width, texture.height);
|
GL.drawTexPattern(texture, x, y, texture.width, texture.height, fgcol, bgcol);
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* Draws texture with blitting - color of 255 will pass-thru what's already on the screen buffer
|
* Draws texture with blitting - color of 255 will pass-thru what's already on the screen buffer
|
||||||
*/
|
*/
|
||||||
GL.drawTexImageOver = function(texture, x, y) {
|
GL.drawTexImageOver = function(texture, x, y, fgcol) {
|
||||||
for (var ty = 0; ty < texture.height; ty++) {
|
GL.drawTexPatternOver(texture, x, y, texture.width, texture.height, fgcol);
|
||||||
for (var tx = 0; tx < texture.width; tx++) {
|
|
||||||
var c = texture.texData[ty * texture.width + tx];
|
|
||||||
if ((c & 255) != 255) {
|
|
||||||
graphics.plotPixel(x + tx, y + ty, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
GL.drawSprite = function(sheet, xi, yi, x, y) {
|
GL.drawSprite = function(sheet, xi, yi, x, y) {
|
||||||
var offx = sheet.getOffX(xi);
|
var offx = sheet.getOffX(xi);
|
||||||
|
|||||||
Reference in New Issue
Block a user