Homebrew Homebrew Development

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
Don't think you can use dynamically linked libraries with the 3ds(.CRO maybe, but I don't think there's really any support for them), you might just have to create a statically linked library and just publish the resulting binary (.a i think) and headers. I don't think many people are going to go for a closed source library around here though.
Yeah, I got a solution to make it open source, but thanks anyway. this is really helpfull information.
 

Hansuasage

Member
Newcomer
Joined
Aug 5, 2015
Messages
5
Trophies
0
Age
33
XP
51
Country
United States
I can't say i'm a very good programmer. The most I have been able to do yet with 3DS homebrew is simple button tests and console input/output.
That being said, is there a function to draw simple 2D graphics in ctrulib? I haven't seen anything in the documentation,and the most I can find in the examples is just drawing a white pixel. I'm looking for ways to draw rectangles, lines, etc.
 

ifrit05

Well-Known Member
Newcomer
Joined
Aug 11, 2014
Messages
85
Trophies
0
Age
33
XP
340
Country
United States
I can't say i'm a very good programmer. The most I have been able to do yet with 3DS homebrew is simple button tests and console input/output.
That being said, is there a function to draw simple 2D graphics in ctrulib? I haven't seen anything in the documentation,and the most I can find in the examples is just drawing a white pixel. I'm looking for ways to draw rectangles, lines, etc.

This may or may not interest you.
http://gbatemp.net/threads/release-beta-sf2dlib-simple-and-fast-2d-library-using-the-gpu.384796/
 

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
I can't say i'm a very good programmer. The most I have been able to do yet with 3DS homebrew is simple button tests and console input/output.
That being said, is there a function to draw simple 2D graphics in ctrulib? I haven't seen anything in the documentation,and the most I can find in the examples is just drawing a white pixel. I'm looking for ways to draw rectangles, lines, etc.

If you know LUA as programming language, my LUA interpreter is pretty simple to use for 2D graphic.

Documentation: http://rinnegatamante.netsons.org/lpp-3ds_doc.html
Official Topic: http://gbatemp.net/threads/release-lua-player-plus-3ds-lpp-3ds-lua-interpreter-for-3ds.384202/
Samples: https://github.com/Rinnegatamante/lpp-3ds/tree/master/samples
 

Hansuasage

Member
Newcomer
Joined
Aug 5, 2015
Messages
5
Trophies
0
Age
33
XP
51
Country
United States
Thanks, I just installed sf2dlib. Whenever I try to build the example though, I get the following output: http://pastebin.com/pHgTic9D

I may not have done something correctly, for example I just downloaded the zip from the github repository and stuck it in my devkitpro folder because thats how I saw ctrulib, I don't know if there is a specific place I should put everything.
 

nop90

Well-Known Member
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,136
Country
Italy
Compile the lib souces with

make install

It will put the compiled lib in the right place.

And remenber to add -lsf2d in the LIBS variable in your program makefile (see the example with the lib source).
 

Hansuasage

Member
Newcomer
Joined
Aug 5, 2015
Messages
5
Trophies
0
Age
33
XP
51
Country
United States
-lsf2d is in the LIBS variable already though, and using "make install" tells me "no rule to make target 'install'" I have been using just make instead.
 

onepiecefreak

Kuriimu 2 Developer
Member
Joined
Aug 12, 2015
Messages
526
Trophies
0
XP
1,769
Country
Germany
I need a function to clear the whole screen. Is there something like this?
On page 121 of this thread is a piece of script with a clearScreen() function, but this function isnt known to devkitARM or ctrulib or something else. Its saying that he's unable to resolve the identifier clearScreen.

Thx for any help.
 

Helreizer543

Well-Known Member
Newcomer
Joined
Nov 24, 2014
Messages
49
Trophies
0
Age
102
XP
119
Country
United States
I need a function to clear the whole screen. Is there something like this?
On page 121 of this thread is a piece of script with a clearScreen() function, but this function isnt known to devkitARM or ctrulib or something else. Its saying that he's unable to resolve the identifier clearScreen.

