Homebrew Homebrew Development

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,034
Country
United States
I know C is possible, I'm talking about mp3, mp4, etc., and if we can use those formats in homebrew.
There is the mvd service for the n3ds, but if you are asking is there a play mp3 api you can call in libctru or other 3ds provided api, then the answer is no. Libctru does provide apis to access the frame buffer and play audio samples. So you just need to either decode the files yourself or find an existing library that does this. You will then need to provide the "glue" to take the decoded information and put it in the format the 3ds requires and then display/play it.
 

TarableCode

Well-Known Member
Member
Joined
Mar 2, 2016
Messages
184
Trophies
0
Age
37
XP
319
Country
Canada
I'm working on drawing text using Citro3D and after peeking at the system font example I've got something that works pretty well.
The thing is that I need to be able to have a black background behind the text in order for it to be visible in some situations and I'm not sure how to handle that with my limited knowledge of 3D stuff.

I'll just post my horrible code rather than try to explain the monsters contained within :D
Code:
#include <3ds.h>
#include <citro3d.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "ui_main.h"
#include "ctr_vid.h"
#include "ctr_util.h"
#include "font.h"

#define FontWidth 8
#define FontHeight 16
#define CharsPerLine ( 320 / FontWidth )
#define LinesPerScreen ( 240 / FontHeight )
#define MaxCharsToDraw ( CharsPerLine * LinesPerScreen )

struct {
   float Left;
   float Top;
   float Bottom;
   float Right;
   struct Vertex Verticies[ 6 ];
} GlyphInfo[ 256 ];

static C3D_Tex Font_Tex;

static struct Vertex* VBOData = NULL;
static rgba32_t* Font_Data = NULL;

static int VertexCount = 0;
static int VBOIndex = 0;

void Font_Begin( void ) {
   C3D_TexEnv* Env = C3D_GetTexEnv( 0 );

   /*
    * Courtesy of the system font example.
    * I still don't really totally understand this yet.
    */
   C3D_TexEnvSrc( Env, C3D_RGB, GPU_PRIMARY_COLOR, 0, 0) ;
   C3D_TexEnvSrc( Env, C3D_Alpha, GPU_TEXTURE0, GPU_PRIMARY_COLOR, 0 );
   C3D_TexEnvOp( Env, C3D_Both, 0, 0, 0 );
   C3D_TexEnvFunc( Env, C3D_RGB, GPU_REPLACE );
   C3D_TexEnvFunc( Env, C3D_Alpha, GPU_MODULATE );

   VertexCount = 0;
   VBOIndex = 0;
}

void Font_AddText( float X, float Y, const char* Text, float R, float G, float B, float A ) {
   struct Vertex* Ptr = NULL;
   int Len = 0;
   int i = 0;
   int v = 0;
   int c = 0;

   Ptr = &VBOData[ VBOIndex ];
   Len = strlen( Text );

   if ( Len ) {
     for ( i = 0; i < Len; i++, X+= 8 ) {
       for ( v = 0; v < 6; v++ ) {
         c = Text[ i ];
         memcpy( Ptr, &GlyphInfo[ c ].Verticies[ v ], sizeof( struct Vertex ) );
         
         Ptr->Position[ 0 ] = GlyphInfo[ c ].Verticies[ v ].Position[ 0 ] + X;
         Ptr->Position[ 1 ] = GlyphInfo[ c ].Verticies[ v ].Position[ 1 ] + Y;

         Ptr->Color[ 0 ] = R;
         Ptr->Color[ 1 ] = G;
         Ptr->Color[ 2 ] = B;
         Ptr->Color[ 3 ] = A;

         Ptr++;
       }
     }

     VertexCount+= ( Len * 6 );
     VBOIndex+= ( Len * 6 );
   }
}

void Font_End( void ) {
   C3D_TexBind( 0, &Font_Tex );
   C3D_DrawArrays( GPU_TRIANGLES, 0, VertexCount );
}

int Font_Init( void ) {
   C3D_BufInfo* BufInfo = NULL;
   float x = 0.0f;
   float y = 0.0f;
   int i = 0;

   printf( "Font_Init\n" );
   C3D_TexInit( &Font_Tex, 128, 256, GPU_RGBA8 );

   Font_Data = LoadImageToPx2_32( "3ds/vmac/gfx/ui_font4.png", 128, 256 );

   if ( Font_Data != NULL ) {
     UI_UploadTexture32( Font_Data, &Font_Tex, 128, 256 );
     printf( "Texture uploaded\n" );

     for ( i = 0; i < 256; i++ ) {
       x = ( i % 16 ) / 16.0f;
       y = ( i / 16 ) / 16.0f;

       GlyphInfo[ i ].Left = x;
       GlyphInfo[ i ].Top = y;
       GlyphInfo[ i ].Right = x + ( 1.0f / 16.0f );
       GlyphInfo[ i ].Bottom =  y + ( 1.0f / 16.0f );

       // Top left, 1st triangle
       GlyphInfo[ i ].Verticies[ 0 ].Position[ 0 ] = 0;
       GlyphInfo[ i ].Verticies[ 0 ].Position[ 1 ] = 0;
       GlyphInfo[ i ].Verticies[ 0 ].Position[ 2 ] = 0.5f;
       GlyphInfo[ i ].Verticies[ 0 ].Texcoord[ 0 ] = x;
       GlyphInfo[ i ].Verticies[ 0 ].Texcoord[ 1 ] = y;

       // Bottom right, 1st triangle
       GlyphInfo[ i ].Verticies[ 1 ].Position[ 0 ] = 8;
       GlyphInfo[ i ].Verticies[ 1 ].Position[ 1 ] = 16;
       GlyphInfo[ i ].Verticies[ 1 ].Position[ 2 ] = 0.5f;
       GlyphInfo[ i ].Verticies[ 1 ].Texcoord[ 0 ] = x + ( 1.0f / 16.0f );
       GlyphInfo[ i ].Verticies[ 1 ].Texcoord[ 1 ] = y + ( 1.0f / 16.0f );

       // Top right, 1st triangle
       GlyphInfo[ i ].Verticies[ 2 ].Position[ 0 ] = 8;
       GlyphInfo[ i ].Verticies[ 2 ].Position[ 1 ] = 0;
       GlyphInfo[ i ].Verticies[ 2 ].Position[ 2 ] = 0.5f;
       GlyphInfo[ i ].Verticies[ 2 ].Texcoord[ 0 ] = x + ( 1.0f / 16.0f );
       GlyphInfo[ i ].Verticies[ 2 ].Texcoord[ 1 ] = y;
       
       // Top left, 2nd triangle
       GlyphInfo[ i ].Verticies[ 3 ].Position[ 0 ] = 0;
       GlyphInfo[ i ].Verticies[ 3 ].Position[ 1 ] = 0;
       GlyphInfo[ i ].Verticies[ 3 ].Position[ 2 ] = 0.5f;
       GlyphInfo[ i ].Verticies[ 3 ].Texcoord[ 0 ] = x;
       GlyphInfo[ i ].Verticies[ 3 ].Texcoord[ 1 ] = y;

       // Bottom left, 2nd triangle
       GlyphInfo[ i ].Verticies[ 4 ].Position[ 0 ] = 0;
       GlyphInfo[ i ].Verticies[ 4 ].Position[ 1 ] = 16;
       GlyphInfo[ i ].Verticies[ 4 ].Position[ 2 ] = 0.5f;
       GlyphInfo[ i ].Verticies[ 4 ].Texcoord[ 0 ] = x;
       GlyphInfo[ i ].Verticies[ 4 ].Texcoord[ 1 ] = y + ( 1.0f / 16.0f );

       // Bottom right, 2nd triangle
       GlyphInfo[ i ].Verticies[ 5 ].Position[ 0 ] = 8;
       GlyphInfo[ i ].Verticies[ 5 ].Position[ 1 ] = 16;
       GlyphInfo[ i ].Verticies[ 5 ].Position[ 2 ] = 0.5f;
       GlyphInfo[ i ].Verticies[ 5 ].Texcoord[ 0 ] = x + ( 1.0f / 16.0f );
       GlyphInfo[ i ].Verticies[ 5 ].Texcoord[ 1 ] = y + ( 1.0f / 16.0f );
     }

     VBOData = ( struct Vertex* ) linearAlloc( sizeof( struct Vertex ) * 6 * MaxCharsToDraw );

     if ( VBOData ) {
       BufInfo = C3D_GetBufInfo( );

       if ( BufInfo ) {
         BufInfo_Init( BufInfo );
         BufInfo_Add( BufInfo, VBOData, sizeof( struct Vertex ), 3, 0x210 );

         printf( "VBO Created\n" );
         
         return 1;
       }
     }
   }

   Font_Close( );
   return 0;
}

void Font_Close( void ) {
   C3D_TexDelete( &Font_Tex );

   if ( Font_Data )
     linearFree( Font_Data );

   if ( VBOData )
     linearFree( VBOData );

   Font_Data = NULL;
   VBOData = NULL;
}

Any thoughts or suggestions?
 
D

Deleted User

Guest
So, started learning homebrew development today. I managed to build the sample programs and get both ctrulib and sf2dlib working, however, I'm having trouble getting sfillib to compile and install. Whenever I run "make install", I get the following error message:

c:/3DS_Homebrew_Development?sfillib-master/libsfil/source/sfil_jpeg.c:5:21: fatal error: jpeglib.h: No such file or directory
compilation terminated
make[1]: *** [sfil_jpeg.o] Error 1
make: *** [build] Error 2

My Google-fu didn't help much, in this case. Are there any dependencies for this library I should be aware of? If not, what am I doing wrong?
 
D

Deleted User

Guest
Sounds like libjpeg isn't installed or it isn't being detected?
Do you have a portlibs directory in your devkitpro directory?

I thought devkitpro came with libjpeg already installed but you might have to install it yourself:
http://devkitpro.org/wiki/portlibs#libjpeg

Ah, I'll try that.

EDIT: Sorry if I'm asking a noob question here, but how would one go about installing these? The instructions on the website are a little vague.
 
Last edited by ,

TricksterGuy

Well-Known Member
Newcomer
Joined
Jan 16, 2016
Messages
81
Trophies
0
Age
37
Location
California
XP
221
Country
United States
After you run make, run "make install" and everything should go in the proper folders.

He'd need to invoke the configure script first to get a Makefile.

Ah, I'll try that.

EDIT: Sorry if I'm asking a noob question here, but how would one go about installing these? The instructions on the website are a little vague.

(Disclaimer I primarily use Linux for development though I sometimes do some development on windows with Mingw/MSYS)
I assume you are on Windows? You will need MSYS or equivalent in order to run the configure script.

Once you have that use the command given in that wiki to get a Makefile.

then its all of a matter of running the commands TarableCode mentioned.

I don't see why they didn't include precompiled versions of those libraries somewhere (I at least don't seem to have them in my devkitPro installation).
 

YugamiSekai

Mr. Picross
Member
Joined
Dec 24, 2014
Messages
2,015
Trophies
1
Age
22
XP
2,386
Country
United States
No. But like elhobbs said, most libraries only decode the file and the actual playback portion will have to be written by you.
Do you mean to use ctrulib's ndsp.h/dsp.h/csnd.h when you want me to make the playback myself, and does the library have to be Linux and Open source? (Yes I know csnd.h is outdated)
 

MasterFeizz

Well-Known Member
Member
Joined
Oct 15, 2015
Messages
1,098
Trophies
1
Age
29
XP
3,710
Country
United States
Do you mean to use ctrulib's ndsp.h/dsp.h/csnd.h when you want me to make the playback myself, and does the library have to be Linux and Open source? (Yes I know csnd.h is outdated)
Yes, you will need to use ctrulib to get the actual physical output, and the library does need to be open source since I don't really think you will be able to find a closed source library that will be compatible with the architecture and compiler.
 
D

Deleted User

Guest
I assume you are on Windows? You will need MSYS or equivalent in order to run the configure script.

Once you have that use the command given in that wiki to get a Makefile.

then its all of a matter of running the commands TarableCode mentioned.

I don't see why they didn't include precompiled versions of those libraries somewhere (I at least don't seem to have them in my devkitPro installation).

Well, I have a Windows desktop and a Ubuntu laptop. I'd like to develop on both, though one would suffice.

Also, an issue installing (on my Ubuntu laptop). zlib builds just fine, I just can't get the other libs to compile.

For example, libjpeg-turbo won't compile. I run "make libjpeg-turbo", then "sudo make install", but the terminal spits out this line:

/usr/bin/ld: skipping incompatible ./libbz2.a when searching for -lbz2
/usr/bin/ld: cannot find -lbz2
collect2: error: ld returned 1 exit status

I also get warnings when compiling, like this:

/opt/devkitPro/devkitARM/bin/../lib/gcc/arm-none-eabi/5.3.0/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000008020

Not sure if this is related, but I also have two devkitPro folders on my laptop. Probably because I ran the install script twice. Would deleting one alleviate the problem, just out of curiosity.
 

TricksterGuy

Well-Known Member
Newcomer
Joined
Jan 16, 2016
Messages
81
Trophies
0
Age
37
Location
California
XP
221
Country
United States
Well, I have a Windows desktop and a Ubuntu laptop. I'd like to develop on both, though one would suffice.

Also, an issue installing (on my Ubuntu laptop). zlib builds just fine, I just can't get the other libs to compile.

For example, libjpeg-turbo won't compile. I run "make libjpeg-turbo", then "sudo make install", but the terminal spits out this line:



I also get warnings when compiling, like this:



Not sure if this is related, but I also have two devkitPro folders on my laptop. Probably because I ran the install script twice. Would deleting one alleviate the problem, just out of curiosity.

Stick to ubuntu laptop then much simpler.

The reason why you get that error message is because its trying to link the libbz2.a that lives in /usr/lib (or some other default path the linker searches) with your library which you don't want here. That libbz2.a was compiled for x86 or x86_64 architectures and is incompatible with the 3d. You will need to point it at the libbz2.a you compiled for the 3ds there should be a flag you can pass to configure to do this.
 
D

Deleted User

Guest
You will need to point it at the libbz2.a you compiled for the 3ds there should be a flag you can pass to configure to do this.

How would I compile libbz2.a, and would I pass this flag to configure it to do so?
 

TricksterGuy

Well-Known Member
Newcomer
Joined
Jan 16, 2016
Messages
81
Trophies
0
Age
37
Location
California
XP
221
Country
United States
How would I compile libbz2.a, and would I pass this flag to configure it to do so?

download the source from here http://www.bzip.org/

it in itself should have a configure script

./configure --host=arm-none-eabi --prefix=$DEVKITPRO/portlibs/arm --enable-static --disable-shared

but looking at that wiki page and your post here are you sure you have the correct libjpeg source?

and on a higher level what is your end goal in all of this just for more context?
 

elhobbs

Well-Known Member
Member
Joined
Jul 28, 2008
Messages
1,044
Trophies
1
XP
3,034
Country
United States
Can someone please say me what the difference between normal and linear heap is?
They are two separate memory address spaces. The main difference is that linear can be accessed by hardware and "normal" cannot. Linear can be used for csnd and dsp playback buffers as well as GPU texture, vertex, and index buffers. If the "normal" or main heap is used for these buffers then it will cause garbage to play for sound or cause the gpu to hang the system requiring a full shutdown to resolve the issue.
Edit: and only main is used by malloc/new. The linear functions are needed to alloc/free for the linear address space.
 
Last edited by elhobbs,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    Sixteenth
  • Psionic Roshambo @ Psionic Roshambo:
    Also it was literally out of a kilo when I got it off the boat so absolutely pure
  • Psionic Roshambo @ Psionic Roshambo:
    Holy shiz that's a lot
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    I was getting 3.5 Grams for 320 could have stepped on it and doubled my money easy lol
    +1
  • BigOnYa @ BigOnYa:
    I'd be afraid to it nowdays, my heart would explode prob. I just stick beers n buds nowdays.
  • Psionic Roshambo @ Psionic Roshambo:
    I would get to drive from tarpon springs to like Miami a thousand bucks lol do that twice a week and back in 92 that was good money
  • Xdqwerty @ Xdqwerty:
    @BigOnYa,
    @Psionic Roshambo what are you guys talking about?
  • Psionic Roshambo @ Psionic Roshambo:
    Blew it on women and muscle cars lol
    +1
  • BigOnYa @ BigOnYa:
    @Xdqwerty Hamster food, its pricey nowadays to keep PCs running.
    +2
  • Psionic Roshambo @ Psionic Roshambo:
    I don't do anything except cigarettes and gotta stop eventually lol
    +1
  • BigOnYa @ BigOnYa:
    I'd do shrooms again if could find, and I was outside camping/fishing, and had a cooler full of beer.
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    I wouldn't mind some LSD, laughing until my face hurt sounds fun lol
    +1
  • BigOnYa @ BigOnYa:
    You ever try soaper powder/qauludes? I did once and like a dumbass drank beer on top of taking, I woke up laying in my backyard in the pouring rain, it knocked me out. I have not seen it around in many many years.
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    No never tried a lot of things but never that lol
  • Psionic Roshambo @ Psionic Roshambo:
    I did pass out one time on a floor after taking a bunch of Ambien lol thought it would help me sleep and did it lol
  • Psionic Roshambo @ Psionic Roshambo:
    Girlfriend was working at a pharmacy and stole like 500 of them, was and still is the biggest pill bottle I have ever seen lol
  • K3Nv2 @ K3Nv2:
    Ativan is pretty legit
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    The last time I had to take something to help me sleep, I was prescribed Trazadone it was pretty OK to be honest.
  • Psionic Roshambo @ Psionic Roshambo:
    Not something I need at all these days, doing a lot better lol
  • BigOnYa @ BigOnYa:
    That Nuka Cola video with old ice grinder is cool, I want one.
    +1
  • K3Nv2 @ K3Nv2:
    @BigOnYa, ANSWER HIS DAMN QUESTION
    +2
  • BigOnYa @ BigOnYa:
    I'm good, how r u, sorry playing Starfield, n have tablet by me on chat, but was exploring a planet
    BigOnYa @ BigOnYa: I'm good, how r u, sorry playing Starfield, n have tablet by me on chat, but was exploring a planet