Homebrew app Want to use shapes on my 3DS with devkitpro.

Yukkuri_XP

New Member
OP
Newbie
Joined
Oct 14, 2022
Messages
4
Trophies
0
Location
ヰンドウズ
XP
65
Country
Japan
Hi.
I am making a program to draw shapes in devkitpro 3DS, but I am unable to build it due to an error.
I would appreciate it if you could tell me where I can correct the problem.
C++:
#include <3ds.h>
#include <stdio.h>
#include <string.h>

u8* pDispBuffer;
unsigned char PenColor[3];
unsigned char BrushColor[3];
unsigned int ClippingRect[4];

#define XYtoOfset(x,y) ((239-y)*3+(x*720))

//SelectFrame : set the frame pointer
// u8* pFrame : Pointer to framebuffer obtained by gfxGetFramebuffer
//
// Note: Always specify this before drawing

void SelectFrame(u8* pFrame) {
    if (pFrame) {
        pDispBuffer = pFrame;
    }
}

//SetClipping : set clipping area
// int x1,y1 : start point coordinates
// int x2,y2 : end point coordinates
void SetClipping(int x1, int y1, int x2, int y2) {
    ClippingRect[0] = x1;
    ClippingRect[1] = y1;
    ClippingRect[2] = x2;
    ClippingRect[3] = y2;
}
//SetPenColor          :pen color
// unsigned char r,g,b :color (RGB)
void SetPenColor(unsigned char r, unsigned char g, unsigned char b) {
    PenColor[2] = r;
    PenColor[1] = g;
    PenColor[0] = b;
}

//SetBrushColor        :brush color
// unsigned char r,g,b :color (RGB)
void SetBrushColor(unsigned char r, unsigned char g, unsigned char b) {
    BrushColor[2] = r;
    BrushColor[1] = g;
    BrushColor[0] = b;
}

//DrawDot : draw a point
// int x1,y1: coordinates
//
// Note: the color selected with the pen will be used.
void DrawDot(int x1, int y1) {
    if (pDispBuffer == NULL) return;
    if ((ClippingRect[0]<=x1)&&(ClippingRect[1]<=y1)&&(ClippingRect[2]>=x1)&&(ClippingRect[3]>=y1))
        memcpy(pDispBuffer + XYtoOfset(x1, y1), PenColor, sizeof(PenColor));
}

//DrawLine : draw a line
// int x1,y1 : start point coordinates
// int x2,y2 : end point coordinates
//
// Note: the color selected with the pen will be used.
void DrawLine(int x1, int y1, int x2, int y2) {
    DrawLineEx(x1, y1, x2, y2, (PenColor[2] << 16) | (PenColor[1] << 8) | PenColor[0]);
}
void DrawLineEx(int x1, int y1, int x2, int y2, int Color) {
    if (pDispBuffer == NULL) return;
    unsigned char brg[3] = { 0,0,0 };
    brg[2] = ((Color >> 16) & 0xFF);
    brg[1] = ((Color >> 8) & 0xFF);
    brg[0] = Color & 0xFF;
    int sp = 0, i = 0;
    double dSlope = 0.0, dSection = 0.0;
    if (x1 == x2) {
        if (y1 < y2) {
            sp = y1;
        } else {
            sp = y2;
        }
        for (i = sp; i < abs(y1 - y2)+sp; i++) {
            if ((ClippingRect[0]<=x1)&&(ClippingRect[1]<=i)&&(ClippingRect[2]>=x1)&&(ClippingRect[3]>=i))
                memcpy(pDispBuffer + XYtoOfset(x1, i), brg, sizeof(brg));
        }
        return;
    }
    dSlope = (double)(y1 - y2) / (double)(x1 - x2);
    dSection = (double)y1 - dSlope * x1;
    if (abs(x1 - x2) >= abs(y1 - y2)) {
        if (x1 < x2) {
            sp = x1;
        } else {
            sp = x2;
        }
        for (i = sp; i < abs(x1 - x2)+sp; i++) {
            if ((ClippingRect[0]<=i)&&(ClippingRect[1]<=(int)(dSlope * (double)i + dSection))&&(ClippingRect[2]>=i)&&(ClippingRect[3]>=(int)(dSlope * (double)i + dSection)))
                memcpy(pDispBuffer + XYtoOfset(i, (int)(dSlope * (double)i + dSection)), brg, sizeof(brg));
        }
    } else {
        if (y1 < y2) {
            sp = y1;
        } else {
            sp = y2;
        }
        for (i = sp; i < abs(y1 - y2)+sp; i++) {
            if ((ClippingRect[0]<=(int)((dSection*-1 + (double)i) / dSlope))&&(ClippingRect[1]<=i)&&(ClippingRect[2]>=(int)((dSection*-1 + (double)i) / dSlope))&&(ClippingRect[3]>=i))
                memcpy(pDispBuffer + XYtoOfset((int)((dSection*-1 + (double)i) / dSlope), i), brg, sizeof(brg));
        }
    }
}

//DrawRect : draw a filled rectangle
// int x1,y1 : start point coordinates
// int x2,y2 : end point coordinates
//
// Note: the color selected with the brush will be used.
void DrawRect(int x1, int y1, int x2, int y2) {
    if (pDispBuffer == NULL) return;
    for (int i1 = y1; i1 < y2; i1++) {
        for (int i2 = x1; i2 < x2; i2++) {
            if ((ClippingRect[0]<=i2)&&(ClippingRect[1]<=i1)&&(ClippingRect[2]>=i2)&&(ClippingRect[3]>=i1))
                memcpy(pDispBuffer + XYtoOfset(i2, i1), BrushColor, sizeof(BrushColor));
        }
    }
}

//DrawFrame : Draw a rectangle with only a frame
// int x1,y1 : start point coordinates
// int x2,y2 : end point coordinates
//
// Note: the color selected with the pen will be used.
void DrawFrame(int x1, int y1, int x2, int y2) {
    if (pDispBuffer == NULL) return;
    DrawLine(x1, y1, x2, y1);
    DrawLine(x2, y1, x2, y2 + 1);
    DrawLine(x2, y2, x1, y2);
    DrawLine(x1, y2, x1, y1);
}

//DrawCircle : draw a circle
// int x1,y1 : start point coordinates
// int x2,y2 : end point coordinates
// bool bPaint : whether to paint
//
// NOTE: The line will use the color selected with the pen.
// The color selected with the brush is used for filling.
void DrawCircle(int x1, int y1, int x2, int y2, bool bPaint) {
    if ((x1 == x2) || (y1 == y2)) return;
    int r = (x2 - x1) / 2, oldx = 0, oldy1 = 0, oldy2 = 0;
    double f = (double)(y2 - y1) / (double)(x2 - x1),tmp;
    int x = x1 + r, y = y1 + (int)((double)r*(double)f);
    if (bPaint) {
        for (int i = -r; i <= r; i++) {
            tmp = f*sqrt(r*r - i*i);
            DrawLineEx(x + i, y - tmp, x + i, y + tmp, (BrushColor[2] << 16) | (BrushColor[1] << 8) | BrushColor[0]);
        }
    }
    for (int i = -r; i <= r; i++) {
        tmp = f*sqrt(r*r - i*i);
        if (i == -r) {
            DrawDot(x + i, y - tmp);
            DrawDot(x + i, y + tmp);
        } else {
            DrawLine(x + i, y - tmp, oldx, oldy1);
            DrawLine(x + i, y + tmp, oldx, oldy2);
        }
        oldx = x + i;
        oldy1 = y - tmp;
        oldy2 = y + tmp;
    }
}

int main(void) {
    gfxInitDefault();
    gfxSetDoubleBuffering(GFX_TOP,true);

    int xpos = 190;
    int ypos = 110;

    while (aptMainLoop()) {
        hidScanInput();
        unsigned int keyDown = hidKeysDown();

        u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
        SelectFrame(fb);

        SetBrushColor(0,0,0);
        DrawRect(0,0,400,240);

        SetBrushColor(255,255,255);
        DrawCircle( xpos, ypos, xpos+20, ypos+20, true);
        if (keyDown & KEY_START) break;
        gfxFlushBuffers();
        gfxSwapBuffers();
        gspWaitForVBlank();
        };
    gfxExit();
    return 0;
};

Is there a library for drawing shapes with devkitpro on 3DS?
If anyone knows, please let me know.

↓The command prompt looks like this.
View attachment 332172
 
Last edited by Yukkuri_XP,

poisoned_soap

Member
Newcomer
Joined
May 10, 2020
Messages
7
Trophies
0
Age
20
XP
303
Country
United States
citro2d is the built-in library for drawing shapes, images and sprites.
You can use this site fo learn more about it, and I'm pretty sure you need to change the makefile in order for the program to actually compile.
 

Yukkuri_XP

New Member
OP
Newbie
Joined
Oct 14, 2022
Messages
4
Trophies
0
Location
ヰンドウズ
XP
65
Country
Japan
citro2d is the built-in library for drawing shapes, images and sprites.
You can use fo learn more about it, and I'm pretty sure you need to change the makefile in order for the program to actually compile.
Sorry, but is it possible to draw shapes only with gfxGetFramebuffer and memcpy?
I used to be able to use this module, but after updating devkitpro, it is no longer available.
C++:
void SelectFrame(u8* pFrame) {
    if (pFrame) {
        pDispBuffer = pFrame;
    }
}