Thx for any help.
It is because it is a user defined function from AlbertOS. You will have to look at the source from his github ^.^ good luck
 

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
I'm having some problem on flipping 32bpp images. My function currently crashes when called.

Here's the code:

Image creation:
Code:
static int lua_newBitmap(lua_State *L)
{
  int argc = lua_gettop(L);
  if (argc != 3) return luaL_error(L, "wrong number of arguments");
   int width_new = luaL_checkinteger(L, 1);
   int height_new = luaL_checkinteger(L, 2);
   u32 color = luaL_checkinteger(L, 3);
   Bitmap *bitmap = (Bitmap*)malloc(sizeof(Bitmap));
   bitmap->width = width_new;
   bitmap->magic = 0x4C494D47;
   bitmap->height = height_new;
   u8* pixels_new = (u8*)malloc(width_new*height_new*4);
   int i=0;
   memset(pixels_new,color,width_new*height_new*4);
   bitmap->pixels = pixels_new;
   bitmap->bitperpixel = 32;
   lua_pushinteger(L, (u32)(bitmap));
   return 1;
}

Image flipping:
Code:
int argc = lua_gettop(L);
  if (argc != 1) return luaL_error(L, "wrong number of arguments");
   Bitmap* bitmap = (Bitmap*)luaL_checkinteger(L, 1);
   if(!bitmap) return luaL_error(L, "Error loading image");
   u8* flipped = (u8*)malloc(bitmap->width*bitmap->height*4);
   for (int y = 0; y < bitmap->height; y++){
     for (int x = 0; x < bitmap->width; x++){
       *(u32*)(&(flipped[(x+y * bitmap->width)*4])) = *(u32*)&(bitmap->pixels[(x + (bitmap->height - y - 1) * bitmap->width)*4]);
     }
   }
   free(bitmap->pixels);
   bitmap->pixels = flipped;

Anyone have idea what's the problem? (Same function with slight differences (like *3 and not *4) works fine for 24bpp images.
 

Jim_e

Well-Known Member
Newcomer
Joined
Nov 13, 2007
Messages
79
Trophies
0
XP
267
Country
United States
*(u32*)(&(flipped[(x+y * bitmap->width)*4])) = *(u32*)&(bitmap->pixels[(x + (bitmap->height - y - 1) * bitmap->width)*4]);
That line looks incredibly sketchy. Why not memcpy the entire row?

memcpy( &flipped[y*width*4], &pixels[ (height - y - 1) * width *4], width *4)

Have you done sanity checks to make sure the pointers are valid? what about flipped is it returning a correct pointer?
 

onepiecefreak

Kuriimu 2 Developer
Member
Joined
Aug 12, 2015
Messages
526
Trophies
0
XP
1,769
Country
Germany
I need help with this picasso assembler.
I want to compile some graphics examples (graphics/gpu/geoshader) from ctrulib, but they need some preparation with picasso I think. What do I have to do with the .pica files or do I have to place picasso source files into the devkitARM/bin folder and include it?

Pls, help.

Sry, that I'm such a noob ^^
 
Last edited by onepiecefreak,

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 line looks incredibly sketchy. Why not memcpy the entire row?

memcpy( &flipped[y*width*4], &pixels[ (height - y - 1) * width *4], width *4)

Have you done sanity checks to make sure the pointers are valid? what about flipped is it returning a correct pointer?

Yes, i've just done sanity checks and function doesn't report me any problem.
Anyway even if i use memcpy, result are the same, console still crashes.

Code:
Bitmap* bitmap = (Bitmap*)luaL_checkinteger(L, 1);
   if(!bitmap) return luaL_error(L, "Error loading image");
   u8* flipped = (u8*)malloc(bitmap->width*bitmap->height*4);
   for (int y = 0; y < bitmap->height; y++){
     memcpy(&flipped[y*bitmap->width*4], &bitmap->pixels[(bitmap->height - y - 1) * bitmap->width * 4], bitmap->width * 4);
   }
   free(bitmap->pixels);
   bitmap->pixels = flipped;
 

Jim_e

