Homebrew [Release] Lua Player Plus 3DS (lpp-3ds) - LUA interpreter for 3DS

The_Marcster

Well-Known Member
Newcomer
Joined
Aug 18, 2015
Messages
98
Trophies
0
Age
24
XP
86
Country
Gambia, The
Is it normal that drawing text using fonts is reaaaally slow? I'm calling Font.print() 16 times a frame and my framerate is already only 10 or 11...
Also for me there are some weird differences with the space between different letters. Does this happen because of my font?
 

PabloMK7

Red Yoshi! ^ω^
Developer
Joined
Feb 21, 2014
Messages
2,617
Trophies
2
Age
24
Location
Yoshi's Island
XP
5,186
Country
Spain
Is it normal that drawing text using fonts is reaaaally slow? I'm calling Font.print() 16 times a frame and my framerate is already only 10 or 11...
Also for me there are some weird differences with the space between different letters. Does this happen because of my font?
If you are printing each line, use newline "\n" instead. That works as pressing Enter
 

The_Marcster

Well-Known Member
Newcomer
Joined
Aug 18, 2015
Messages
98
Trophies
0
Age
24
XP
86
Country
Gambia, The
If you are printing each line, use newline "\n" instead. That works as pressing Enter

I know, but I have to use this many calls to label buttons and images. The amount of calls will probably even increase when I continue to work on this program...

The weird thing is that System.debugPrint triples by framerate to 30 even though it should basically be the same thing, but even 30 fps are really low when I'm just rendering some text.

Look at the eShop or the browser. The 3DS can clearly handle large amounts of text and even some images at the same time with an acceptable framerate.

Maybe there should be some sort of way to render text using the GPU and not the CPU other than using dozens of images...
 

PabloMK7

Red Yoshi! ^ω^
Developer
Joined
Feb 21, 2014
Messages
2,617
Trophies
2
Age
24
Location
Yoshi's Island
XP
5,186
Country
Spain
I know, but I have to use this many calls to label buttons and images. The amount of calls will probably even increase when I continue to work on this program...

The weird thing is that System.debugPrint triples by framerate to 30 even though it should basically be the same thing, but even 30 fps are really low when I'm just rendering some text.

Look at the eShop or the browser. The 3DS can clearly handle large amounts of text and even some images at the same time with an acceptable framerate.

Maybe there should be some sort of way to render text using the GPU and not the CPU other than using dozens of images...
Maybe the problem is your font
 

Rinnegatamante

Well-Known Member
OP
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,858
Country
Italy
Is it normal that drawing text using fonts is reaaaally slow? I'm calling Font.print() 16 times a frame and my framerate is already only 10 or 11...
Also for me there are some weird differences with the space between different letters. Does this happen because of my font?

Font rendering is done with CPU rendering that's why it's so slow. An hardware font renderer (that works with Graphics module) is under development. Atm what you can do to improve your framerate is too write a renderer that uses a fixed bitmap font and Graphics module like @HexZyle did.
 

The_Marcster

Well-Known Member
Newcomer
Joined
Aug 18, 2015
Messages
98
Trophies
0
Age
24
XP
86
Country
Gambia, The
Font rendering is done with CPU rendering that's why it's so slow. An hardware font renderer (that works with Graphics module) is under development. Atm what you can do to improve your framerate is too write a renderer that uses a fixed bitmap font and Graphics module like @HexZyle did.

Thanks for your info, I think I'm going to do that
 
  • Like
Reactions: Rinnegatamante

The_Marcster

Well-Known Member
Newcomer
Joined
Aug 18, 2015
Messages
98
Trophies
0
Age
24
XP
86
Country
Gambia, The
I have another problem, Graphics.drawImage as well as all of its variations fail to draw my image. Note that it does work with some images, but some others just don't work. I suspect that this has something to do with the resolution (1143 x 44) because images with lower resolution (64 x 64 or similar) are the ones working. How can I get this to work?
 

Rinnegatamante