void SetClipping(int x1, int y1, int x2, int y2) {
    ClippingRect[0] = x1;
    ClippingRect[1] = y1;
    ClippingRect[2] = x2;
    ClippingRect[3] = y2;
}
//SetPenColor
// unsigned char r,g,b
void SetPenColor(unsigned char r, unsigned char g, unsigned char b) {
    PenColor[2] = r;
    PenColor[1] = g;
    PenColor[0] = b;
}

void SetBrushColor(unsigned char r, unsigned char g, unsigned char b) {
    BrushColor[2] = r;
    BrushColor[1] = g;
    BrushColor[0] = b;
}

void DrawDot(int x1, int y1) {
    if (pDispBuffer == NULL) return;
    if ((ClippingRect[0]<=x1)&&(ClippingRect[1]<=y1)&&(ClippingRect[2]>=x1)&&(ClippingRect[3]>=y1))
        memcpy(pDispBuffer + XYtoOfset(x1, y1), PenColor, sizeof(PenColor));
}

void DrawLine(int x1, int y1, int x2, int y2) {
    DrawLineEx(x1, y1, x2, y2, (PenColor[2] << 16) | (PenColor[1] << 8) | PenColor[0]);
}
void DrawLineEx(int x1, int y1, int x2, int y2, int Color) {
    if (pDispBuffer == NULL) return;
    unsigned char brg[3] = { 0,0,0 };
    brg[2] = ((Color >> 16) & 0xFF);
    brg[1] = ((Color >> 8) & 0xFF);
    brg[0] = Color & 0xFF;
    int sp = 0, i = 0;
    double dSlope = 0.0, dSection = 0.0;
    if (x1 == x2) {
        if (y1 < y2) {
            sp = y1;
        } else {
            sp = y2;
        }
        for (i = sp; i < abs(y1 - y2)+sp; i++) {
            if ((ClippingRect[0]<=x1)&&(ClippingRect[1]<=i)&&(ClippingRect[2]>=x1)&&(ClippingRect[3]>=i))
                memcpy(pDispBuffer + XYtoOfset(x1, i), brg, sizeof(brg));
        }
        return;
    }
    dSlope = (double)(y1 - y2) / (double)(x1 - x2);
    dSection = (double)y1 - dSlope * x1;
    if (abs(x1 - x2) >= abs(y1 - y2)) {
        if (x1 < x2) {
            sp = x1;
        } else {
            sp = x2;
        }
        for (i = sp; i < abs(x1 - x2)+sp; i++) {
            if ((ClippingRect[0]<=i)&&(ClippingRect[1]<=(int)(dSlope * (double)i + dSection))&&(ClippingRect[2]>=i)&&(ClippingRect[3]>=(int)(dSlope * (double)i + dSection)))
                memcpy(pDispBuffer + XYtoOfset(i, (int)(dSlope * (double)i + dSection)), brg, sizeof(brg));
        }
    } else {
        if (y1 < y2) {
            sp = y1;
        } else {
            sp = y2;
        }
        for (i = sp; i < abs(y1 - y2)+sp; i++) {
            if ((ClippingRect[0]<=(int)((dSection*-1 + (double)i) / dSlope))&&(ClippingRect[1]<=i)&&(ClippingRect[2]>=(int)((dSection*-1 + (double)i) / dSlope))&&(ClippingRect[3]>=i))
                memcpy(pDispBuffer + XYtoOfset((int)((dSection*-1 + (double)i) / dSlope), i), brg, sizeof(brg));
        }
    }
}

void DrawRect(int x1, int y1, int x2, int y2) {
    if (pDispBuffer == NULL) return;
    for (int i1 = y1; i1 < y2; i1++) {
        for (int i2 = x1; i2 < x2; i2++) {
            if ((ClippingRect[0]<=i2)&&(ClippingRect[1]<=i1)&&(ClippingRect[2]>=i2)&&(ClippingRect[3]>=i1))
                memcpy(pDispBuffer + XYtoOfset(i2, i1), BrushColor, sizeof(BrushColor));
        }
    }
}

void DrawFrame(int x1, int y1, int x2, int y2) {
    if (pDispBuffer == NULL) return;
    DrawLine(x1, y1, x2, y1);
    DrawLine(x2, y1, x2, y2 + 1);
    DrawLine(x2, y2, x1, y2);
    DrawLine(x1, y2, x1, y1);
}

void DrawCircle(int x1, int y1, int x2, int y2, bool bPaint) {
    if ((x1 == x2) || (y1 == y2)) return;
    int r = (x2 - x1) / 2, oldx = 0, oldy1 = 0, oldy2 = 0;
    double f = (double)(y2 - y1) / (double)(x2 - x1),tmp;
    int x = x1 + r, y = y1 + (int)((double)r*(double)f);
    if (bPaint) {
        for (int i = -r; i <= r; i++) {
            tmp = f*sqrt(r*r - i*i);
            DrawLineEx(x + i, y - tmp, x + i, y + tmp, (BrushColor[2] << 16) | (BrushColor[1] << 8) | BrushColor[0]);
        }
    }
    for (int i = -r; i <= r; i++) {
        tmp = f*sqrt(r*r - i*i);
        if (i == -r) {
            DrawDot(x + i, y - tmp);
            DrawDot(x + i, y + tmp);
        } else {
            DrawLine(x + i, y - tmp, oldx, oldy1);
            DrawLine(x + i, y + tmp, oldx, oldy2);
        }
        oldx = x + i;
        oldy1 = y - tmp;
        oldy2 = y + tmp;
    }
}

void DrawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, bool bPaint) {
}
*/
 
Last edited by Yukkuri_XP,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • SylverReZ @ SylverReZ:
    @K3Nv2, RIP Felix does great videos on the PS3 yellow-light-of-death.
  • Jayro @ Jayro:
    Eventhough the New 3DS XL is more powerful, I still feel like the DS Lite was a more polished system. It's a real shame that it never got an XL variant keeping the GBA slot. You'd have to go on AliExpress and buy an ML shell to give a DS phat the unofficial "DS Lite" treatment, and that's the best we'll ever get I'm afraid.
    +1
  • Jayro @ Jayro:
    The phat model had amazingly loud speakers tho.
    +1
  • SylverReZ @ SylverReZ:
    @Jayro, I don't see whats so special about the DS ML, its just a DS lite in a phat shell. At least the phat model had louder speakers, whereas the lite has a much better screen.
    +1
  • SylverReZ @ SylverReZ:
    They probably said "Hey, why not we combine the two together and make a 'new' DS to sell".
  • Veho @ Veho:
    It's a DS Lite in a slightly bigger DS Lite shell.
    +1
  • Veho @ Veho:
    It's not a Nintendo / iQue official product, it's a 3rd party custom.
    +1
  • Veho @ Veho:
    Nothing special about it other than it's more comfortable than the Lite
    for people with beefy hands.
    +1
  • Jayro @ Jayro:
    I have yaoi anime hands, very lorge but slender.
  • Jayro @ Jayro:
    I'm Slenderman.
  • Veho @ Veho:
    I have hands.
  • BakerMan @ BakerMan:
    imagine not having hands, cringe
    +1
  • AncientBoi @ AncientBoi:
    ESPECIALLY for things I do to myself :sad:.. :tpi::rofl2: Or others :shy::blush::evil:
    +1
  • The Real Jdbye @ The Real Jdbye:
    @SylverReZ if you could find a v5 DS ML you would have the best of both worlds since the v5 units had the same backlight brightness levels as the DS Lite unlockable with flashme
  • The Real Jdbye @ The Real Jdbye:
    but that's a long shot
  • The Real Jdbye @ The Real Jdbye:
    i think only the red mario kart edition phat was v5
  • BigOnYa @ BigOnYa:
    A woman with no arms and no legs was sitting on a beach. A man comes along and the woman says, "I've never been hugged before." So the man feels bad and hugs her. She says "Well i've also never been kissed before." So he gives her a kiss on the cheek. She says "Well I've also never been fucked before." So the man picks her up, and throws her in the ocean and says "Now you're fucked."
    +1
  • BakerMan @ BakerMan:
    lmao
  • BakerMan @ BakerMan:
    anyways, we need to re-normalize physical media

    if i didn't want my games to be permanent, then i'd rent them
    +1
  • BigOnYa @ BigOnYa:
    Agreed, that why I try to buy all my games on disc, Xbox anyways. Switch games (which I pirate tbh) don't matter much, I stay offline 24/7 anyways.
  • AncientBoi @ AncientBoi:
    I don't pirate them, I Use Them :mellow:. Like I do @BigOnYa 's couch :tpi::evil::rofl2:
    AncientBoi @ AncientBoi: I don't pirate them, I Use Them :mellow:. Like I do @BigOnYa 's couch :tpi::evil::rofl2: