Homebrew Homebrew Development

TheCruel

Developer
Banned
Joined
Dec 6, 2013
Messages
1,350
Trophies
2
XP
3,131
Country
United States
Alright, I'll look at it, but I'm interested in using the GPU functions in my programs. Specifically 3D stuff, which I'm pretty sure sf2dlib doesn't do. But the source code might be helpful since there are descriptions of what each function does.
sf2dlib is using the GPU. There are no special 3d functions necessarily, it's essentially a hacky OpenGL ES. You would simply need to make sure sf2dlib's default shader script handles x/y/z vertex coords (I think it already may) and then use proper projection matrix.

I have a 3d engine and lib made already, but it's lacking fragment lighting, so until it has that it looks pretty ugly and not worth using.

Here's an example of a basic 3d shader. It's already fragment-lighting ready (though untested): https://github.com/cpp3ds/cpp3ds/blob/3d/res/core_resource/default_shader.vsh

Here's an example of projection matrix: https://github.com/cpp3ds/cpp3ds/blob/3d/src/cpp3ds/Graphics/Camera.cpp#L187

Not much else. If you don't know how to create a 3d environment in OpenGL ES, you certainly won't be able to using ctrulib.
 
Last edited by TheCruel,

Trinitro21

Well-Known Member
Member
Joined
Oct 14, 2015
Messages
133
Trophies
0
Location
Userland
XP
206
Country
United States
sf2dlib is using the GPU. There are no special 3d functions necessarily, it's essentially a hacky OpenGL ES. You would simply need to make sure sf2dlib's default shader script handles x/y/z vertex coords (I think it already may) and then use proper projection matrix.

I have a 3d engine and lib made already, but it's lacking fragment lighting, so until it has that it looks pretty ugly and not worth using.

Here's an example of a basic 3d shader. It's already fragment-lighting ready (though untested): https://github.com/cpp3ds/cpp3ds/blob/3d/res/core_resource/default_shader.vsh

Here's an example of projection matrix: https://github.com/cpp3ds/cpp3ds/blob/3d/src/cpp3ds/Graphics/Camera.cpp#L187

Not much else. If you don't know how to create a 3d environment in OpenGL ES, you certainly won't be able to using ctrulib.
I know sf2dlib uses the GPU; the emphasis in the first sentence of that post should have been the words my own. But I looked at the functions documented and the only z coordinate I see doesn't change per vertex of the polygons. Still, I haven't looked at the source code yet.

I have no experience with OpenGL and my knowledge of matrices is limited to googling during my research on perspective-correct textures, but I know enough about 3D to make my own software renderer, complete with z-buffering, using the command for changing the color of a pixel found in the application template in ctrulib's examples.

