Homebrew [Release] {beta} sf2dlib - Simple and Fast 2D library (using the GPU)

machinamentum

Well-Known Member
Member
Joined
Jul 5, 2015
Messages
163
Trophies
0
XP
549
Country
United States
Sorry for double post, but it's another (noob?) question this time, so I wanted to separate it from my reply.

How do I create a texture on VRAM? When I use sf2d_create_texture_mem_RGBA8 I can set the place of allocation to SF2D_PLACE_VRAM instead of SF2D_PLACE_RAM, but it freezes/crashes the program.
Are you writing to the texture after placing it in VRAM? The ARM CPU can't access VRAM directly, you have to request a DMA transfer through the GX engine to move data from main memory to VRAM and vice versa.
 

MOHRCORE

Well-Known Member
Newcomer
Joined
Nov 1, 2013
Messages
70
Trophies
0
XP
170
Country
Poland
Are you writing to the texture after placing it in VRAM? The ARM CPU can't access VRAM directly, you have to request a DMA transfer through the GX engine to move data from main memory to VRAM and vice versa.

You got me! I was trying to make some pixels transparent :P How can I move the texture from RAM to VRAM and vice versa?
 

machinamentum

Well-Known Member
Member
Joined
Jul 5, 2015
Messages
163
Trophies
0
XP
549
Country
United States
You got me! I was trying to make some pixels transparent :P How can I move the texture from RAM to VRAM and vice versa?
You have to call GX_RequestDma(u32 *src, u32 *dst, u32 len) then wait for the DMA event. However, ctrulib's GX_RequestDma doesn't set the flush cache bit for the request so it will often transfer broken bits of texture that weren't flush from the cache to main memory (I've set the bit for VRAM textures in Caelina). So, you may want to implement a DMA+flush request or just modify your texture before you send it to VRAM with sf2dlib.
 

cearp

瓜老外
Developer
Joined
May 26, 2008
Messages
8,728
Trophies
2
XP
8,522
Country
Tuvalu
thanks for the work, this is very helpful!
and, @xerpi - is your 3ds sdl port ready/finished/useable? (and how about your vita port?)
i want to port a game that uses sdl to 3ds, but @nop90 said there was some problems last time they tested, and used this lib and your others instead of sdl.
:)
 
Last edited by cearp,
D

Deleted User

Guest
Does color transparency work with this library? I ask this because I loaded an image with transparency using sf2dlib and sfillib, and in my program, the image showed white where it should have been transparent.
 

cearp

瓜老外
Developer
Joined
May 26, 2008
Messages
8,728
Trophies
2
XP
8,522
Country
Tuvalu
Does color transparency work with this library? I ask this because I loaded an image with transparency using sf2dlib and sfillib, and in my program, the image showed white where it should have been transparent.
yes transparency does work. i'm not sure about with images but i guess so, i don't see why not.
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,825
Trophies
2
Location
home
XP
9,344
Country
Hungary
Does color transparency work with this library? I ask this because I loaded an image with transparency using sf2dlib and sfillib, and in my program, the image showed white where it should have been transparent.

Yes, I don't think there's even a way to turn off transparency :S

Edit: ninja'd :P gg wp :ninja:
 
D

Deleted User

Guest
It may be stupid, but have you tried sf2d_draw_texture_blend? I never looked into replacing sf2d_draw_texture_blend with sf2d_draw_texture (since Jan. 26), but it's worth a try :P

Tried blending with black, made it completely invisible against my background. :/
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,825
Trophies
2
Location
home
XP
9,344
Country
Hungary
Tried blending with black, made it completely invisible against my background. :/

C:
void drawicona(u8* buf, IIcon icon, s16 x, s16 y, u8 a)
{
  sf2d_draw_texture_blend(icon.img, x, 240 - (y + icon.h), 0x00FFFFFF | (a << 24));
}

Don't worry about the other arguments, just see the last argument :P a==0 means the image is invisible, a==0xFF means the image is drawn without any transparency :D
 

Sono

cripple piss
Developer
Joined
Oct 16, 2015
Messages
2,825
Trophies
2
Location
home
XP
9,344
Country
Hungary
It's a JPEG.

Well, I think that's your problem then :P I don't think JPEG supports transparency :/ Try png, it's lossless :P

Edit: yes, JPEG doesn't support transparency AT ALL! Why are people using JPEG nowdays anyways? It's lossy and doesn't support transparency!
Convert your image to png, it's lossless, and it supports transparency :D
 
Last edited by Sono,
D

Deleted User

Guest
Well, I think that's your problem then :P I don't think JPEG supports transparency :/ Try png, it's lossless :P

Edit: yes, JPEG doesn't support transparency AT ALL! Why are people using JPEG nowdays anyways? It's lossy and doesn't support transparency!
Convert your image to png, it's lossless, and it supports transparency :D

Nope, converted to PNG, still there.
 

Sage_of_Mirrors

Member
Newcomer
Joined
Jul 30, 2016
Messages
6
Trophies
0
Age
27
XP
53
Country
United States
Hey, I'm having some trouble compiling applications that use SF2D.

I have updated Citro3D and libctru to their most recent versions, and it appears that everything should be fine. However, when I try to compile an app, say, the sample included with libsf2d, I get one error:

"Undefined reference to C3D_SafeDisplayTransfer."

My LIBS section of the makefile looks like this:

LIBS := -lsf2d -lcitro3d -lctru -lm​

If I get rid of-lcitro3d, the issue gets worse, with everything having to do with Citro3D giving the undefined error. I'm just at a loss as to what to do, since the chain of #includes should mean that the compiler can find C3D_SafeDisplayTransfer. It can find everything else.

Does anyone have any suggestions?
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: Finally there are people here