devkitpro / citro2d Goto Github PK
View Code? Open in Web Editor NEWLibrary for drawing 2D graphics using the Nintendo 3DS's PICA200 GPU
Home Page: https://citro2d.devkitpro.org/
License: zlib License
Library for drawing 2D graphics using the Nintendo 3DS's PICA200 GPU
Home Page: https://citro2d.devkitpro.org/
License: zlib License
I have a plain white PNG in my sprite sheet, and I want to draw it with different colors. It's a 1x1 full white pixel. My idea is to use C2D_DrawImageAt to stretch, rotate, and color the image so I can essentially draw lines (since this feature isn't already built in for some reason). I would use rectangles, triangles, or ellipse', but I don't want them filled in, plus I just need plain lines anyway.
My problem is that I don't understand how to create a C2D_ImageTint. I looked at the documentation but I don't understand that either.
It would be a good function for Citro2D, to draw a box with rounded Corners. :)
Are there any examples created yet for this? Since pp2d no longer exists, I would like to use citro2d in my future projects, but I have no idea how to implement it.
I might be doing something wrong, but whenever I try to draw a sprite to the screen, the screen flickers.
Paste of my code: https://pastebin.com/1BGVWn1C
EDIT: Forgot to mention that I'm using the gpusprites example makefile.
Unlike all other drawing commands, the color supplied to C2D_TargetClear must be in the format of the texture being cleared. This is particularly troublesome with 16 bit (RGBA5551) textures, as knowledge of the byte endianness of the system (among other things) is necessary in order to get C2D_TargetClear to function properly. For instance, I currently have to perform transformations on the colors produced by C2D_Color32() to get it into 0bGGBBBBBARRRRRGGG0000000000000000
format solely for this function.
When I was looking at the documentation about C2D_Text, I noticed that it had a width
data field, which was useful for me since I needed it for my 3DS project. However, a height
data field was never mentioned anywhere in the struct nor in text.h, so I would have to guess it doesn't exist. Why does width
exist but not with height
? Is it even possible to get the height for the text?
This bug was originally reported by @DPS2004 on FAKE-08 (jtothebell/fake-08#106). I worked with them to track down the root issue and it looks like it is regression in citro2d introduced sometime in the last several months. It does not happen when built with 1.5.0, but does with the latest build (1.6.0). I'm attaching a video of a simple repro case, as well as the code to build the repro case, as I'm not really sure how to describe the problem.
We think we have a bug fix and will PR shortly.
There's no way to get the width/height of text printed in a formatted way (word wrap specifically), C2D_TextGetDimensions only has inputs for the text object, x-scale and y-scale. could potentially be fixed by GH-38
https://github.com/devkitPro/citro2d/blob/master/source/text.c#L329-L341
I'm pretty sure the ceilf() can be omitted (as well as in C2D_TextGetDimensions
to keep consistency) without consequences to allow the text to smoothly scale without the lines visibly jumping.
I've done it myself and not found any issues so far.
Here's a video of a homebrew dialog box I made to showcase this issue:
https://cdn.discordapp.com/attachments/329983699804487681/1173802183494479912/cyxlaunchtest1.mp4?ex=65654778&is=6552d278&hm=2c0363ae6136044a80455738b793045ad1128feeb11052a5a8a8c588708ef4fa&
Program: SMM3DSSE
I get a lot of errors on my citra build #337 with hardware renderer, no errors with software rasterizer
Could we have an example of this feature added to the "3ds-examples" repos?
This needs a tutorial or examples, it doesn't seem like there is already.
Calling C2D_SpriteSetScale
, and changing the scale to 0 will permanently make the sprite invisible. However, changing the centre of the sprite on the axis that the scale was set to 0, will make it reappear again. I've only tested this bug in citra however, so it might not occur on a real 3ds.
I think the bug is caused by these lines, where it calculates the old centre by dividing the centre by the width and height(which would be 0). It is important to note that this bug also occurs in C2D_SpriteScale
.
I can provide a code example if it helps.
Take a fresh installation of devkitPro w/ devkitARM, add dependencies with pacman (except for makerom and bannertool, which need to be added manually... I put them in msys2/opt/bin).
It will error out because msys2 can't find anything in devkitPro/tools/bin.
This is probably not how I should have done this, but I took care of it on my end by changing line 24 in devkitPro/msys2/etc/profile to read: MSYS2_PATH="/usr/local/bin:/usr/bin:/bin:/c/devkitPro/tools/bin"
Also, the installer adds an msys icon to the start menu (which doesn't work) along with the msys2 icon.
As stated, if you for example call C2D_DrawLine without any other shapes within a standard render loop (with all the appropriate calls etc.), it appears to use the alpha of the target that it is being drawn to rather than the alpha supplied in the color passed in the C2D_DrawLine call. However, if for instance, C2D_DrawRectangle is called first in the loop, then C2D_DrawLine, the alpha is properly set.
I've only tried it on off-screen render targets. One of the interesting quirks I found (which suggests that drawline is using purely the alpha from the target rather than just not showing at all), is if you run your code from the hb-menu, create an off-screen render target but don't clear it, then try to draw lines into it. The render target will have some of the effects from the hb-menu, and the lines will be MOSTLY transparent, same as the transparency that exists in the target (or so it seems). If you instead fully clear the target with full transparency, then try to do C2D_DrawLine as the first primitive in your render loop, nothing will show up at all (presumably because it is using the 0 alpha present in the target).
I can provide a full code example if it will help.
I don't know if it's already on the table or not, but it would be nice to add basic view manipulation (a global matrix transformation applied before drawing the sprites). In the current state there doesn't seem to be a simple way to do this through C2D, please tell me if I missed something.
I guess it could look something like that, modeled after the C2D_Sprite functions :
C2D_ViewSetPosition(x, y);
C2D_ViewMove(x, y);
C2D_ViewSetRotation(z);
C2D_ViewRotate(z);
C2D_ViewSetScale(x, y);
C2D_ViewScale(x, y);
Hi, I doubt this library is even maintained anymore now that the Switch is out, but I have a bit of an issue with using C2D_Image to draw an image.
Here's my relevant test code. It's fairly simple and the result should just be a gradient that sets the RGB from 0 to 255 and then loops until it runs out of pixels.
C2D_Image *createTest() {
u32 w=32, h=32;
C3D_Tex *tex = new C3D_Tex;
if(!C3D_TexInit(tex,w,h,GPU_RGBA8)) return NULL;
u32 s=w*h, *b = (u32*)linearAlloc(s*4); u8 n=0;
for(u32 ofs=0; ofs<s; ofs++) { b[ofs] = C2D_Color32(255,n,n,n); n++; }
C3D_TexUpload(tex,b); Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
subtex->left=subtex->top=0; subtex->width=w*4; subtex->height=h*4; //Draw at 400% scale.
subtex->right=subtex->bottom=1; return new C2D_Image {tex,subtex};
}
Only the result is well... Kinda trippy? Is my 3DS high? This happens on both a USA O3DS and a JPN N3DS. I figured it woud be easy enough, I'd just figure out what it's doing and put data in the buffer in a way that compensates for it... Only I've tried a few different tests with different colors/patterns/etc, and I can't really figure out what the pattern is. I'm stumped, what's wrong with this thing?
I'm trying to use off-screen render targets as layers in a drawing application. Regardless of the use case though, it would be nice to be able to clear an arbitrary section, as in set a rectangle or such to all-transparent (not the whole target).
Alternatively, if this is "not possible", it would be nice to be able to change the blending modes used for 2D primitives (I understand if this is difficult for circles). I would like to have the option to do pure overwrites for all channels (including the alpha channel) rather than blending with the target when drawing triangles/rectangles/etc. Considering that something similar is being performed to get circles to work, I don't see why this would be "outside the realm of an efficient 2D library".
This seems to be a common question, "Why do you want to do this?". Imagine you have a rasterized image produced from many many applications of drawing commands. Something that is difficult to reproduce on the fly. And then I want to draw, for instance, a semi-transparent blue rectangle and have it completely overwrite the pixels underneath it. Maybe I'm drawing a window or something. Perhaps I'm not understanding, but this doesn't seem like it'd be inefficient to perform, and it would greatly increase the usability of the library.
Currently, the library is a perfect fit for this drawing application I'm working on save for this one missing feature. I don't want to have to give up and redo everything with Citro3D just because this one thing isn't available.
I'm very new to 3DS homebrew development, but I'm surprised at the performance of the gpusprites example. Unedited, it can only do around 750 sprites without lagging on my old 3DS. If I edit the example to enable stereoscopic 3D and draw the sprites once for each screen side, it can obviously only draw half that number before it starts to lag. I know the old 3DS is pretty weak, but is this all it can do? Should I be expecting much less out of this system, or is better performance somehow possible? (Somewhat related, could a tiling system be implemented feasibly using sprites or something else in this library?) Thanks!
The bottom tetromino is being drawn with a C2D_ImageTint, to which the only operation performed was C2D_AlphaImageTint(&GHOST, 100);
. The tint has no effect, due to the blending strength being set to 0.
static inline void C2D_AlphaImageTint(C2D_ImageTint* tint, float alpha)
{
C2D_PlainImageTint(tint, C2D_Color32f(0.0f, 0.0f, 0.0f, alpha), 0.0f);
}
(base.h:137
)
I'm not too sure whether this is intended or not, but the documentation leads me to believe it isn't.
When using C2D_AlignCenter
, characters at the edges of an individual C2D_DrawText
can become clipped horizontally. In the below screenshot, it is most noticeable on the (B)
buttons in the center button diamond, but it is also affecting the /L/
and (A)
characters to a lesser extent. Notably, the (B)
in the top row is also being aligned with C2D_AlignCenter
but not showing the issue.
Each button glyph is a codepoint from the system font, (A)
is \uE000
and (B)
is \uE001
. /L/
and \R\
are \uE07B
and \uE07C
, respectively. I have not made any changes to devkitPro tooling, I am using the official devkitpro/devkitarm 20240202
tag in Docker.
Building my repo at vaguerant/red-viper is probably a decent start. If you want to replicate just the problematic portion, it can be found here and in the preceding variables: https://github.com/vaguerant/red-viper/blob/5ba407fbe4ab4706d8b8ab26f6c9c2ab5cbef7a3/source/3ds/gui_hard.c#L507-L510
20240202
C2D_Text width
? e.g. A single, centered glyph with an odd number of pixels in its width would need to be placed an off-integer pixel to be truly centered. If Citro2D is centering the glyph and anti-aliasing, that would mean the width of the glyph itself is two pixels less than the aliased version which is "half" in one pixel at either side. Again, just speculating, I have no idea how Citro2D renders text or does anything at all.C2D_DrawText
calls by 0.5, presumably forcing them back onto a pixel boundary.Today I added 2 new sprites, so I opened the sprites.t3s file and added the two file names to my large list of sprites.
I went to compile and it said 'No atlas solution found.'
If I remove the 2 lines (the 2 filenames) from the file again, it compiles fine.
Is there a sprite limit or something?
Hi,
I'm working on rendering a set of PNG images in my game using C2D_DrawImage but when I try to go back to my game it doesn't render any of the triangles anymore. If I go back to the image, it loads fine and renders again. I've checked the output of C2D_DrawTriangle and it says it is successful so I'm not sure why it isn't rendering.
I've broken it down to a simple example of swapping the scene here: https://github.com/pyroticinsanity/3dsdod/tree/issue2_manual/test/scene_swap.
I've also attached a copy of the 3dsx file if you'd like to check it out.
Any help would be greatly appreciated!
scene_swap.zip
Hello, please tell me how I can crop sprites.
I found that sprites can be cropped using Tex3dc_Texture and Tex3dc_SubTexture.
devkitPro/tex3ds#16
But I have no idea how to work with these types and functions
I can provide a simpler code example if necessary. I created a 1024x1024 off-screen render target, and any drawing commands within the first 8 rows causes a full system hang, requiring a hard reboot. It's currently happening in https://github.com/randomouscrap98/3ds_basicdraw/, particularly the "draw_centeredrect" function in https://github.com/randomouscrap98/3ds_basicdraw/blob/master/source/main.c, however I can create a simpler example if necessary, as it has been happening since the app did nothing at all. If you comment out the y < PAGE_EDGEBUF
section, then start the app and try drawing near the top, you can (perhaps) discover the full system hang.
I'm not sure if the 1024x1024 size matters. Again, I can provide a super minimal code example if required.
I wanted to learn more about how to make basic shapes for the 3DS because I wanted to do more than just text. And for some reason every single time I use a C2D function and try to build the file, it always says it's undefined in the terminal in a header file. I don't know what's causing it to happen.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.