Well-Known Member
Newcomer
Joined
Nov 13, 2007
Messages
79
Trophies
0
XP
267
Country
United States
I'm not seeing much, is bitmap->pixels a (u8*) and not a (u32*)?

The only things I could see cause a crash is accessing a bad pointer or writing out of memory.
If Flipped is fine and bitmap is correct, then the loop it self is doing the deed. I think you just need print some debug messages and find exactly what line it crashes on.
 

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
I build the http example from ctrulib.
after using the function a few times (first few works) "http_download" it gives error at httpcOpenContext,
Does someone has any idea why?
 

onepiecefreak

Kuriimu 2 Developer
Member
Joined
Aug 12, 2015
Messages
526
Trophies
0
XP
1,769
Country
Germany
I don't know if it's already included, but the drawPixel function is a bit false.
I tried it and the x and y position were not right.
I change the function for v a little bit and now it is:

Code:
u32 v=(height-1-y+x*height)*(x/100);

No it draws the specified Pixel at the right position.
Don't know if it's relevant.

And with that rewrote function I could finish my drawCell function:
Code:
//draw a Cell from start_x/y to end_x/y with the color r/g/b
void DrawCell (int start_x, int start_y, int end_x, int end_y char r, char g, char b, u8* screen) {
    int i,j;
    for (i=0+start_y;i<=end_y;i++) {
        for (j=0+start_x;j<=end_x;j++) {
            drawPixel(j,i,r,g,b,screen);
        }
    }
}

u8* screen is one of three variables defined in the main loop:
Code:
u8* screenBottom=gfyGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
u8* screenTopLeft=gfyGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
u8* screenTopRight=gfyGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);

And the variables r, g, b have to be in this format, where ?? is one Hexvalue from 0 to 255:
Code:
0x??

Any additions to that?
 
Last edited by onepiecefreak,

Tjessx

Well-Known Member
Member
Joined
Dec 3, 2014
Messages
1,160
Trophies
0
Age
27
XP
952
Country
Belgium
I don't know if it's already included, but the drawPixel function is a bit false.
I tried it and the x and y position were not right.
I change the function for v a little bit and now it is:

Code:
u32 v=(height-1-y+x*height)*(x/100);

No it draws the specified Pixel at the right position.
Don't know if it's relevant.

And with that rewrote function I could finish my drawCell function:
Code:
//draw a Cell from start_x/y to end_x/y with the color r/g/b
void DrawCell (int start_x, int start_y, int end_x, int end_y char r, char g, char b, u8* screen) {
    int i,j;
    for (i=0+start_y;i<=end_y;i++) {
        for (j=0+start_x;j<=end_x;j++) {
            drawPixel(j,i,r,g,b,screen);
        }
    }
}

u8* screen is one of three variables defined in the main loop:
Code:
u8* screenBottom=gfyGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL);
u8* screenTopLeft=gfyGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
u8* screenTopRight=gfyGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);

And the variables r, g, b have to be in this format, where ?? is one Hexvalue from 0 to 255:
Code:
0x??

Any additions to that?
Drawpixel is indeedd notbincluded. Everyone uses his own version
 

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
I'm not seeing much, is bitmap->pixels a (u8*) and not a (u32*)?

The only things I could see cause a crash is accessing a bad pointer or writing out of memory.
If Flipped is fine and bitmap is correct, then the loop it self is doing the deed. I think you just need print some debug messages and find exactly what line it crashes on.

bitmap->pixels is a correct pointer (infact if i use it without flipping the image is works fine), i tried also with something like this and i got always the same problem:

Code:
u8* tmp = (u8*)malloc(bitmap->width * 4);
   for (int y = 0; y < bitmap->height / 2; y++){
     memcpy(tmp, &bitmap->pixels[y*bitmap->width*4], bitmap->width * 4);
     memcpy(&bitmap->pixels[y*bitmap->width*4], &bitmap->pixels[(bitmap->height - y - 1) * bitmap->width * 4], bitmap->width * 4);
     memcpy(&bitmap->pixels[(bitmap->height - y - 1) * bitmap->width * 4], tmp, bitmap->width * 4);
   }
   free(tmp);
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    NinStar @ NinStar: :wub: