Homebrew Homebrew Development

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
That's pretty weird.
I was working on pictochat3DS, and wanted to use http requests to log in and receive new messages.

logging in was just "visiting a webpage" so i wrote a ping command which never stopped working.
But after a few times, receiving new messages doesn't work anymore.
 

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,858
Country
Italy
That's pretty weird.
I was working on pictochat3DS, and wanted to use http requests to log in and receive new messages.

logging in was just "visiting a webpage" so i wrote a ping command which never stopped working.
But after a few times, receiving new messages doesn't work anymore.

Why using httpc service and not socketing? ( http://3dbrew.org/wiki/Socket_Services )
 

onepiecefreak

Kuriimu 2 Developer
Member
Joined
Aug 12, 2015
Messages
526
Trophies
0
XP
1,774
Country
Germany
Yeah, showing my code isnt that bad, isnt it?

main.c
Code:
#include "draw.h"

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

int main (int argc, char **argv) {
    gfxInitDefault();
   
    PrintConsole topScreen, bottomScreen;
    consoleInit(GFX_TOP,&topScreen);
    consoleInit(GFX_BOTTOM,&bottomScreen);
   
    while (aptMainLoop()) {
        u8* screenBottom=gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
       
        hidScanInput();
        touchPosition touch;
        u32 kDown = hidKeysDown();
        hidTouchRead(&touch);
       
        if (kDown & KEY_A) break;
       
        //u32 v=(240-1-touch.py+touch.px*240)*2;
       
        consoleSelect(&topScreen);
        printf("\x1b[0;0Hx: %03d",touch.px);
        printf("\x1b[1;0Hy: %03d",touch.py);
        printf("\x1b[2;0Hv: %06lu",v);
        consoleSelect(&bottomScreen);
       
        if (touch.px>0 && touch.py>0) {
            drawPixel(screenBottom,touch.px,touch.py,0xFF563F6D);
        }
       
        gfxFlushBuffers();
        gfxSwapBuffers();
       
        gspWaitForVBlank();
    }
   
    gfxExit();
    return 0;
}

draw.h
Code:
#ifndef DRAW_H
#define DRAW_H

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

/*void drawPixel(u32 v, int r, int g, int b, u8* screen) {
    screen[v]=b;
    screen[v+1]=g;
    screen[v+2]=r;
}*/

void drawPixel (u8* screen, int x, int y, u32 color) {
    int idx=(((x)*240) + (239-(y)))*3;
   
    printf("\x1b[0;0Hidx: %06d",idx);
   
    *(u32*)&(screen[idx]) = (((color) & 0x00FFFFFF) | ((*(u32*)&(screen[idx])) & 0xFF000000));
}
#endif    // DRAW_H

And now you can hopefully see the error!
P.S: the drawPixel function is the same from Rinnegatamante, except the printf.
 

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
Yeah, showing my code isnt that bad, isnt it?

main.c
Code:
#include "draw.h"

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

int main (int argc, char **argv) {
    gfxInitDefault();
  
    PrintConsole topScreen, bottomScreen;
    consoleInit(GFX_TOP,&topScreen);
    consoleInit(GFX_BOTTOM,&bottomScreen);
  
    while (aptMainLoop()) {
        u8* screenBottom=gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
      
        hidScanInput();
        touchPosition touch;
        u32 kDown = hidKeysDown();
        hidTouchRead(&touch);
      
        if (kDown & KEY_A) break;
      
        //u32 v=(240-1-touch.py+touch.px*240)*2;
      
        consoleSelect(&topScreen);
        printf("\x1b[0;0Hx: %03d",touch.px);
        printf("\x1b[1;0Hy: %03d",touch.py);
        printf("\x1b[2;0Hv: %06lu",v);
        consoleSelect(&bottomScreen);
      
        if (touch.px>0 && touch.py>0) {
            drawPixel(screenBottom,touch.px,touch.py,0xFF563F6D);
        }
      
        gfxFlushBuffers();
        gfxSwapBuffers();
      
        gspWaitForVBlank();
    }
  
    gfxExit();
    return 0;
}

draw.h
Code:
#ifndef DRAW_H
#define DRAW_H

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

/*void drawPixel(u32 v, int r, int g, int b, u8* screen) {
    screen[v]=b;
    screen[v+1]=g;
    screen[v+2]=r;
}*/

void drawPixel (u8* screen, int x, int y, u32 color) {
    int idx=(((x)*240) + (239-(y)))*3;
  
    printf("\x1b[0;0Hidx: %06d",idx);
  
    *(u32*)&(screen[idx]) = (((color) & 0x00FFFFFF) | ((*(u32*)&(screen[idx])) & 0xFF000000));
}
#endif    // DRAW_H

And now you can hopefully see the error!
P.S: the drawPixel function is the same from Rinnegatamante, except the printf.

Why not use the GPU? Check out sf2dlib
 

onepiecefreak

Kuriimu 2 Developer
Member
Joined
Aug 12, 2015
Messages
526
Trophies
0
XP
1,774
Country
Germany
Hmm... I see what you mean. Only to draw some simple 2D forms using GPU isnt a good idea, because using the GPU is less accurate, right?
I begin to learn :D

But all in all, the first question is, why does the functions doesnt draw the pixel at the given values?
 
Last edited by onepiecefreak,

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... I see what you mean. Only to draw some simple 2D forms using GPU isnt a good idea, because using the GPU is less accurate, right?
I begin to learn :D

But all in all, the first question is, why does the functions doesnt draw the pixel at the given values?
It's just as accurate, however as @Rinnegatamante said, it can be a lot harder drawing certain shapes.
You could always check out https://github.com/filfat/3DS_UI for references (though the project isn't being updated anymore due to time constraints, I hope to start working on that again sometime next year)
 

onepiecefreak

Kuriimu 2 Developer
Member
Joined
Aug 12, 2015
Messages
526
Trophies
0
XP
1,774
Country
Germany
Hmm, my compiler says it can't find the cosf, sinf and tanf function.
I included the math.h and I read that these functions are only included in the C++ version of the math.h.

Why isnt that included in devkitARM or do I do things wrong?
 

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,858
Country
Italy
Hmm, my compiler says it can't find the cosf, sinf and tanf function.
I included the math.h and I read that these functions are only included in the C++ version of the math.h.

Why isnt that included in devkitARM or do I do things wrong?

You can wright your own math functions in ASM or C.
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,519
Country
United States
Ok, I believe I got rendering to a texture working, but now I'm having an issue elsewhere. When testing my stuff, for some reason it tears on the left side. Thinking I was doing something too process-intensive, I went back to the original project I began with, which was the texture_cube example that came with ctrulib. I took that, and forced translation to -1.0 to make it fill the screen and ran it. It too was showing the tearing on that side. I understand that on the 3DS, the refresh is not from top to bottom, but from side to side (don't know from which side first), but with so little happening, I don't know what's going on. Is it still too intensive (GPU-wise)? Is it not waiting for something like the VBlank or is it transferring over to the display at the wrong time?

edit:

Ok, so I tried swapping the "gspWaitForVBlank()" and "gfxSwapBuffersGpu()" functions, and I'm not noticing any tearing anymore (the VBlank function was first prior to switching them). However, this doesn't exactly make a lot of sense, because if I'm switching the buffers prior to waiting, surely that would cause tearing, but it isn't. It seems to have the opposite effect.

edit #2:

Ok, hopefully this is the last one, since posting more than once in a row is considered improper here. I looked into ctrulib's source to see what "gfxSwapBuffersGpu" was doing, and from the look of it, it was just writing values into its own structure. I saw there was a "gfxSwapBuffers" version (no Gpu attached) that actually sent data via service requests, so, I used the non-Gpu version, and moved it back after the WaitForVBlank function. Sure enough, no tearing. So what exactly is the purpose of the Gpu version? Is that for if the GPU is currently processing, and becomes a pre-emptive action for when it is told to wait for the VBlank?
 
Last edited by DiscostewSM,
  • Like
Reactions: SLiV3R

geocool

Well-Known Member
Newcomer
Joined
Jul 31, 2008
Messages
57
Trophies
0
Age
32
Location
Athens
XP
528
Country
Greece
hey guys.

Does anyone know if there is a way to get available memory in runtime ?
I'm building a C++ engine for my game and I would like to know how much memory it consumes and if there are any memory leaks.

@DiscostewSM
I started with the template that latest ctrulib has and they use gfxSwapBuffers there, so you may have found the right function to use.
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,519
Country
United States
hey guys.

Does anyone know if there is a way to get available memory in runtime ?
I'm building a C++ engine for my game and I would like to know how much memory it consumes and if there are any memory leaks.

@DiscostewSM
I started with the template that latest ctrulib has and they use gfxSwapBuffers there, so you may have found the right function to use.

I believe linearSpaceFree() is what you're looking for. Also, thanks for telling about ctrulib being updated. I guess they must have updated recently if they changed it.

Maybe a more recent update is also what's fixes a black screen problem that's happening to me with my current build. I took the texture_cube example, and trimmed the polygon list so it would only show one side of the cube. When I ran it, it froze with a black screen. But (and this is the weird part), when I removed the flags for the texture assignment (set to 0 to have no filtering, wrapping, etc), it ran fine.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • Sicklyboy @ Sicklyboy:
    2 port HPE SFP+ PCIE NIC in my desktop and all of my servers
  • Sicklyboy @ Sicklyboy:
    silly shit
  • Sicklyboy @ Sicklyboy:
    eventually this desktop is going to act as a server too, just for the hell of it. Because this PC is WAY fucking overkill for how little I use it.
  • Sicklyboy @ Sicklyboy:
    And once I do that, my desktop OS that I interact with is just going to be a virtual machine and use GPU passthrough to connect everything
  • K3Nv2 @ K3Nv2:
    Send it to me ffs
  • Sicklyboy @ Sicklyboy:
    No because it's my desktop lol
  • Sicklyboy @ Sicklyboy:
    The most use this PC is getting right now is 979 Chrome tabs open right now
  • K3Nv2 @ K3Nv2:
    This is my desktop there are many like it but it is mine alone
  • K3Nv2 @ K3Nv2:
    Enabled PPPoE on router now no wifi connection lul
  • HiradeGirl @ HiradeGirl:
    Anyone knows
    where is Juan?
  • K3Nv2 @ K3Nv2:
    Taken by the feet police
  • HiradeGirl @ HiradeGirl:
    Horny jail?
  • K3Nv2 @ K3Nv2:
    It was a nationwide vote
  • BigOnYa @ BigOnYa:
    That does look good
  • HiradeGirl @ HiradeGirl:
    Does it have any more trailers?
  • HiradeGirl @ HiradeGirl:
    @K3Nv2 Are you there? I miss you.
  • K3Nv2 @ K3Nv2:
    Gay
  • HiradeGirl @ HiradeGirl:
    @K3Nv2 Those nights were wild. Thank you so much. :wub:
  • K3Nv2 @ K3Nv2:
    You were once human
  • NinStar @ NinStar:
    AI girlfriend
  • K3Nv2 @ K3Nv2:
    HiradeGirls intelligence is more advanced than all of us
    K3Nv2 @ K3Nv2: HiradeGirls intelligence is more advanced than all of us