Homebrew [Release] SDL-3DS 1.2.15 - Simple DirectMedia Layer for 3DS

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
I also tried loading a PNG in case BMP wasn't supported by IMG_Load() (which wouldn't make sense at all but who knows) and it didn't work either.

Never had problems using SDL_Image. Please provide a code example and the image you're trying to load, so I can test it on my toolchain.

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

That worked! I removed -lvorbis and it worked. I also had to make some more changes to the Makefile cause it failed at some points but it's finally installed.

Thanks for your help and enjoy your visit to Japan!

EDIT:

So I've been trying to compile one of @nop90 's projects (KETM). It compiled (with too many warnings) successfuly so I got the .3dsx and the .smdh. I tried to run the game in my 3DS but it didn't work. Bottom screen turns brown everytime I open the game, so I guess even though there was no error, the game wasn't correctly compiled.

Has anyone ver experienced anything like this?

There are several things that can go wrong.the problem could be a library compliled the wrong way, or tre program used to convert the elf in the 3dsx/cia package, or maybe problems with your FW version.

Are you using the 3dsx version or the cia? The same program from my release is working fine? the program files are matching?
 

titoEarly

Active Member
Newcomer
Joined
Jan 12, 2016
Messages
27
Trophies
0
XP
128
Country
Never had problems using SDL_Image. Please provide a code example and the image you're trying to load, so I can test it on my toolchain.
I tried to attach the project to the post but I couldn't so I uploaded it to MEGA. Here's the link.

In main.c, simply comment and uncomment these 2 lines to check what I previously said:
Code:
    loadedImage = SDL_LoadBMP(full_path);
    // loadedImage = IMG_Load(full_path);

There are several things that can go wrong.the problem could be a library compliled the wrong way, or tre program used to convert the elf in the 3dsx/cia package, or maybe problems with your FW version.

Are you using the 3dsx version or the cia? The same program from my release is working fine? the program files are matching?

I'm using the 3dsx version, haven't tried the program from your release tho. But I guess it should work. I will check that when I have the time and will let you know.
 
Last edited by titoEarly,

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
I tried to attach the project to the post but I couldn't so I uploaded it to MEGA. Here's the link.

In main.c, simply comment and uncomment these 2 lines to check what I previously said:
Code:
    loadedImage = SDL_LoadBMP(full_path);
    // loadedImage = IMG_Load(full_path);



I'm using the 3dsx version, haven't tried the program from your release tho. But I guess it should work. I will check that when I have the time and will let you know.
Tried the two version on citra ant both work the same. Later I'll try on a real 3ds. But probably there is something wrong with the your SDL_Image lib.

Anyway I'm going to upload on github a release of the libs precompiled.
 

titoEarly

Active Member
Newcomer
Joined
Jan 12, 2016
Messages
27
Trophies
0
XP
128
Country
Uploaded a zip file with all the compiled SDL libs on github.
Thank you! I downloaded it and replaced my own compiled files with yours and unfortunately I keep getting the same screen when I use IMG_Load()... So you got it working by testing it on Citra but might it be it doesn't work on a real 3DS? or could it be something with my 3DS?? I'm using an old 3ds, latest FW and homebrew loader 1.1.0 in case that tells you something
 

titoEarly

Active Member
Newcomer
Joined
Jan 12, 2016
Messages
27
Trophies
0
XP
128
Country
Hello again! Haven't had much time to work on this but today I decided to try my compiled .3dsx on Citra and it did work. So I guess there's must be something wrong with my 3DS? I don't know if just mine or that it doesn't work on 3DS in general? I tried on both my Old 3ds and New 3ds and it didn't work in any of them.
 

CrafterGamer

Member
Newcomer
Joined
Mar 16, 2018
Messages
9
Trophies
0
Age
25
XP
67
Country
Germany
I have a Problem with SDL..
I want to install SDL on Windows but there is always an error that the 3ds.h file cannot be found.
How can I fix this?
Thanks
 
D

Deleted User

Guest
I have a Problem with SDL..
I want to install SDL on Windows but there is always an error that the 3ds.h file cannot be found.
How can I fix this?
Thanks
You're going to want to make sure you have ctrulib installed first. Here's a link to a helpful tutorial.. The process on Windows is actually really easy, just let the installer do the work for you.

After you've made sure that you have DevKitPro installed, navigate to the DevKitPro install folder (which, more likely than not, is C:\devkitPro or something similar). Go inside the msys folder and click on msys.bat. From there, just clone the repository linked at the first post of this thread, navigate inside of that, and type in the command "make". Then, after that, "make install".
 

CrafterGamer

Member
Newcomer
Joined
Mar 16, 2018
Messages
9
Trophies
0
Age
25
XP
67
Country
Germany
Now have this error with msys
Code:
arm-none-eabi-gcc -g -Wall -O2 -mword-relocations -fomit-frame-pointer -ffast-math -march=armv6k -mtune=mpcore -mfloat-abi=hard -I./include -IC:/devkitPro//libctru/include -DARM11 -D_3DS -D__3DS__ -Wno-unused-variable   -c -o src/SDL.o src/SDL.c
make: arm-none-eabi-gcc: Command not found
make: *** [src/SDL.o] Error 127
------
Okay a have fix this with systemvariables

-----
Thank you lib is now created :D
-----
New problem
Code:
SDL.h: No such file or directory
 #include <SDL.h>

i have add this in makefile

Code:
export DEVKITPRO = /c/devkitPro
export DEVKITARM = /c/devkitPro/devkitARM

#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif

TOPDIR ?= $(CURDIR)
include $(DEVKITARM)/3ds_rules

ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
    MAKEROM := $(DEVKITPRO)/buildtools/3ds/makerom64.exe
else
    MAKEROM := $(DEVKITPRO)/buildtools/3ds/makerom32.exe
endif

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#
# NO_SMDH: if set to anything, no SMDH file is generated.
# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
# APP_TITLE is the name of the app stored in the SMDH file (Optional)
# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
# ICON is the filename of the icon (.png), relative to the project folder.
#   If not set, it attempts to use one of the following (in this order):
#     - <Project name>.png
#     - icon.png
#     - <libctru folder>/default_icon.png
#---------------------------------------------------------------------------------
TARGET        :=    $(notdir $(CURDIR))
BUILD        :=    build
SOURCES        :=    source source/pp2d/pp2d
DATA        :=    data
INCLUDES    :=    include $(PORTLIBS)/3ds/include
ROMFS        :=    romfs
APP_TITLE   :=  SDL TEST
APP_DESCRIPTION := SDL TEST
APP_AUTHOR  :=  CrafterGamer
ICON        :=  icon.png
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH    :=    -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft

CFLAGS    :=    -g -Wall -O2 -mword-relocations \
            -fomit-frame-pointer -ffunction-sections \
            $(ARCH)

CFLAGS    +=    $(INCLUDE) -DARM11 -D_3DS

CXXFLAGS    := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11

ASFLAGS    :=    -g $(ARCH)
LDFLAGS    =    -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)


LIBS    := -lSDL -lcitro3d -lctru -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS    := $(CTRULIB) $(PORTLIBS)


#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT    :=    $(CURDIR)/$(TARGET)
export TOPDIR    :=    $(CURDIR)

export VPATH    :=    $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
            $(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR    :=    $(CURDIR)/$(BUILD)

CFILES        :=    $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES    :=    $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES        :=    $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PICAFILES    :=    $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
SHLISTFILES    :=    $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
BINFILES    :=    $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
    export LD    :=    $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
    export LD    :=    $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES    :=    $(addsuffix .o,$(BINFILES)) \
            $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
            $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)

export INCLUDE    :=    $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
            $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
            -I$(CURDIR)/$(BUILD)

export LIBPATHS    :=    $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

ifeq ($(strip $(ICON)),)
    icons := $(wildcard *.png)
    ifneq (,$(findstring $(TARGET).png,$(icons)))
        export APP_ICON := $(TOPDIR)/$(TARGET).png
    else
        ifneq (,$(findstring icon.png,$(icons)))
            export APP_ICON := $(TOPDIR)/icon.png
        endif
    endif
else
    export APP_ICON := $(TOPDIR)/$(ICON)
endif

ifeq ($(strip $(NO_SMDH)),)
    export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
endif

ifneq ($(ROMFS),)
    export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
endif

.PHONY: $(BUILD) clean all

#---------------------------------------------------------------------------------
all: $(BUILD)

$(BUILD):
    @[ -d $@ ] || mkdir -p $@
    @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
    @echo clean ...
    @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(TARGET)-strip.elf $(TARGET).cia $(TARGET).3ds
#---------------------------------------------------------------------------------
$(TARGET)-strip.elf: $(BUILD)
    @$(STRIP) $(TARGET).elf -o $(TARGET)-strip.elf
#---------------------------------------------------------------------------------
cci: $(TARGET)-strip.elf
    @$(MAKEROM) -f cci -rsf resources/$(TARGET).rsf -target d -exefslogo -elf $(TARGET)-strip.elf -o $(TARGET).3ds
    @echo "built ... 3ds"
#---------------------------------------------------------------------------------
cia: $(TARGET)-strip.elf
    @$(MAKEROM) -f cia -o $(TARGET).cia -elf $(TARGET)-strip.elf -rsf resources/$(TARGET).rsf -icon resources/icon.bin -banner resources/banner.bin -exefslogo -target t
    @echo "built ... cia"
#---------------------------------------------------------------------------------
else

DEPENDS    :=    $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
ifeq ($(strip $(NO_SMDH)),)
$(OUTPUT).3dsx    :    $(OUTPUT).elf $(OUTPUT).smdh
else
$(OUTPUT).3dsx    :    $(OUTPUT).elf
endif

$(OUTPUT).elf    :    $(OFILES)

#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o    :    %.bin
#---------------------------------------------------------------------------------
    @echo $(notdir $<)
    @$(bin2o)

#---------------------------------------------------------------------------------
%.ttf.o    :    %.ttf
#---------------------------------------------------------------------------------
    @echo $(notdir $<)
    @$(bin2o)

# WARNING: This is not the right way to do this! TODO: Do it right!
#---------------------------------------------------------------------------------
%.jpeg.o:    %.jpeg
#---------------------------------------------------------------------------------
    @echo $(notdir $<)
    @$(bin2o)

#---------------------------------------------------------------------------------
%.png.o    :    %.png
#---------------------------------------------------------------------------------
    @echo $(notdir $<)
    @$(bin2o)

# WARNING: This is not the right way to do this! TODO: Do it right!
#---------------------------------------------------------------------------------
# rules for assembling GPU shaders
#---------------------------------------------------------------------------------
define shader-as
    $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
    picasso -o $(CURBIN) $1
    bin2s $(CURBIN) | $(AS) -o $@
    echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
    echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
    echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
endef

%.shbin.o : %.v.pica %.g.pica
    @echo $(notdir $^)
    @$(call shader-as,$^)

%.shbin.o : %.v.pica
    @echo $(notdir $<)
    @$(call shader-as,$<)

%.shbin.o : %.shlist
    @echo $(notdir $<)
    @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))

-include $(DEPENDS)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

How can i fix this?
 
Last edited by CrafterGamer,

realWinterMute

Well-Known Member
Member
Joined
Feb 24, 2011
Messages
117
Trophies
1
XP
558
Country
New problem
Code:
SDL.h: No such file or directory
 #include <SDL.h>

i have add this in makefile

...

How can i fix this?

By getting of that Makefile and using a standard devkitPro supplied one. It contains things that are just going to cause you grief. I also *strongly* recommend removing buildtools and forgetting that it ever existed.

Right now I have some things in progress which should hopefully sort out problems like this but it's going to require that @nop90 produce a proper patch against upstream SDL & stop supplying these Makefiles for the other libraries.

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

You're going to want to make sure you have ctrulib installed first. Here's a link to a helpful tutorial.. The process on Windows is actually really easy, just let the installer do the work for you.

After you've made sure that you have DevKitPro installed, navigate to the DevKitPro install folder (which, more likely than not, is C:\devkitPro or something similar). Go inside the msys folder and click on msys.bat. From there, just clone the repository linked at the first post of this thread, navigate inside of that, and type in the command "make". Then, after that, "make install".


It's libctru not ctrulib.

