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

Discussion in '3DS - Homebrew Development and Emulators' started by nop90, Jan 30, 2017.

  1. nop90
    OP

    nop90 GBAtemp Advanced Maniac

    Member
    12
    Jan 11, 2014
    Italy
    Rome
    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.

    — Posts automatically merged - Please don't double post! —

    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?
     
  2. MyLegGuy

    MyLegGuy GBAtemp Advanced Fan

    Member
    6
    Nov 26, 2014
    United States
    Information if anybody in the future has trouble compiling SDL_mixer:
    Epic Chronicle
     
    Last edited by MyLegGuy, Nov 27, 2017
  3. nop90
    OP

    nop90 GBAtemp Advanced Maniac

    Member
    12
    Jan 11, 2014
    Italy
    Rome
    My makefile apply a patch (SDL_mixer-1.2.12.patch) to disable that check. If this doesn't work you could have other problems with the other packages
     
    MyLegGuy likes this.
  4. titoEarly

    titoEarly Member

    Newcomer
    1
    Jan 12, 2016
    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.
     
    Last edited by titoEarly, Nov 29, 2017
  5. nop90
    OP

    nop90 GBAtemp Advanced Maniac

    Member
    12
    Jan 11, 2014
    Italy
    Rome
    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.
     
  6. nop90
    OP

    nop90 GBAtemp Advanced Maniac

    Member
    12
    Jan 11, 2014
    Italy
    Rome
    Uploaded a zip file with all the compiled SDL libs on github.
     
  7. titoEarly

    titoEarly Member

    Newcomer
    1
    Jan 12, 2016
    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
     
  8. titoEarly

    titoEarly Member

    Newcomer
    1
    Jan 12, 2016
    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.
     
  9. CrafterGamer

    CrafterGamer Newbie

    Newcomer
    1
    Mar 16, 2018
    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
     
  10. B_E_P_I_S_M_A_N

    B_E_P_I_S_M_A_N knows nothing

    Member
    10
    Jun 7, 2016
    Antarctica
    Hell
    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".
     
  11. CrafterGamer

    CrafterGamer Newbie

    Newcomer
    1
    Mar 16, 2018
    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, Mar 17, 2018
  12. realWinterMute

    realWinterMute GBAtemp Regular

    Member
    4
    Feb 24, 2011
    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.

    — Posts automatically merged - Please don't double post! —


    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, Mar 17, 2018
  13. B_E_P_I_S_M_A_N

    B_E_P_I_S_M_A_N knows nothing

    Member
    10
    Jun 7, 2016
    Antarctica
    Hell
    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.
     
  14. gnmmarechal

    gnmmarechal GBAtemp Guru

    Member
    14
    GBAtemp Patron
    gnmmarechal is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    Jul 13, 2014
    Portugal
    https://gs2012.xyz
    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, Mar 17, 2018
    Joel16, cearp and B_E_P_I_S_M_A_N like this.
  15. EmmanuelIstace

    EmmanuelIstace Newbie

    Newcomer
    1
    Apr 25, 2018
    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, Apr 26, 2018
    cearp likes this.
  16. metasprite

    metasprite Newbie

    Newcomer
    1
    Sep 5, 2018
    United States
    Why is
    Code:
    SDL_Flip(screen)
    hard-limiting me to 30FPS? Surely there's a way to get 60FPS?[/code]
     
    Last edited by metasprite, Sep 5, 2018
  17. nop90
    OP

    nop90 GBAtemp Advanced Maniac

    Member
    12
    Jan 11, 2014
    Italy
    Rome
    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.
     
  18. delicator

    delicator Member

    Newcomer
    2
    Mar 10, 2010
    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, Dec 25, 2018
  19. MrHuu

    MrHuu GBAtemp Fan

    Member
    5
    Sep 19, 2015
    Netherlands
    Try to setup your DevkitARM environment with pacman. SDL 1.2 for 3ds is made available as a patch / package.
     
    delicator likes this.
  20. delicator

    delicator Member

    Newcomer
    2
    Mar 10, 2010
    France
    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, Dec 26, 2018
Quick Reply
Draft saved Draft deleted
Loading...