I vaguely understand the projection matrix linked, with x and y being modified to fit the field of view(I'm pretty sure it has the same function as the zooming I use to eliminate excessive perspective distortion in my renderer, except before projection), and z being modified to fit within the defined boundaries(like the if statements I use to prevent division by 0).
 

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
No, else you wouldn't be able to use ftpservers for files bigger then 500KB as well.
I can't see anything wring with the code you've shown.
Maybe it's a problem with another part of the code.
Are you trying to stream a song? i might try that out tonight, will let you know if i can get it to work.

Yes, this is the purpose of the hb. If you want to take a look to the sourcecode in its entirety, here you are the repository: https://github.com/Rinnegatamante/SMuRF

(I know there is already yellows8 hb which is quite similar but i'm experimenting my socketing skills right now with this hb).
 
Last edited by Rinnegatamante,

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
Does anyone know how the 2DS and New 3DS control the wifi hardware via software? To elaborate, my original 3DS' wifi switch no longer works (i.e. sliding it up does nothing, it does not turn it on or off), so it'd be nice if we had a homebrew method of enabling or disabling the wifi power through software.

Well, the answer is finally here (http://3dbrew.org/wiki/NWMEXT:ControlWirelessEnabled, thanks yellows8!):

Code:
#include <3ds.h>
#include <stdio.h>

#define ERR_WIFI_ALREADY_ON_OR_OFF 0xC8A06C0D

enum
{
    WIFI_ENABLE = 0,
    WIFI_DISABLE
}NWMEXT_WifiStates;

// http://3dbrew.org/wiki/NWMEXT:ControlWirelessEnabled
Result NWMEXT_ControlWirelessEnabled(u32 enable)
{
    Handle nwmExtHandle = 0;
    Result result = srvGetServiceHandle(&nwmExtHandle, "nwm::EXT");
    printf("srvGetServiceHandle: %lx\n", result);
    if (result != 0)
        return result;

    u32 *commandBuffer = getThreadCommandBuffer();
    commandBuffer[0] = 0x00080040;
    commandBuffer[1] = enable; // 0 = enable, 1 = disable

    result = svcSendSyncRequest(nwmExtHandle);
    printf("svcSendSyncRequest: %lx\n", result);
    svcCloseHandle(nwmExtHandle);

    return result;
}

void toggleWifi()
{
    // Try to turn wifi on by default.
    Result r = NWMEXT_ControlWirelessEnabled(WIFI_ENABLE);

    if (r == ERR_WIFI_ALREADY_ON_OR_OFF)
        NWMEXT_ControlWirelessEnabled(WIFI_DISABLE);
}

int main(int argc, char **argv)
{
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);

    printf("Press A to toggle wifi on/off.\n");
    printf("Press START to exit.\n");

    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();

        if (hidKeysDown() & KEY_A)
            toggleWifi();

        if (hidKeysDown() & KEY_START)
            break;

        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    gfxExit();
    return 0;
}

Note that this probably requires service access patching (so 9.2 and below only).

Under the Homebrew Launcher, launch your homebrew as MSET (6.0+ only, I think?) and it should provide proper access to nwm::EXT.

Edit: Made the toggle a bit more robust.

Edit 2: Off-topic bonus: MSET also has access to gsp::Lcd, so that might work as an alternative to control backlights until *hax 2.5.

Edit 3: Changed toggleWifi to work more or less 100% of the time. You'd have to be spamming on and off so fast for it not to work.
 
Last edited by daxtsu,
  • Like
Reactions: Shadowtrance

filfat

CTO @ Nordcom Group Inc.
Member
Joined
Nov 24, 2012
Messages
1,261
Trophies
1
Location
Gothenburg, Sweden
Website
www.sweetsideofsweden.com
XP
1,749
Country
Sweden
Hmm...

y8ZKjqD.png
 

filfat

CTO @ Nordcom Group Inc.
Member
Joined
Nov 24, 2012
Messages
1,261
Trophies
1
Location
Gothenburg, Sweden
Website
www.sweetsideofsweden.com
XP
1,749
Country
Sweden
Yay options, eww JavaScript. :P

Still cool though, I'm sure there's plenty of people that would rather code in JS than C, so whatever. Not my thing though.
Well, it's a heck of a lot faster to develop in than C/C++ or even C# and in this day and age is mostly worth the small performance trade off (it's quite large on the 3DS as duktape doesn't do any JIT) :)

DJ4bxnq.png

Edit:
Here is the Github repo: https://github.com/filfat-Studios-AB/3ds.js
 
Last edited by filfat,

Arseface_TM

Board Game Dev
Member
Joined
Sep 16, 2015
Messages
331
Trophies
0
Age
32
XP
306
Country
United States
I'm trying to send commands to ctrQuake, and the different buttons it recognizes are macros.

The rest of my binds work fine by accessing this array

Code:
char letters[144] = {"1234567890cdefghijklmnopqrstuvwzyxab"  //0
              "!@#$%^&*()CDEFGHIJKLMNOPQRSTUVWZYXAB"  //1
              "<>()[]{}!@#$%^&*;':\"-+=_,./?|`~\0\t\b\n "  //2
              "line of 36 characters I wanna change"}; //actually 36 characters :)

The last line I'd like to set to numbers 203-238, which are macros K_JOY1-4 and K_AUX1-32.

Is there any way to organize this without it looking like complete face?
And if there isn't, how can I set it even if it looks like complete face?
 

spinal_cord

Knows his stuff
Member
Joined
Jul 21, 2007
Messages
3,225
Trophies
1
Age
43
Location
somewhere
Website
spinalcode.co.uk
XP
3,378
Country
Guys, is the following way a good way to limit framerate?

Code:
    uint32 tim2 = svcGetSystemTick();
    while(tim2 < tim){tim2 = svcGetSystemTick();}
    tim = svcGetSystemTick() + (TICKS_PER_SEC/50);

I'm currently getting a steady framerate using it but it seems to randomly freeze for 10 or so seconds. does SystemTick loop or something that would end up with tim2 and tim being miles apart rather than a 50th of a second?
 

bnosam

Member
Newcomer
Joined
Sep 21, 2015
Messages
7
Trophies
0
Location
Canada
XP
67
Country
Canada
Does anyone have an example on how to play sound effects while looping music in the background?

I load the music and the effect in. I want to play the sound when I press KEY_A. But nothing happens, in fact when the music starts or re-loops it plays both the music and the sound effect but won't play the sound effect any other time.

Obviously I made they are on both different channels.
Code:
FILE *file = fopen(audio, "rb");
    fseek(file, 0, SEEK_END);
    off_t size = ftell(file);
    fseek(file, 0, SEEK_SET);
    buffer = linearAlloc(size);
    off_t bytesRead = fread(buffer, 1, size, file);

    fclose(file);

    csndPlaySound(8, SOUND_FORMAT_16BIT | SOUND_REPEAT, SAMPLE_RATE, 1, 0, buffer, buffer, size);
Is how I load the background music. I'm doing similar loading for the sound effect, but even when I omit the csndPlaySound function, the sound still plays when the background music starts and re-loops.

But when I do:

Code:
if(held & KEY_A)
csndPlaySound(8, SOUND_FORMAT_16BIT | SOUND_ONE_SHOT SAMPLE_RATE, 1, 0, buffer, buffer, size);

To play the effect, nothing happens.
 
Last edited by bnosam,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Veho @ Veho: It's how we used to cheat at Pokewalker.