mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +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";
|
||||
}
|
||||
};
|
||||
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) {
|
||||
this.tileWidth = tilew;
|
||||
this.tileHeight = tileh;
|
||||
@@ -37,46 +46,65 @@ GL.SpriteSheet = function(tilew, tileh, tex) {
|
||||
return ty;
|
||||
};
|
||||
};
|
||||
GL.drawTexPattern = function(texture, x, y, width, height) {
|
||||
for (var yy = 0; yy < height; yy++) {
|
||||
for (var xx = 0; xx < width; xx++) {
|
||||
var tx = xx % texture.width;
|
||||
var ty = yy % texture.height;
|
||||
var c = texture.texData[ty * texture.width + tx];
|
||||
graphics.plotPixel(x + xx, y + yy, c);
|
||||
GL.drawTexPattern = function(texture, x, y, width, height, fgcol, bgcol) {
|
||||
if (!(texture instanceof GL.Texture) && !(texture instanceof GL.MonoTex)) throw Error("Texture is not a GL Texture types");
|
||||
|
||||
for (let yy = 0; yy < height; yy++) {
|
||||
for (let xx = 0; xx < width;) {
|
||||
let tx = xx % texture.width;
|
||||
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) {
|
||||
for (var yy = 0; yy < height; yy++) {
|
||||
for (var xx = 0; xx < width; xx++) {
|
||||
var tx = xx % texture.width;
|
||||
var ty = yy % texture.height;
|
||||
var c = texture.texData[ty * texture.width + tx];
|
||||
if ((c & 255) != 255) {
|
||||
graphics.plotPixel(x + xx, y + yy, c);
|
||||
GL.drawTexPatternOver = function(texture, x, y, width, height, fgcol) {
|
||||
if (!(texture instanceof GL.Texture) && !(texture instanceof GL.MonoTex)) throw Error("Texture is not a GL Texture types");
|
||||
|
||||
for (let yy = 0; yy < height; yy++) {
|
||||
for (let xx = 0; xx < width;) {
|
||||
let tx = xx % texture.width;
|
||||
let ty = yy % texture.height;
|
||||
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
|
||||
*/
|
||||
GL.drawTexImage = function(texture, x, y) {
|
||||
GL.drawTexPattern(texture, x, y, texture.width, texture.height);
|
||||
GL.drawTexImage = function(texture, x, y, fgcol, bgcol) {
|
||||
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
|
||||
*/
|
||||
GL.drawTexImageOver = function(texture, x, y) {
|
||||
for (var ty = 0; ty < texture.height; ty++) {
|
||||
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.drawTexImageOver = function(texture, x, y, fgcol) {
|
||||
GL.drawTexPatternOver(texture, x, y, texture.width, texture.height, fgcol);
|
||||
};
|
||||
GL.drawSprite = function(sheet, xi, yi, x, y) {
|
||||
var offx = sheet.getOffX(xi);
|
||||
|
||||
Reference in New Issue
Block a user