Well-Known Member
OP
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,858
Country
Italy
I have another problem, Graphics.drawImage as well as all of its variations fail to draw my image. Note that it does work with some images, but some others just don't work. I suspect that this has something to do with the resolution (1143 x 44) because images with lower resolution (64 x 64 or similar) are the ones working. How can I get this to work?

3DS hardware can't handle too much big textures (i don't know what are the limits but probably that's the cause).
 

The_Marcster

Well-Known Member
Newcomer
Joined
Aug 18, 2015
Messages
98
Trophies
0
Age
24
XP
86
Country
Gambia, The
So I tried to create a way to draw fonts using the GPU by creating images of every single letter and then drawing them to the screen, but I'm facing 2 problems right now:
1. Every time I draw a letter scaled up or down, some weird artifacts (single pixels in wrong places) appear in a way that makes the font almost unreadable. Note that this doesn't happen when drawing the images normally (not scaled).
2. This way of rendering text seems to be even slower than using the standard Fonts.* methods. Is there any easy way to make it faster?
 

OctoNezd

*insert some funny quote here*
Member
Joined
Aug 11, 2016
Messages
234
Trophies
0
Location
Moscow
XP
219
Country
Russia
Where i need to place my index.lua to compile it into CIA? Tried placing it in romfs, nothing happens, still error not index,lua found
 

Rinnegatamante

Well-Known Member
OP
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,858
Country
Italy
Where i need to place my index.lua to compile it into CIA? Tried placing it in romfs, nothing happens, still error not index,lua found

Use the buildscripts in R5 to properly create a standalone CIA using romfs partition.

So I tried to create a way to draw fonts using the GPU by creating images of every single letter and then drawing them to the screen, but I'm facing 2 problems right now:
1. Every time I draw a letter scaled up or down, some weird artifacts (single pixels in wrong places) appear in a way that makes the font almost unreadable. Note that this doesn't happen when drawing the images normally (not scaled).
2. This way of rendering text seems to be even slower than using the standard Fonts.* methods. Is there any easy way to make it faster?

Impossible it's slower. Your code is propbably bugged. Post it.
 

OctoNezd

*insert some funny quote here*
Member
Joined
Aug 11, 2016
Messages
234
Trophies
0
Location
Moscow
XP
219
Country
Russia
Use the buildscripts in R5 to properly create a standalone CIA using romfs partition.



Impossible it's slower. Your code is propbably bugged. Post it.
Already on R5, using cia_buildscript, still same thing(also tried 3dsx in Citra)

--------------------- MERGED ---------------------------

Here is log:
Code:
C:\Users\pk-asus\Desktop\Projects\Homebrew\3ds\lpp-3ds_r5\RomFs Buildscripts>3dstool -cvtf romfs romfs.bin --romfs-dir romfs
load: romfs/source/index.lua

C:\Users\pk-asus\Desktop\Projects\Homebrew\3ds\lpp-3ds_r5\RomFs Buildscripts>makerom -f cia -o lpp-3ds.cia -elf lpp-3ds.elf -rsf cia_workaround.rsf -icon icon.bin -banner banner.bin -exefslogo -target t -romfs romfs.bin

C:\Users\pk-asus\Desktop\Projects\Homebrew\3ds\lpp-3ds_r5\RomFs Buildscripts>
 

The_Marcster

Well-Known Member
Newcomer
Joined
Aug 18, 2015
Messages
98
Trophies
0
Age
24
XP
86
Country
Gambia, The
I wrote a module to load a font as a collection of images in a way so it is as similar as possible to the original Font.* methods. It takes an entire folder as its input, which should contain all characters you want to use as .png images named (x)xx.png, where (x)xx is the ASCII code of the character.

Here is the code:
Code:
ImageFont = {}
function ImageFont.load(path, baseHeight)
    local imageFont = {}
    imageFont.chars = {}
    for k, v in pairs(System.listDirectory(path)) do
        imageFont.chars[string.char(v['name']:sub(1, -5))] = Graphics.loadImage(path .. v['name'])
    end
    imageFont.baseHeight = baseHeight
    imageFont.height = baseHeight
    return imageFont
end
function ImageFont.setPixelSizes(imageFont, height)
    imageFont.height = height
end
function ImageFont.print(imageFont, x, y, text, color)
    local offset = x
    color = color or Color.new(0, 0, 0)
    for i = 1, #text do
        if(text:sub(i, i) == ' ') then
            offset = math.floor(offset + imageFont.height / 4 + 0.5)
        else
            Graphics.drawScaleImage(offset, y, imageFont.chars[text:sub(i, i)], imageFont.height / imageFont.baseHeight, imageFont.height / imageFont.baseHeight, color)
            offset = math.floor(offset + Graphics.getImageWidth(imageFont.chars[text:sub(i, i)]) * 0.9 * imageFont.height / imageFont.baseHeight + math.ceil(imageFont.height / 36) + 0.5)
        end
    end
end
function ImageFont.unload(imageFont)
    for k, v in pairs(imageFont.chars) do
        Graphics.freeImage(v)
    end
end

I know it's probably this slow because of all the drawn images, but I don't know how to make it more efficient...
 

Rinnegatamante

Well-Known Member
OP
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,858
Country
Italy
Already on R5, using cia_buildscript, still same thing(also tried 3dsx in Citra)

--------------------- MERGED ---------------------------

Here is log:
Code:
C:\Users\pk-asus\Desktop\Projects\Homebrew\3ds\lpp-3ds_r5\RomFs Buildscripts>3dstool -cvtf romfs romfs.bin --romfs-dir romfs
load: romfs/source/index.lua

C:\Users\pk-asus\Desktop\Projects\Homebrew\3ds\lpp-3ds_r5\RomFs Buildscripts>makerom -f cia -o lpp-3ds.cia -elf lpp-3ds.elf -rsf cia_workaround.rsf -icon icon.bin -banner banner.bin -exefslogo -target t -romfs romfs.bin

C:\Users\pk-asus\Desktop\Projects\Homebrew\3ds\lpp-3ds_r5\RomFs Buildscripts>

you must have romfs/index.lua, not romfs/source/index.lua.

I wrote a module to load a font as a collection of images in a way so it is as similar as possible to the original Font.* methods. It takes an entire folder as its input, which should contain all characters you want to use as .png images named (x)xx.png, where (x)xx is the ASCII code of the character.

Here is the code:
Code:
ImageFont = {}
function ImageFont.load(path, baseHeight)
    local imageFont = {}
    imageFont.chars = {}
    for k, v in pairs(System.listDirectory(path)) do
        imageFont.chars[string.char(v['name']:sub(1, -5))] = Graphics.loadImage(path .. v['name'])
    end
    imageFont.baseHeight = baseHeight
    imageFont.height = baseHeight
    return imageFont
end
function ImageFont.setPixelSizes(imageFont, height)
    imageFont.height = height
end
function ImageFont.print(imageFont, x, y, text, color)
    local offset = x
    color = color or Color.new(0, 0, 0)
    for i = 1, #text do
        if(text:sub(i, i) == ' ') then
            offset = math.floor(offset + imageFont.height / 4 + 0.5)
        else
            Graphics.drawScaleImage(offset, y, imageFont.chars[text:sub(i, i)], imageFont.height / imageFont.baseHeight, imageFont.height / imageFont.baseHeight, color)
            offset = math.floor(offset + Graphics.getImageWidth(imageFont.chars[text:sub(i, i)]) * 0.9 * imageFont.height / imageFont.baseHeight + math.ceil(imageFont.height / 36) + 0.5)
        end
    end
end
function ImageFont.unload(imageFont)
    for k, v in pairs(imageFont.chars) do
        Graphics.freeImage(v)
    end
end

I know it's probably this slow because of all the drawn images, but I don't know how to make it more efficient...

I'll take a look when i'll have more time [probably tonight or tomorrow] (atm my brain is dying with the Quake netcode for vitaQuake T.T) and i'll tell you my suggestions ;)
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    BigOnYa @ BigOnYa: I played the intro to far cry 5, that is like some crazy Jim Jones cult shit. Still its petty...