mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
fix some model loading bugs and font loading bugs
This commit is contained in:
parent
6f1dbf85ed
commit
f8f45818cd
@ -87,6 +87,9 @@ object Versions : Iterable<Version> {
|
||||
}
|
||||
|
||||
operator fun get(name: String?): Version? {
|
||||
if (name == "automatic") {
|
||||
return AUTOMATIC
|
||||
}
|
||||
return VERSIONS_BY_NAME[name]
|
||||
}
|
||||
|
||||
|
@ -46,5 +46,4 @@ object FontLoader : DefaultFactory<FontProviderFactory<*>>(
|
||||
providers = providers,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import de.bixilon.minosoft.gui.rendering.font.Font
|
||||
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||
import de.bixilon.minosoft.util.KUtil.asList
|
||||
import de.bixilon.minosoft.util.KUtil.toDouble
|
||||
import de.bixilon.minosoft.util.KUtil.toInt
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||
import glm_.vec2.Vec2
|
||||
@ -30,21 +29,24 @@ class BitmapFontProvider(
|
||||
private val renderWindow: RenderWindow,
|
||||
data: Map<String, Any>,
|
||||
) : FontProvider {
|
||||
val height = data["height"]?.toInt() ?: 8
|
||||
val ascent = data["ascent"].toDouble()
|
||||
private val chars: MutableMap<Char, CharData> = mutableMapOf()
|
||||
private val heightScale = Font.CHAR_HEIGHT.toFloat() / height
|
||||
var charWidth = 8
|
||||
private set
|
||||
|
||||
init {
|
||||
val charRows = data["chars"].asList()
|
||||
val texture = renderWindow.textureManager.staticTextures.createTexture(data["file"].toResourceLocation().texture())
|
||||
texture.load(renderWindow.connection.assetsManager)
|
||||
|
||||
val height = texture.size.y / charRows.size
|
||||
val heightScale = Font.CHAR_HEIGHT.toFloat() / height
|
||||
|
||||
charWidth = texture.size.x / CHARS_PER_ROW
|
||||
val textureData = texture.data!!
|
||||
val pixel = Vec2(1.0f) / texture.size
|
||||
for ((y, row) in data["chars"].asList().withIndex()) {
|
||||
val xStart = IntArray(CHARS_PER_ROW) { 8 }
|
||||
for ((y, row) in charRows.withIndex()) {
|
||||
val xStart = IntArray(CHARS_PER_ROW) { charWidth }
|
||||
val xEnd = IntArray(CHARS_PER_ROW) { 0 }
|
||||
val yStart = pixel.y * y * height
|
||||
val yEnd = pixel.y * (y + 1) * height
|
||||
@ -84,14 +86,14 @@ class BitmapFontProvider(
|
||||
y = yEnd,
|
||||
)
|
||||
|
||||
var width = xEnd[x] - xStart[x]
|
||||
val width = xEnd[x] - xStart[x]
|
||||
|
||||
var scaledWidth = (width * heightScale).toInt()
|
||||
|
||||
if (width <= 0) {
|
||||
width = EMPTY_CHAR_WIDTH
|
||||
scaledWidth = EMPTY_CHAR_WIDTH
|
||||
}
|
||||
|
||||
val scaledWidth = (width * heightScale).toInt()
|
||||
|
||||
val charData = CharData(
|
||||
renderWindow = renderWindow,
|
||||
char = char.toChar(),
|
||||
@ -102,7 +104,7 @@ class BitmapFontProvider(
|
||||
uvEnd = uvEnd,
|
||||
)
|
||||
|
||||
chars[char.toChar()] = charData
|
||||
this.chars[char.toChar()] = charData
|
||||
}
|
||||
}
|
||||
textureData.rewind()
|
||||
|
@ -51,9 +51,6 @@ class ModelLoader(
|
||||
}
|
||||
|
||||
private fun loadBlockStates(block: Block) {
|
||||
if (block.resourceLocation.path == "grass_block") {
|
||||
val a = 1
|
||||
}
|
||||
val blockStateJson = assetsManager[block.resourceLocation.blockState()].readJsonObject()
|
||||
|
||||
val model = RootModel(this, blockStateJson) ?: return
|
||||
|
@ -64,7 +64,7 @@ class PNGTexture(override val resourceLocation: ResourceLocation) : AbstractText
|
||||
val byteOutput = ByteArrayOutputStream()
|
||||
val dataOutput = DataOutputStream(byteOutput)
|
||||
for (color in rgb) {
|
||||
dataOutput.writeInt(color)
|
||||
dataOutput.writeInt(color shl 8)
|
||||
}
|
||||
|
||||
data.put(byteOutput.toByteArray())
|
||||
|
@ -15,7 +15,7 @@
|
||||
uniform sampler2DArray uTextures[7];
|
||||
|
||||
vec4 getTexture(uint textureId, vec3 uv) { // ToDo: This method is just stupid and workarounds a opengl crash with mesa drivers
|
||||
#ifdef __NVIDIA
|
||||
#if defined __NVIDIA || defined __AMD
|
||||
return texture(uTextures[textureId], uv);
|
||||
#else
|
||||
switch (textureId) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user