It's devkitPro please don't add random capitals. You don't install devkitPro, we're not something you install - we supply devkitARM (the toolchain you're using for 3DS code) which is something you install. These instructions are also missing several steps.
 
Last edited by realWinterMute,
D

Deleted User

Guest
New problem
It's libctru not ctrulib.

It's devkitPro please don't add random capitals. You don't install devkitPro, we're not something you install - we supply devkitARM (the toolchain you're using for 3DS code) which is something you install. These instructions are also missing several steps.
My bad. Perhaps I also should've told him to use Citro3D directly instead of this SDL port, as SDL is but a "handy" 2D Wrapper for lazy people who are only concerned with putting graphics on-screen.
 

gnmmarechal

Well-Known Member
Member
GBAtemp Patron
Joined
Jul 13, 2014
Messages
6,038
Trophies
2
Age
25
Location
https://gs2012.xyz
Website
gs2012.xyz
XP
5,989
Country
Portugal
It's libctru not ctrulib.

It's devkitPro please don't add random capitals. You don't install devkitPro, we're not something you install - we supply devkitARM (the toolchain you're using for 3DS code) which is something you install. These instructions are also missing several steps.

lmao. I don't think need I need say more, but here.

It's not ctrulib? That's the first time I hear anyone complain about that. What does it matter? The repo itself is called ctrulib.
Please don't add random capitals? sigh

Both of these complaints are incredibly pointless.
 
Last edited by gnmmarechal,

EmmanuelIstace

New Member
Newbie
Joined
Apr 25, 2018
Messages
1
Trophies
0
Age
33
XP
63
Country
Belgium
Hi !

Thank you for your amazing work, really nice !

I just started brewing my first project on the 3DS console using your port.

My problem is, I've started to write a multi layer background for shoot'em'up game but once I have more than 2 or 3 layer the fps fall dramaticaly and a lot of freeze occurs. I don't know if I'm doing something wrong or if it's just because I've already reach the performance limit of the SDL library port.

So I'm using this technique to loop the background and do the scrolling: lazyfoo . net/tutorials/SDL/31_scrolling_backgrounds/index.php
I write all my sprite to a back buffer and I blit the backbuffer to the screen once per frame. My sprites are approx. 512x240, perhap's too big to blit 6 sprites times 2 (for looping) of this size to the screen ?
I'm not a game developer so I've taken a look at the game ported by Nop90 as references on how to do stuffs.
Bliting to a backbuffer the sprites seems to be a common practice, I don't see how to improve my performance. And i don't even have enemies and bullets displayed :(

I also have a second issue, the SDL_mixer initialization fails, but when I try to get the error, it's empty.

I've uploaded my code to github if you want to take a look: github . com/Manu404/HelloShmup3DS

There's also a 3dsx if you don't want spend time compiling my project.

There's some rest of Meritous here and there, I just used your port of it as a "template".

Any help would be appreciated :)

Thanks in advance !

EDIT: I managed to improve a bit the performance by optimizing my sprites. All the layers were full 512*256, I resized them to 400*Y.
I also cropped all the unused space on top of certain layer making smaller.
It start to look fluid, but still around 15 FPS max only.

EDIT2: I've reached the 30FPS limit now ! I use SDL_DisplayFormat or SDL_ConvertSurface to converts my sprites to my screen format. Everything is now fluid. But all the colors are off now.
And still the error with SDL_mixer

EDIT3: Color issue solved by using SDL_DisplayFormatAlpha, everything works fine and at 30FPS which is totally fine for me.

FRAMERATE PROBLEM SOLVED :) - Still the SDL_mixer issue.
 
Last edited by EmmanuelIstace,
  • Like
Reactions: cearp

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
Maybe it's possible, but I wasn't able without having problems with GPU sync and audio thread priority.

If you want enhance the code, you're welcome.
 

delicator

Member
Newcomer
Joined
Mar 10, 2010
Messages
23
Trophies
0
XP
186
Country
France
Hi guys !
I have some time off and I can spend time to do something fun, I have build the hello world example from the devkitPro repo,
I try to build the SDL port, but I can't, I am searching but in the mean time, I try to post here if you can help me.

What I've done (perhaps I've done some basic mistake)

- setup my dev env (devkitpro - everythink is fine so far because the hello world example is compiling and working)
- clone the @nop90 repo for SDL
- go in the directory and make

but I'm stuck on
checking whether we are cross compiling...

 
Last edited by delicator,

delicator

Member
Newcomer
Joined
Mar 10, 2010
Messages
23
Trophies
0
XP
186
Country
France
Try to setup your DevkitARM environment with pacman. SDL 1.2 for 3ds is made available as a patch / package.
I have done the setup with pacman, following the official doc.
But, I did not see all the package I can install with it, I used it only for devkitARM ... :D
So thanks a lot for the hint ! I have search so many things, but not the most obvious

Have a really nice day, thanks again for your help !


for further reference, under ubuntu:

# sync and update:
dkp-pacman -Syu
# list of available packages
dkp-pacman -S -l
# install sdl package
dkp-pacman -S 3ds-sdl

...
 
Last edited by delicator,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Psionic Roshambo @ Psionic Roshambo: The Real Jdbye yeah those are great too