Compare commits

...

133 Commits

Author SHA1 Message Date
jonko0493
8932de1fff rich text: Optionally return cursor position from dry run & allow indenting text
Some checks failed
Documentation / Generate website (push) Has been cancelled
Documentation / Publish website with GitHub pages (push) Has been cancelled
The goal of the changes made in this PR is to create something with this
effect ("Jonko" is in in green, the rest is in white):

    "Dear god." Jonko quickly replied,
    crestfallen.

In order to do this, I need to call `NE_RichTextRender3D` or
`NE_RichTextRender3DAlpha` three times: once to draw the first part of
the sentence with the white font, once to draw "Jonko" in turquoise, and
once to draw the remainder of the sentence in white again. In order to
ensure that text is being drawn in the correct location, I need the
position where the previous call stopped drawing, which leads to the
first change this PR makes: I have added a version of
`DSF_StringRenderDryRun` which accepts pointers to `final_x` and
`final_y` and stores the last position of `font->pointer_x` and
`font->pointer_y` in them and I have added a new variant of
`NE_RichTextRenderDryRun` called `NE_RichTextRenderDryRunWithPos` which
uses that DSF function and has analogous parameters.

These functions get us the position where we need to place the next
cursor, but the next issue is that currently NitroEngine and libDSF only
allow for specifying the position of the overall box to draw text in,
but not where to offset the cursor in that box. This leads to the
following problem ("Jonko" is in in green, the rest is in white):

    "Dear god." Jonko quickly replied,
                        crestfallen.

Thus, the second change: I have introduced new versions of
`DSF_StringRender3D` and `DSF_StringRender3DAlpha` which accept an
`xStart` position that is added to the `pointerX`. Correspondingly, I
have added versions of `NE_RichTextRender3D` and
`NE_RichTextRender3DAlpha` that use these new functions as well.

Let me know if there are any issues with how I've written this (C is not
my forte, after all), but the first screenshot is this being tested in
production code.
2025-06-11 00:03:38 +01:00
Antonio Niño Díaz
86955bc0a0 rich text: Allow the number of fonts to be specified dynamically
Some checks failed
Documentation / Generate website (push) Has been cancelled
Documentation / Publish website with GitHub pages (push) Has been cancelled
This switches the rich text library from using a constant for the max
number of fonts to allowing the user to specify how many fonts should be
used dynamically. To accomplish this, a new method is introduced to the
rich text system: `NE_RichTextStartSystem`, which accepts the number of
slots to allocate. Those slots are allocated and then freed when
`NE_RichTextResetSystem` is called.

To maintain compatibility, I have not removed `NE_MAX_RICH_TEXT_FONTS`
(instead opting to mark it as deprecated), and have added functionality
to automatically call `NE_RichTextStartSystem` with that old value (8)
if the user decides to init a rich text slot before calling
`NE_RichTextStartSystem` (which would likely be the previous default
behavior).
2025-05-25 01:32:55 +02:00
jonko0493
6e1dca996c rich text: Allow the number of fonts to be specified dynamically 2025-05-24 09:37:46 -07:00
Antonio Niño Díaz
02f3cd7012 github: Add workflow to publish the documentation
Some checks failed
Documentation / Generate website (push) Has been cancelled
Documentation / Publish website with GitHub pages (push) Has been cancelled
2025-05-14 00:02:21 +01:00
Antonio Niño Díaz
926bb4f361 docs: library: Update changelog and version number to 0.15.3 2025-03-26 18:08:47 +00:00
Antonio Niño Díaz
f6b0200be3 build: Build library with debug symbols enabled
They are excluded from the final binaries, so the only effect of this is
to help with debugging by using a bit more of disk space.
2025-03-26 18:06:36 +00:00
Antonio Niño Díaz
d42cb2c08e docs: Update changelog 2025-03-24 21:19:31 +00:00
Antonio Niño Díaz
d52a92812e examples: Use BLOCKSDS environment variables to find tools
Only use the hardcoded paths if the variable isn't set to anything.
2025-03-24 21:18:00 +00:00
Antonio Niño Díaz
cb2e62f953 examples: Refresh pre-converted textures in the repository 2025-03-24 21:05:15 +00:00
Antonio Niño Díaz
5a10679dfb build: docs: Remove outdated devkitARM makefiles
Nitro Engine doesn't work with the current libraries of devkitARM. It's
better to remove the makefiles and to stop pretending that devkitARM is
supported. Updating the makefiles wouldn't be enough, though, it's likely
that the library will require code changes, as well as the examples.
2025-03-24 21:03:01 +00:00
Antonio Niño Díaz
b67c60d5f0 docs: library: Update changelog and library version to 0.15.2 2025-01-15 18:26:00 +00:00
Antonio Niño Díaz
fff1a65647 docs: Add note about using devkitARM 2025-01-15 18:24:47 +00:00
Antonio Niño Díaz
efbf4b6546 docs: Fix link 2025-01-14 01:29:06 +00:00
Antonio Niño Díaz
dd20800334 docs: Mention BlocksDS package in setup instructions 2025-01-14 01:27:25 +00:00
Antonio Niño Díaz
39117696aa build: Uniformize all devkitARM makefiles
Add DATA and GRAPHICS directories to all of them so that it's easier to
maintain the files.
2024-12-31 16:20:02 +01:00
Antonio Niño Díaz
459d8f8960 build: Use ar from ARM toolchain instead of the system one 2024-12-30 02:13:53 +01:00
Antonio Niño Díaz
e5ae245674 examples: Fix build of example on devkitARM 2024-12-28 12:44:36 +01:00
Antonio Niño Díaz
8a18dfa586 doxygen: Update version number in Doxyfile 2024-12-23 00:50:19 +01:00
Antonio Niño Díaz
de9ca58286 docs: library: Update changelog and version number 2024-12-23 00:40:45 +01:00
Antonio Niño Díaz
446e27110e examples: Clarify some comments 2024-12-17 00:38:28 +00:00
Antonio Niño Díaz
09c3712431 build: Install licenses with the rest of the library 2024-12-01 13:42:18 +00:00
Antonio Niño Díaz
a6738a9ab5 docs: library: Update changelog and version number 2024-12-01 12:07:51 +00:00
W3SLAV/gt4ous
afdd56eda4 examples: Fix devkitARM makefile
Added missing data directory.
2024-11-30 13:38:07 +00:00
Antonio Niño Díaz
fe6e4a0dcc examples: Add example of assigning a matrix to a model 2024-10-11 13:33:33 +02:00
Antonio Niño Díaz
4642bdf982 library: Allow users to specify model transformation matrices
A manual matrix overrides scale, translation and rotation. It can be
removed to switch back to individual scale, translation and rotation.
2024-10-11 13:33:21 +02:00
Antonio Niño Díaz
26823c024f docs: library: Update changelog and bump version to 0.14.0 2024-09-10 18:18:30 +01:00
Antonio Niño Díaz
5a4824f461 library: Fix use-after-free in RichText module
When this function doesn't fail, it should preserve the buffers that
have just been allocated, as they will be used later.
2024-08-14 00:47:06 +01:00
Antonio Niño Díaz
de16a59722 library: Fixes to RichText module 2024-08-14 00:45:07 +01:00
Antonio Niño Díaz
4115a62800 libdsf: Update to v0.1.3 2024-08-14 00:44:23 +01:00
Antonio Niño Díaz
88d1b489f6 examples: Update BlocksDS Makefiles
They were missing several updates made over the last few months.
2024-08-14 00:43:55 +01:00
Antonio Niño Díaz
7d13c2d637 docs: Update Doxyfile 2024-08-01 18:02:17 +01:00
Antonio Niño Díaz
5dda97fe52 Use stdint.h types instead of libnds custom types 2024-07-29 00:09:41 +01:00
Antonio Niño Díaz
c2af70fe15 docs: Update changelog 2024-06-08 12:53:34 +01:00
Antonio Niño Díaz
dce5e99f0f library: Optimize copy of NE_RGB5 textures to VRAM
This is the same optimization made by asie here:

479ca8fb77
2024-06-05 02:28:40 +01:00
Antonio Niño Díaz
1c752174e9 examples: Stop using NE_RGB5 in examples
This texture format sets bit 15 manually to 1. This is slow, and it's
better if the developer converts graphics in a way that the bit is already
set to 1.
2024-06-03 18:39:33 +01:00
Antonio Niño Díaz
935f7eb084 examples: Update binaries used by the examples
This isn't strictly required, but this way running the global assets.sh
won't cause lots of files to be marked as modified.
2024-06-02 21:55:32 +01:00
Antonio Niño Díaz
0f92fc9da7 build: Use BlocksDS paths for assets conversion scripts 2024-06-02 21:50:06 +01:00
Antonio Niño Díaz
3f4bfbdb25 examples: Remove unused files 2024-06-02 18:06:51 +01:00
Antonio Niño Díaz
b52b704000 build: Rename BlocksDS makefile 2024-06-02 18:06:00 +01:00
Antonio Niño Díaz
902314a2ac docs: build: Add simplified global build targets 2024-06-02 17:38:55 +01:00
Antonio Niño Díaz
3ba35ba48e docs: build: library: examples: Set BlocksDS as main toolchain
Until now the main makefiles of Nitro Engine have been the ones of
devkitPro, forcing users to go through extra steps to build everything
under BlocksDS.

Now, the easy makefiles are the BlocksDS ones, and additional notes have
been added to warn about the limitations of devkitPro:

- No GRF support in libnds.
- NitroFS doesn't work in melonDS.
2024-06-02 17:38:52 +01:00
Antonio Niño Díaz
381e4071ac tools: Update md5_2_dsma
This fixes a bug where the base animation of the model (its standing pose)
would be exported with the wrong extension.
2024-06-02 12:08:08 +01:00
Antonio Niño Díaz
ccb3739f98 docs: Add note about ArchitectDS to the readme 2024-06-01 02:03:38 +01:00
Antonio Niño Díaz
230a65541e docs: Remove version from readme
This gets out of date easily and it isn't that useful anyway.
2024-04-09 01:53:49 +01:00
Antonio Niño Díaz
7dda3abe54 docs: Update changelog 2024-03-30 11:41:28 +00:00
Antonio Niño Díaz
3f3e266a4f library: Implement priority setting functions in RichText
This reverts commit 48ff37231f ("library: Remove unimplemented
functions from RichText system").

I thought the 3D drawing functions took a "depth" argument, but I was
wrong. I'm re-introducing the functions (and, this time, with an actual
implementation).
2024-03-30 00:34:39 +00:00
Antonio Niño Díaz
5ce71a9b02 library: Add function to calculate rendered text size
This simply exposes DSF_StringRenderDryRun() in a way that can be easily
used with Nitro Engine.
2024-03-29 22:21:22 +00:00
Antonio Niño Díaz
12b7389d1f examples: Remove asset from example that doesn't use it 2024-03-29 19:39:12 +00:00
Antonio Niño Díaz
48ff37231f library: Remove unimplemented functions from RichText system
They were never meant to be there, they are a copy-paste error from taking
the code of the original text system to create the original files of the
rich text system.
2024-03-29 14:56:55 +00:00
William
ff734036fc
fix: NE_RichTextMetadataLoadFAT returning error code on success 2024-03-28 14:19:30 +00:00
Antonio Niño Díaz
d7ecc5cc4d templates: examples: Fix linker invocation for C++
Using g++ to link object files automatically links the STD of C++. It looks
like this library is linked outside of the start/end-group commands with
the other libraries, which causes undefined reference errors when linking
C++ projects that use standard library functions that interface with the
OS, like `fopen()`.

Thanks to @lifehackerhansol for the report and testing the fix.
2024-03-26 18:54:35 +00:00
Antonio Niño Díaz
5ea29c4f81 docs: Update sprites screenshot in readme 2024-03-24 16:52:19 +00:00
Antonio Niño Díaz
b40f67c593 examples: Improve sprites example 2024-03-24 16:50:51 +00:00
Antonio Niño Díaz
8cb10264bb library: Support setting texture coordinates in sprites
This allows you to use one single texture for multiple images, and to
specify the coordinates that a sprite needs to use so that you don't need
to keep track of them.
2024-03-24 16:14:21 +00:00
Antonio Niño Díaz
cf1a3c48e2 library: Fix build on devkitARM 2024-03-20 23:42:15 +00:00
Antonio Niño Díaz
b0d9151455 library: Build some functions as ARM to increase performance
Using `mulf32()` while compiling functions to Thumb makes the compiler
add calls to `__aeabi_lmul()` once per multiplication. This routine is
quite slow, so the cost of any function that uses `mulf32()` a lot is
quite high.

Switching math-heavy functions to ARM increases performance and reduces
code size.
2024-03-16 03:04:02 +01:00
Antonio Niño Díaz
82171bbf69 chore: Simplify copyright years in notices
Instead of listing every individual year, keep only the first and last
years.
2024-03-09 01:42:29 +00:00
Antonio Niño Díaz
47c8061168 examples: test: Refactor to avoid global variables
Using global variables is generally discouraged. Now that NE_ProcessArg()
and NE_ProcessDualArg() exist, it's better to show how to use them instead
of NE_Process() and NE_ProcessDual() while using global variables.

Also, switch from "int main(void)" to "int main(int argc, char *argv[])".
2024-03-08 18:44:02 +00:00
Antonio Niño Díaz
9f81541075 examples: Remove global variables from some examples 2024-03-08 02:43:18 +00:00
Antonio Niño Díaz
a06617a93f examples: Cleanup variables of 2D quads example 2024-03-08 02:43:18 +00:00
Antonio Niño Díaz
fc73687b79 docs: Update list of future work items 2024-03-07 02:41:06 +00:00
Antonio Niño Díaz
052a15b974 example: Stop using deprecated NE_ShadingEnabled() 2024-03-07 01:49:25 +00:00
Antonio Niño Díaz
bf63ddea8a examples: Remove unneeded calls to NE_ShadowEnable()
This function wasn't required for regular shading, but for toon shading.
2024-03-07 01:49:07 +00:00
Antonio Niño Díaz
636a7d73c3 library: Deprecate NE_ShadingEnable()
This has been replaced by NE_SetupToonShadingTables(), which is a more
sensible name.

A define has been added for compatibility.
2024-03-07 01:48:34 +00:00
Antonio Niño Díaz
521012d4d1 library: Add function to reset rich text system 2024-03-07 01:26:15 +00:00
Antonio Niño Díaz
15ce18b74c examples: Add example of loading rich text fonts from RAM 2024-03-07 01:22:36 +00:00
Antonio Niño Díaz
dd746c0ef5 library: Allow loading font bitmaps from RAM, not just the filesystem 2024-03-07 01:20:00 +00:00
Antonio Niño Díaz
a49ddecda7 examples: Fix incorrect comments 2024-03-06 23:05:28 +00:00
Antonio Niño Díaz
30ac9ab8e9 library: Don't expect palette objects when loading GRF files
Currently, if the user wants to load a GRF file with a palette, the
function NE_MaterialTexLoadGRF() will fail unless it is provided a palette
object.

With this change, if a palette object isn't provided, it will be created
and marked for automatic deletion when the material is deleted.
2024-03-06 22:17:49 +00:00
Antonio Niño Díaz
edf4457d49 examples: Fix typo 2024-03-06 22:02:30 +00:00
Antonio Niño Díaz
e952990ae4 examples: Improve volumetric shadow example
The light in the dark room was too bright.
2024-03-06 21:41:11 +00:00
Antonio Niño Díaz
3273bd7333 examples: Fix comment 2024-03-06 21:41:11 +00:00
Antonio Niño Díaz
c22fa167e7 docs: Add shadow volume screenshot to readme 2024-03-06 21:41:11 +00:00
Antonio Niño Díaz
5a2b722128 examples: Add shadow volume example 2024-03-06 21:41:11 +00:00
Antonio Niño Díaz
227bffddc5 library: Fix compilation with devkitARM 2024-03-06 01:31:40 +00:00
Antonio Niño Díaz
a85b16284f library: Update libDSF to version 0.1.2 2024-03-05 01:55:19 +00:00
Antonio Niño Díaz
006bcf9d01 library: Add note about texture sizes for rich text 2024-03-03 19:59:49 +00:00
Antonio Niño Díaz
366a9532c1 libdsf: Update to version 0.1.1 2024-03-03 19:59:15 +00:00
Antonio Niño Díaz
719935647a library: Relicense libdsf under "Zlib OR MIT"
Nitro Engine and DSMA use the MIT license. This way everything can be used
under the MIT license.
2024-03-02 18:47:38 +00:00
Antonio Niño Díaz
e94ed5b4e3 docs: Add screenshot of text rendering to readme 2024-03-02 18:43:19 +00:00
Antonio Niño Díaz
935c06e296 library: Add note about the replacement character 2024-03-02 18:42:00 +00:00
Antonio Niño Díaz
c0d41eabff doc: library: Increase version to 0.11.0 2024-03-02 14:21:47 +00:00
Antonio Niño Díaz
9c62fbf0f2 docs: Update changelog 2024-03-02 13:20:53 +00:00
Antonio Niño Díaz
9c3bb283cc library: Add note to old text system 2024-03-02 13:14:45 +00:00
Antonio Niño Díaz
3e6af44b1b examples: Move old text example to text folder 2024-03-02 13:13:28 +00:00
Antonio Niño Díaz
9fd31b81ad examples: Add example of using rich text from NitroFS 2024-03-02 13:13:28 +00:00
Antonio Niño Díaz
50e14b2c21 library: Add rich text support
This support relies on BMFont: https://www.angelcode.com/products/bmfont/

Nitro Engine doesn't support that format directly. Instead, it uses
LibDSF internally: https://github.com/AntonioND/libdsf
2024-03-02 13:07:44 +00:00
Antonio Niño Díaz
951f0f87ca library: Support autodeleting palettes
In many cases the developer doesn't want to keep track of palettes and
materials as two different objects. This is only required if a palette
needs to be shared between multiple materials.

In cases where there a palette is only used by one material, this new
function can be used so that the developer doesn't need to keep track of
the palette object, only the material.
2024-03-02 12:42:31 +00:00
Antonio Niño Díaz
e7fc9f8203 library: Silence warnings of unused variables 2024-03-02 12:42:08 +00:00
Antonio Niño Díaz
a7f8353bac library: Set sprite size to the texture size it is assigned
What most people will want to do is to draw sprites with the same size as
the texture, so do that by default.
2024-02-28 02:50:29 +00:00
Antonio Niño Díaz
3af40682cb examples: Don't print text when using dual 3D FB mode
When using dual 3D DMA mode the console is setup to use memory in the
middle of SUB background VRAM. This is what holds the text that you can see
on the screen.

When switching to FB mode, the console is never reconfigured (when
switching to regular dual 3D mode it is reconfigured). This means that any
printf will write to the middle of background VRAM, which is used as
framebuffer. This will manifest itself as a blue horizontal line in the
middle of the screen.

This patch fixes the examples to not print text when using FB mode.
2024-02-18 01:42:01 +00:00
Antonio Niño Díaz
b00a4f29b8 library: Refactor sprite setup in dual 3D modes
Instead of allocating the buffer permanently, only allocate it while the
sprites are setup. Then, free the buffer.

Also, the cache needs to be flushed before doing a DMA copy. This used to
cause black squares on the screen because of some sprite attributes not
being properly copied to OAM.
2024-02-18 01:22:23 +00:00
Antonio Niño Díaz
25fc0bcff3 library: Update usage of GRF libnds functions 2024-02-15 17:49:50 +00:00
Antonio Niño Díaz
83dd805fe8 examples: library: docs: Fix "properties" typo everywhere
Function names have also been changed, but this patch adds defines to
preserve compatibility with old names for the time being.
2024-02-05 01:45:14 +00:00
Antonio Niño Díaz
4d0066465e docs: library: Update version to 0.10.0 2024-01-28 02:35:35 +00:00
Antonio Niño Díaz
91abea3e87 tests: Fix build of LCD depth test example 2024-01-28 02:35:35 +00:00
Antonio Niño Díaz
a44073e9ce examples: Fix makefile not handling defines correctly 2024-01-28 01:59:05 +00:00
Antonio Niño Díaz
cf12e3d51d img2ds: Add another deprecation notice 2024-01-28 01:44:50 +00:00
Antonio Niño Díaz
441997c50c examples: Remove unused files in NFlib template 2024-01-27 19:47:12 +00:00
Antonio Niño Díaz
d432916f0a examples: Simplify GRF loading example 2024-01-27 19:43:27 +00:00
Antonio Niño Díaz
488f5c7d8f library: Small style fixes 2024-01-27 19:34:15 +00:00
Antonio Niño Díaz
33f9bd4416 examples: Remove unneeded casts
They were needed in older versions of Nitro Engine, but now the functions
that take data arrays expect a void pointer, so casts are not needed.
2024-01-27 19:33:56 +00:00
Antonio Niño Díaz
9ce79478e0 img2ds: Update readme to mention img2ds is deprecated 2024-01-27 18:41:59 +00:00
Antonio Niño Díaz
1a29d63a6d img2ds: Deprecate tool for regular textures
It's unlikely this tool will be removed from the repository, but it's no
longer going to be maintained now that the version of grit included in
BlocksDS has had a few bugs related to NDS textures fixed.

The main purpose for img2ds was to eventually support compressed
textures, but ptexconv already does a good job at it.
2024-01-27 18:39:42 +00:00
Antonio Niño Díaz
83928fd8aa tests: Use grit instead of img2ds 2024-01-27 18:36:14 +00:00
Antonio Niño Díaz
1c58dd09ed docs: Update readme 2024-01-27 18:33:03 +00:00
Antonio Niño Díaz
55a53a91dc examples: Add warnings to BlocksDS makefiles 2024-01-27 18:31:17 +00:00
Antonio Niño Díaz
c037b79af4 examples: Stop using img2ds and switch to grit
img2ds is still required for the clear bitmap example because grit doesn't
support the clear depth format.
2024-01-27 18:25:38 +00:00
Antonio Niño Díaz
c8324ca1b9 examples: Migrate 2D examples to grit 2024-01-27 03:35:03 +00:00
Antonio Niño Díaz
1d0b3058aa examples: Add example of loading GRF files 2024-01-25 18:28:13 +00:00
Antonio Niño Díaz
8e6d64d2d9 library: Disable GRF loading function outside of BlocksDS
This isn't supported in devkitPro.
2024-01-25 18:28:07 +00:00
Antonio Niño Díaz
640d2441f6 library: Add helper to load textures in GRF format 2024-01-25 02:42:38 +00:00
Antonio Niño Díaz
fb503d5972 library: Add deprecation notice 2024-01-25 02:05:24 +00:00
Antonio Niño Díaz
5fbe47c7fc examples: Refactor compressed texture example
Add PNG files that get converted to the binary data used by the NDS ROM.
2024-01-22 02:28:51 +00:00
Antonio Niño Díaz
a57af044f4 library: Make some pointers void and const
It doesn't make sense to use other types because the modified functions
treat the data as a constant binary blob.
2024-01-22 02:26:57 +00:00
Antonio Niño Díaz
142e1662b6 examples: Clarify Texel 4x4 format example 2024-01-21 17:00:57 +00:00
Antonio Niño Díaz
65b4eb55a3 library: Add alternate functions to load Texel 4x4 textures
They can be used to load textures where the 3 chunks are stored as
different files.
2024-01-21 17:00:12 +00:00
Antonio Niño Díaz
0a7db208da docs: Update doxyfile 2024-01-21 16:20:22 +00:00
Antonio Niño Díaz
bacb1d1811 chore: Remove comments about NE_PolyEnd() being ignored
It's not 100% clear that the command is ignored. It's better to remove
the comments unless we're completely sure about it.
2024-01-10 19:28:13 +00:00
Antonio Niño Díaz
eca99150c4 examples: Add simple example of loading models from nitroFS 2024-01-03 00:52:33 +01:00
Antonio Niño Díaz
9a5c6dfa67 library: Use NULL insted of 0 for clarity 2024-01-02 02:49:13 +01:00
Antonio Niño Díaz
e6e27fed0a library: Remove unnecessary DC_FlushAll()
The buffer that is passed to fwrite() is written by the CPU, not by DMA.
It isn't needed to do anything to the cache.
2024-01-02 01:10:42 +01:00
Antonio Niño Díaz
36957b04ab library: Add warning about screenshot function 2024-01-02 01:09:18 +01:00
Antonio Niño Díaz
53a382e8ac build: Update BlocksDS makefile 2024-01-02 01:08:10 +01:00
Antonio Niño Díaz
f885f25bfb tools: Clarify some comments 2024-01-01 03:50:16 +01:00
Antonio Niño Díaz
2ec91e1100 examples: Add missing include 2024-01-01 03:35:34 +01:00
Antonio Niño Díaz
d03ccfddd5 obj2dl: Fix vertical texture coordinate 2024-01-01 03:35:25 +01:00
Antonio Niño Díaz
2d7a71a056 build: Install tools to BlocksDS directory 2023-12-31 02:09:00 +01:00
Antonio Niño Díaz
7cd5d3999c obj2dl: Improve error message 2023-12-26 23:52:55 +01:00
Antonio Niño Díaz
76dc2f9901 library: Make some small functions static inline 2023-11-17 01:00:40 +01:00
Antonio Niño Díaz
6fde18d712 library: examples: Use stdint.h types 2023-11-17 01:00:40 +01:00
Antonio Niño Díaz
ec72c4080d examples: Add example of new process functions with arguments 2023-11-17 00:46:40 +01:00
Antonio Niño Díaz
88e222c756 library: Add new process functions that can take arguments
The functions called by NE_Process() and NE_ProcessDual() rely on global
data to know what to draw on the screen.

The functions called by the new NE_ProcessArg() and NE_ProcessDualArg()
can take arguments passed from the caller of the process function. This way
it isn't needed to have global variables.
2023-11-17 00:46:23 +01:00
453 changed files with 7652 additions and 13114 deletions

79
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,79 @@
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2025
name: Documentation
on:
push:
branches:
- 'master'
paths-ignore:
- '**.rst'
- 'examples'
- 'licenses'
- 'Makefile*'
- 'source*'
- 'tests'
- 'tools'
workflow_dispatch:
repository_dispatch:
types: [run_build]
permissions:
contents: read
pages: write
id-token: write
packages: write
jobs:
generate_website:
name: Generate website
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- name: Clone project
uses: actions/checkout@v4
with:
ref: 'master'
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt-get install doxygen
- name: Build documentation
run: |
cd documentation
bash generate.sh
# Create tarball with everything to upload to GitHub pages
cd html
tar -cvf ../../repo.tar ./*
- name: Upload repo artifact
uses: actions/upload-artifact@v4
with:
name: github-pages
path: repo.tar
if-no-files-found: error
publish_repo:
name: Publish website with GitHub pages
if: contains(github.ref,'refs/heads/master')
needs: [generate_website]
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

146
Makefile
View File

@ -1,139 +1,23 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2024
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
# Tools
# -----
include $(DEVKITARM)/ds_rules
MAKE := make
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
SOURCES := source source/dsma
DATA := data
INCLUDES := include
# Targets
# -------
ifeq ($(NE_DEBUG),1)
TARGET := NE_debug
BUILD := build_debug
else
TARGET := NE
BUILD := build_release
endif
.PHONY: all install clean
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
all:
$(MAKE) -f Makefile.blocksds
$(MAKE) -f Makefile.blocksds NE_DEBUG=1
CFLAGS := -g -Wall -O2\
-march=armv5te -mtune=arm946e-s \
-fomit-frame-pointer -ffast-math \
$(ARCH) -Wno-address-of-packed-member
install: all
$(MAKE) -f Makefile.blocksds install
ifeq ($(NE_DEBUG),1)
CFLAGS += -DNE_DEBUG
endif
CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS :=
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
lib:
@[ -d $@ ] || mkdir -p $@
$(BUILD): lib
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr build_debug build_release lib
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT) : $(OFILES)
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
$(MAKE) -f Makefile.blocksds clean

View File

@ -12,7 +12,7 @@ ARM_NONE_EABI_PATH ?= $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-arm-none-eabi/bin/
# -----------------
SOURCEDIRS := source
INCLUDEDIRS := include
INCLUDEDIRS := include source/libdsf
GFXDIRS :=
BINDIRS :=
@ -49,7 +49,7 @@ ARCHIVE := lib/lib$(NAME).a
PREFIX := $(ARM_NONE_EABI_PATH)arm-none-eabi-
CC := $(PREFIX)gcc
CXX := $(PREFIX)g++
AR := ar
AR := $(PREFIX)ar
MKDIR := mkdir
RM := rm -rf
CP := cp
@ -92,16 +92,16 @@ WARNFLAGS := -Wall -Wno-address-of-packed-member
INCLUDEFLAGS := $(foreach path,$(INCLUDEDIRS),-I$(path)) \
$(foreach path,$(LIBDIRS),-I$(path)/include)
ASFLAGS += -x assembler-with-cpp $(DEFINES) $(ARCH) \
ASFLAGS += -g -x assembler-with-cpp $(DEFINES) $(ARCH) \
-mthumb -mthumb-interwork $(INCLUDEFLAGS) \
-ffunction-sections -fdata-sections
CFLAGS += -std=gnu11 $(WARNFLAGS) $(DEFINES) $(ARCH) \
CFLAGS += -g -std=gnu11 $(WARNFLAGS) $(DEFINES) $(ARCH) \
-mthumb -mthumb-interwork $(INCLUDEFLAGS) -O2 \
-ffunction-sections -fdata-sections \
-fomit-frame-pointer
CXXFLAGS += -std=gnu++14 $(WARNFLAGS) $(DEFINES) $(ARCH) \
CXXFLAGS += -g -std=gnu++14 $(WARNFLAGS) $(DEFINES) $(ARCH) \
-mthumb -mthumb-interwork $(INCLUDEFLAGS) -O2 \
-ffunction-sections -fdata-sections \
-fno-exceptions -fno-rtti \
@ -139,8 +139,15 @@ $(ARCHIVE): $(OBJS)
install: all
@echo " INSTALL $(BLOCKSDSEXT)/$(INSTALLNAME)/"
$(V)$(RM) $(BLOCKSDSEXT)/$(INSTALLNAME)/
$(V)$(INSTALL) -d $(BLOCKSDSEXT)/$(INSTALLNAME)/
$(V)$(INSTALL) -d $(BLOCKSDSEXT)/$(INSTALLNAME)/ \
$(BLOCKSDSEXT)/$(INSTALLNAME)/tools/img2ds \
$(BLOCKSDSEXT)/$(INSTALLNAME)/tools/md5_to_dsma \
$(BLOCKSDSEXT)/$(INSTALLNAME)/tools/obj2dl
$(V)$(CP) -r include lib $(BLOCKSDSEXT)/$(INSTALLNAME)/
$(V)$(CP) -r tools/img2ds/*.py $(BLOCKSDSEXT)/$(INSTALLNAME)/tools/img2ds
$(V)$(CP) -r tools/md5_to_dsma/*.py $(BLOCKSDSEXT)/$(INSTALLNAME)/tools/md5_to_dsma
$(V)$(CP) -r tools/obj2dl/*.py $(BLOCKSDSEXT)/$(INSTALLNAME)/tools/obj2dl
$(V)$(CP) -r licenses $(BLOCKSDSEXT)/$(INSTALLNAME)/
clean:
@echo " CLEAN"

View File

@ -1,6 +1,123 @@
Changelog
=========
Version 0.15.3 (2025-03-26)
---------------------------
- The devkitARM makefiles have been removed as they only work with old versions
of devkitARM, which aren't supported by its maintainers. The code and examples
of Nitro Engine will probably need changes to work with current devkitARM.
- The GRF files used in an example have been updated, they were built before the
format was changed.
- The build scripts for assets have been modified to use the value of the
environment variables ``BLOCKSDS`` and ``BLOCKSDSEXT`` if they are found.
- Build library with debug symbols to help debug applications that use it.
Version 0.15.2 (2025-01-15)
---------------------------
- Fix `ar` binary used to build the library.
- Update documentation.
- Fix build of examples in devkitARM.
- Improve setup instructions.
Version 0.15.1 (2024-12-23)
---------------------------
- Install licenses with the rest of the library.
- Clarify some comments in examples.
Version 0.15.0 (2024-12-01)
---------------------------
- Allow users to specify the transformation matrix of a model manually.
- Fix a devkitARM Makefile in an example.
Version 0.14.0 (2024-09-10)
---------------------------
- Use ``stdint.h`` types instead of libnds types.
- Update BlocksDS makefiles.
- Update libdsf to v0.1.3.
- Fix some memory leaks/use-after-free bugs in the RichText module.
Version 0.13.0 (2024-06-08)
---------------------------
- Define BlocksDS as the main toolchain to use with Nitro Engine.
- Simplify build and installation instructions of the library.
- Update ``md5_2_dsma`` to correctly export the base animation of models.
- Stop using ``NE_RGB5`` in the examples, this format is discouraged.
- Optimize copy of ``NE_RGB5`` textures to VRAM.
Version 0.12.0 (2024-03-30)
---------------------------
- Deprecate ``NE_ShadingEnable()``. The name was misleading. All examples that
use it have stopped calling it.
- For sprites, add a way to specify texture coordinates inside the material to
use a small part of the texture instead of the whole texture:
``NE_SpriteSetMaterialCanvas()``. This is now used in the sprites example.
- Stop using global variables in most examples. Instead, the rendering functions
get values through the arguments of ``NE_ProcessArg()`` and
``NE_ProcessDualArg()``.
- Don't expect palette objects when loading GRF files if the file doesn't
contain a palette.
- Allow loading BMFont fonts from RAM, not just nitroFS. Add an example of
using rich text fonts from RAM.
- Added a function to reset the rich text font system. Also add a function to
return the size that a specific text string would have if drawn.
- Add shadow volume example.
- Build some functions that do lots of multiplications as ARM to increase
performance.
- Fix compilation with devkitARM.
- Fix linker invocation for C++ with BlocksDS.
- Update libDSF to version 0.1.2, with some speed improvements.
- Relicensed libDSF under "Zlib OR MIT" to simplify licensing with Nitro Engine.
- Some minor documentation improvements.
Version 0.11.0 (2024-03-02)
---------------------------
- Added a rich text system. This allows the user to draw non-monospaced text,
and it's based on `BMFont <https://www.angelcode.com/products/bmfont/>`_. An
example has been added to show how to use it to render text. It can render
text by using one quad per character, or by rendering to a texture which is
then drawn as a single quad.
- Fix "properties" typo. This involves renaming some functions, but compatibilty
definitions have been added.
- Update calls to GRF libnds functions after their prototypes have changed.
- Cleanup setup of dual 3D modes that involve setting up 2D sprites to be used
as a framebuffer.
- Now the size of a sprite is set to the size of the material it is assigned. It
can be modified later as usual.
Version 0.10.0 (2024-01-28)
---------------------------
- Create variants of ``NE_Process()`` and ``NE_ProcessDual()`` that can pass an
argument to the screen draw callbacks.
- Add function to load textures in GRF format (BlocksDS only).
- Add functions to load compressed textures (Texel 4x4 format).
- Add examples to load assets from the filesystem, both in binary and GRF
function.
- Cleanup code style: Use stdint types, turn some functions ``static inline``...
- Remove unneeded call to ``DC_FlushAll()``.
- ``obj2dl``: Improve error message. Fix vertical coordinates being flipped.
- ``img2ds``: Deprecate it except for generating ``DEPTHBMP`` binaries.
- The makefile for BlocksDS now installs the tools to ``/opt/blockds/external``,
not only the library and headers.
- Migrate all examples to using ``grit`` instead of ``img2ds``.
Version 0.9.1 (2023-11-12)
--------------------------
@ -170,9 +287,9 @@ Version 0.6.0 (2009-6-30)
- The functions used to modify textures and palettes now return a pointer to the
data so that you can modify them easily.
- Each material can have different propierties (amient, diffuse...). You can set
the default ones, the propierties each new material will have, and then you
can set each material's propierties individually.
- Each material can have different properties (amient, diffuse...). You can set
the default ones, the properties each new material will have, and then you
can set each material's properties individually.
- New texture and palette allocation system, it is faster and better.
Defragmenting functions don't work now, but I'll fix them for the next

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,25 @@
SUBDIRS:= `ls`
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2023-2024
.PHONY: all clean
MAKE := make
all:
@for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done;
@for i in `ls`; do \
if test -e $$i/Makefile ; then \
cd $$i; \
$(MAKE) --no-print-directory || exit 1 ; \
cd ..; \
fi; \
done;
clean:
@for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done;
@for i in `ls`; do \
if test -e $$i/Makefile ; then \
cd $$i; \
$(MAKE) clean --no-print-directory || exit 1 ; \
cd ..; \
fi; \
done;

View File

@ -1,25 +0,0 @@
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2023
.PHONY: all clean
MAKE := make
all:
@for i in `ls`; do \
if test -e $$i/Makefile.blocksds ; then \
cd $$i; \
$(MAKE) -f Makefile.blocksds --no-print-directory || { exit 1;}; \
cd ..; \
fi; \
done;
clean:
@for i in `ls`; do \
if test -e $$i/Makefile.blocksds ; then \
cd $$i; \
$(MAKE) -f Makefile.blocksds clean --no-print-directory || { exit 1;}; \
cd ..; \
fi; \
done;

View File

@ -1,220 +1,6 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
GFXDIRS := graphics
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,25 +0,0 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
TOOLS=$NITRO_ENGINE/tools
IMG2DS=$TOOLS/img2ds/img2ds.py
mkdir -p data
python3 $IMG2DS \
--input assets/button.png \
--name button \
--output data \
--format PAL256
python3 $IMG2DS \
--input assets/empty.png \
--name empty \
--output data \
--format PAL256
python3 $IMG2DS \
--input assets/true.png \
--name true \
--output data \
--format PAL256

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 882 B

View File

@ -0,0 +1,2 @@
# 256 color palette
-gx -gb -gB8 -gTFF00FF

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -0,0 +1,2 @@
# 256 color palette
-gx -gb -gB8 -gTFF00FF

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -0,0 +1,2 @@
# 256 color palette
-gx -gb -gB8 -gTFF00FF

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -1,17 +1,14 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2022
//
// This file is part of Nitro Engine
#include <NEMain.h>
#include "button_tex_bin.h"
#include "button_pal_bin.h"
#include "empty_tex_bin.h"
#include "empty_pal_bin.h"
#include "true_tex_bin.h"
#include "true_pal_bin.h"
#include "button.h"
#include "empty.h"
#include "true.h"
void Draw3DScene(void)
{
@ -19,7 +16,7 @@ void Draw3DScene(void)
NE_GUIDraw();
}
int main(void)
int main(int argc, char *argv[])
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
@ -50,20 +47,20 @@ int main(void)
NE_MaterialTexLoad(ButtonImg, NE_PAL256, 64, 64,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_COLOR0_TRANSPARENT,
(void *)button_tex_bin);
NE_PaletteLoad(ButtonPal, (void *)button_pal_bin, 256, NE_PAL256);
buttonBitmap);
NE_PaletteLoad(ButtonPal, buttonPal, 256, NE_PAL256);
NE_MaterialSetPalette(ButtonImg, ButtonPal);
NE_MaterialTexLoad(EmptyImg, NE_PAL256, 64, 64,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_COLOR0_TRANSPARENT,
(void *)empty_tex_bin);
NE_PaletteLoad(EmptyPal, (void *)empty_pal_bin, 256, NE_PAL256);
emptyBitmap);
NE_PaletteLoad(EmptyPal, emptyPal, 256, NE_PAL256);
NE_MaterialSetPalette(EmptyImg, EmptyPal);
NE_MaterialTexLoad(TrueImg, NE_PAL256, 64, 64,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_COLOR0_TRANSPARENT,
(void *)true_tex_bin);
NE_PaletteLoad(TruePal, (void *)true_pal_bin, 256, NE_PAL256);
trueBitmap);
NE_PaletteLoad(TruePal, truePal, 256, NE_PAL256);
NE_MaterialSetPalette(TrueImg, TruePal);

View File

@ -1,220 +1,6 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
GFXDIRS := graphics
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,31 +0,0 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
TOOLS=$NITRO_ENGINE/tools
IMG2DS=$TOOLS/img2ds/img2ds.py
mkdir -p data
python3 $IMG2DS \
--input assets/s8.png \
--name s8 \
--output data \
--format PAL16
python3 $IMG2DS \
--input assets/s16.png \
--name s16 \
--output data \
--format PAL16
python3 $IMG2DS \
--input assets/s64.png \
--name s64 \
--output data \
--format PAL16
python3 $IMG2DS \
--input assets/s256.png \
--name s256 \
--output data \
--format PAL16

View File

@ -1 +0,0 @@
!!1DD1DDA`&A`&A6eA6eA&`A&`Ae6Ae6!DD!DD11!!1DD1DDA`&A`&A6eA6eA&`A&`Ae6Ae6!DD!DD11

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
!!!!!!!!1DD1DD1DD1DD1DD1DD1DD1DDA`&A`&A`&A`&A`&A`&A`&A`&A6eA6eA6eA6eA6eA6eA6eA6eA&`A&`A&`A&`A&`A&`A&`A&`Ae6Ae6Ae6Ae6Ae6Ae6Ae6Ae6!DD!DD!DD!DD!DD!DD!DD!DD11111111!!!!!!!!1DD1DD1DD1DD1DD1DD1DD1DDA`&A`&A`&A`&A`&A`&A`&A`&A6eA6eA6eA6eA6eA6eA6eA6eA&`A&`A&`A&`A&`A&`A&`A&`Ae6Ae6Ae6Ae6Ae6Ae6Ae6Ae6!DD!DD!DD!DD!DD!DD!DD!DD11111111!!!!!!!!1DD1DD1DD1DD1DD1DD1DD1DDA`&A`&A`&A`&A`&A`&A`&A`&A6eA6eA6eA6eA6eA6eA6eA6eA&`A&`A&`A&`A&`A&`A&`A&`Ae6Ae6Ae6Ae6Ae6Ae6Ae6Ae6!DD!DD!DD!DD!DD!DD!DD!DD11111111!!!!!!!!1DD1DD1DD1DD1DD1DD1DD1DDA`&A`&A`&A`&A`&A`&A`&A`&A6eA6eA6eA6eA6eA6eA6eA6eA&`A&`A&`A&`A&`A&`A&`A&`Ae6Ae6Ae6Ae6Ae6Ae6Ae6Ae6!DD!DD!DD!DD!DD!DD!DD!DD11111111!!!!!!!!1DD1DD1DD1DD1DD1DD1DD1DDA`&A`&A`&A`&A`&A`&A`&A`&A6eA6eA6eA6eA6eA6eA6eA6eA&`A&`A&`A&`A&`A&`A&`A&`Ae6Ae6Ae6Ae6Ae6Ae6Ae6Ae6!DD!DD!DD!DD!DD!DD!DD!DD11111111!!!!!!!!1DD1DD1DD1DD1DD1DD1DD1DDA`&A`&A`&A`&A`&A`&A`&A`&A6eA6eA6eA6eA6eA6eA6eA6eA&`A&`A&`A&`A&`A&`A&`A&`Ae6Ae6Ae6Ae6Ae6Ae6Ae6Ae6!DD!DD!DD!DD!DD!DD!DD!DD11111111!!!!!!!!1DD1DD1DD1DD1DD1DD1DD1DDA`&A`&A`&A`&A`&A`&A`&A`&A6eA6eA6eA6eA6eA6eA6eA6eA&`A&`A&`A&`A&`A&`A&`A&`Ae6Ae6Ae6Ae6Ae6Ae6Ae6Ae6!DD!DD!DD!DD!DD!DD!DD!DD11111111!!!!!!!!1DD1DD1DD1DD1DD1DD1DD1DDA`&A`&A`&A`&A`&A`&A`&A`&A6eA6eA6eA6eA6eA6eA6eA6eA&`A&`A&`A&`A&`A&`A&`A&`Ae6Ae6Ae6Ae6Ae6Ae6Ae6Ae6!DD!DD!DD!DD!DD!DD!DD!DD11111111

View File

@ -1 +0,0 @@
!1DDA`&A6eA&`Ae6!DD1

View File

@ -0,0 +1,2 @@
# 16 color palette
-gx -gb -gB4 -gTFF00FF

View File

Before

Width:  |  Height:  |  Size: 606 B

After

Width:  |  Height:  |  Size: 606 B

View File

@ -0,0 +1,2 @@
# 16 color palette
-gx -gb -gB4 -gTFF00FF

View File

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -0,0 +1,2 @@
# 16 color palette
-gx -gb -gB4 -gTFF00FF

View File

Before

Width:  |  Height:  |  Size: 678 B

After

Width:  |  Height:  |  Size: 678 B

View File

@ -0,0 +1,2 @@
# 16 color palette
-gx -gb -gB4 -gTFF00FF

View File

Before

Width:  |  Height:  |  Size: 583 B

After

Width:  |  Height:  |  Size: 583 B

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2024
//
// This file is part of Nitro Engine
@ -13,20 +13,20 @@
#include <NEMain.h>
#include "s8_tex_bin.h"
#include "s8_pal_bin.h"
#include "s16_tex_bin.h"
#include "s16_pal_bin.h"
#include "s64_tex_bin.h"
#include "s64_pal_bin.h"
#include "s256_tex_bin.h"
#include "s256_pal_bin.h"
#include "s8.h"
#include "s16.h"
#include "s64.h"
#include "s256.h"
NE_Material *Material_s8, *Material_s16, *Material_s64, *Material_s256;
NE_Palette *Palette_s8, *Palette_s16, *Palette_s64, *Palette_s256;
typedef struct {
NE_Material *Material_s8, *Material_s16, *Material_s64, *Material_s256;
NE_Palette *Palette_s8, *Palette_s16, *Palette_s64, *Palette_s256;
} SceneData;
void Draw3DScene(void)
void Draw3DScene(void *arg)
{
SceneData *Scene = arg;
NE_ClearColorSet(NE_DarkGray, 31, 63);
NE_2DViewInit();
@ -34,27 +34,29 @@ void Draw3DScene(void)
// Texture scaled from 64x64 to 128x128
NE_2DDrawTexturedQuad(10, 10,
10 + 128, 10 + 128,
2, Material_s64);
2, Scene->Material_s64);
// Texture scaled from 8x8 to 32x32
NE_2DDrawTexturedQuad(150, 10,
150 + 32, 10 + 32,
0, Material_s8);
0, Scene->Material_s8);
// Texture not scaled
NE_2DDrawTexturedQuad(160, 50,
160 + 64, 50 + 64,
10, Material_s64);
10, Scene->Material_s64);
// Texture scaled from 16x16 to 64x64
NE_2DDrawTexturedQuad(150, 120,
150 + 64, 120 + 64,
1, Material_s16);
1, Scene->Material_s16);
}
void Draw3DScene2(void)
void Draw3DScene2(void *arg)
{
SceneData *Scene = arg;
NE_ClearColorSet(NE_Magenta, 31, 63);
NE_2DViewInit();
@ -62,55 +64,57 @@ void Draw3DScene2(void)
// Texture not scaled
NE_2DDrawTexturedQuad(-10, -70,
-10 + 256, -70 + 256,
3, Material_s256);
3, Scene->Material_s256);
}
int main(void)
int main(int argc, char *argv[])
{
SceneData Scene = { 0 };
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_InitDual3D();
Material_s8 = NE_MaterialCreate();
Material_s16 = NE_MaterialCreate();
Material_s64 = NE_MaterialCreate();
Material_s256 = NE_MaterialCreate();
Scene.Material_s8 = NE_MaterialCreate();
Scene.Material_s16 = NE_MaterialCreate();
Scene.Material_s64 = NE_MaterialCreate();
Scene.Material_s256 = NE_MaterialCreate();
Palette_s8 = NE_PaletteCreate();
Palette_s16 = NE_PaletteCreate();
Palette_s64 = NE_PaletteCreate();
Palette_s256 = NE_PaletteCreate();
Scene.Palette_s8 = NE_PaletteCreate();
Scene.Palette_s16 = NE_PaletteCreate();
Scene.Palette_s64 = NE_PaletteCreate();
Scene.Palette_s256 = NE_PaletteCreate();
NE_MaterialTexLoad(Material_s8, NE_PAL16, 8, 8,
NE_MaterialTexLoad(Scene.Material_s8, NE_PAL16, 8, 8,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_WRAP_S | NE_TEXTURE_WRAP_T,
(void *)s8_tex_bin);
NE_MaterialTexLoad(Material_s16, NE_PAL16, 16, 16,
s8Bitmap);
NE_MaterialTexLoad(Scene.Material_s16, NE_PAL16, 16, 16,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_WRAP_S | NE_TEXTURE_WRAP_T,
(void *)s16_tex_bin);
NE_MaterialTexLoad(Material_s64, NE_PAL16, 64, 64,
s16Bitmap);
NE_MaterialTexLoad(Scene.Material_s64, NE_PAL16, 64, 64,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_WRAP_S | NE_TEXTURE_WRAP_T,
(void *)s64_tex_bin);
NE_MaterialTexLoad(Material_s256, NE_PAL16, 256, 256,
s64Bitmap);
NE_MaterialTexLoad(Scene.Material_s256, NE_PAL16, 256, 256,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_WRAP_S | NE_TEXTURE_WRAP_T,
(void *)s256_tex_bin);
s256Bitmap);
NE_PaletteLoad(Palette_s8, (u16 *)s8_pal_bin, 16, NE_PAL16);
NE_PaletteLoad(Palette_s16, (u16 *)s16_pal_bin, 16, NE_PAL16);
NE_PaletteLoad(Palette_s64, (u16 *)s64_pal_bin, 16, NE_PAL16);
NE_PaletteLoad(Palette_s256, (u16 *)s256_pal_bin, 16, NE_PAL16);
NE_PaletteLoad(Scene.Palette_s8, s8Pal, 16, NE_PAL16);
NE_PaletteLoad(Scene.Palette_s16, s16Pal, 16, NE_PAL16);
NE_PaletteLoad(Scene.Palette_s64, s64Pal, 16, NE_PAL16);
NE_PaletteLoad(Scene.Palette_s256, s256Pal, 16, NE_PAL16);
NE_MaterialSetPalette(Material_s8, Palette_s8);
NE_MaterialSetPalette(Material_s16, Palette_s16);
NE_MaterialSetPalette(Material_s64, Palette_s64);
NE_MaterialSetPalette(Material_s256, Palette_s256);
NE_MaterialSetPalette(Scene.Material_s8, Scene.Palette_s8);
NE_MaterialSetPalette(Scene.Material_s16, Scene.Palette_s16);
NE_MaterialSetPalette(Scene.Material_s64, Scene.Palette_s64);
NE_MaterialSetPalette(Scene.Material_s256, Scene.Palette_s256);
while (1)
{
NE_WaitForVBL(0);
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_ProcessDualArg(Draw3DScene, Draw3DScene2, &Scene, &Scene);
}
return 0;

View File

@ -1,220 +1,4 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1 +0,0 @@
include ../../Makefile.example.blocksds

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2024
//
// This file is part of Nitro Engine
@ -17,7 +17,7 @@ typedef struct {
quad_t Quad[NUM_QUADS];
uint32 kheld;
bool enable_alpha = false;
void UpdateQuads(void)
{
@ -55,7 +55,7 @@ void Draw3DScene(void)
if (!Quad[i].enabled)
continue;
if (kheld & KEY_A)
if (enable_alpha)
NE_PolyFormat(Quad[i].alpha, Quad[i].id, 0, NE_CULL_NONE, 0);
NE_2DDrawQuad(Quad[i].x1, Quad[i].y1, Quad[i].x2, Quad[i].y2, i,
@ -63,7 +63,7 @@ void Draw3DScene(void)
}
}
int main(void)
int main(int argc, char *argv[])
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
@ -83,7 +83,11 @@ int main(void)
NE_WaitForVBL(0);
scanKeys();
kheld = keysHeld();
uint16_t kheld = keysHeld();
if (kheld & KEY_A)
enable_alpha = true;
else
enable_alpha = false;
UpdateQuads();

View File

@ -1,220 +1,6 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
GFXDIRS := graphics
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,13 +0,0 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
TOOLS=$NITRO_ENGINE/tools
IMG2DS=$TOOLS/img2ds/img2ds.py
mkdir -p data
python3 $IMG2DS \
--input assets/icon.png \
--name icon \
--output data \
--format PAL16

Binary file not shown.

Before

Width:  |  Height:  |  Size: 796 B

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
# 256 color palette
-gx -gb -gB8 -gTFF00FF

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -0,0 +1,7 @@
This file is derived from:
Name: Ancient ruins pixel art
License: CC-BY 3.0
Author: CraftPix.net 2D Game Assets
https://opengameart.org/content/ancient-ruins-pixel-art

View File

@ -0,0 +1,2 @@
# 16 color palette
-gx -gb -gB4 -gTFF00FF

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -1,74 +1,116 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2024
//
// This file is part of Nitro Engine
#include <NEMain.h>
#include "icon_tex_bin.h"
#include "icon_pal_bin.h"
#include "assets.h"
#include "icon.h"
NE_Material *Material;
NE_Palette *Palette;
NE_Sprite *Sprite[4];
NE_Sprite *Sprite[6];
void Draw3DScene(void)
void Draw3DScene1(void)
{
NE_2DViewInit();
NE_SpriteDrawAll();
NE_ClearColorSet(NE_White, 31, 63);
NE_SpriteDraw(Sprite[3]);
NE_SpriteDraw(Sprite[4]);
NE_SpriteDraw(Sprite[5]);
}
int main(void)
void Draw3DScene2(void)
{
NE_2DViewInit();
NE_ClearColorSet(NE_Gray, 31, 63);
NE_SpriteDraw(Sprite[0]);
NE_SpriteDraw(Sprite[1]);
NE_SpriteDraw(Sprite[2]);
}
int main(int argc, char *argv[])
{
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_HBLANK, NE_HBLFunc);
NE_Init3D();
NE_SwapScreens();
NE_InitDual3D();
NE_InitConsole();
Material = NE_MaterialCreate();
Palette = NE_PaletteCreate();
NE_Material *MaterialIcon = NE_MaterialCreate();
NE_Palette *PaletteIcon = NE_PaletteCreate();
NE_MaterialTexLoad(Material, NE_PAL16, 128, 128, NE_TEXGEN_TEXCOORD,
(void *)icon_tex_bin);
NE_PaletteLoad(Palette, (void *)icon_pal_bin, 32, NE_PAL16);
NE_MaterialSetPalette(Material, Palette);
NE_MaterialTexLoad(MaterialIcon, NE_PAL16, 128, 128,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_COLOR0_TRANSPARENT,
iconBitmap);
NE_PaletteLoad(PaletteIcon, iconPal, iconPalLen / 2, NE_PAL16);
NE_MaterialSetPalette(MaterialIcon, PaletteIcon);
NE_Material *MaterialAssets = NE_MaterialCreate();
NE_Palette *PaletteAssets = NE_PaletteCreate();
NE_ClearColorSet(NE_Gray, 31, 63);
NE_MaterialTexLoad(MaterialAssets, NE_PAL256, 512, 256,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_COLOR0_TRANSPARENT,
assetsBitmap);
NE_PaletteLoad(PaletteAssets, assetsPal, assetsPalLen / 2, NE_PAL16);
NE_MaterialSetPalette(MaterialAssets, PaletteAssets);
Sprite[0] = NE_SpriteCreate();
Sprite[1] = NE_SpriteCreate();
Sprite[2] = NE_SpriteCreate();
Sprite[3] = NE_SpriteCreate();
Sprite[4] = NE_SpriteCreate();
Sprite[5] = NE_SpriteCreate();
NE_SpriteSetPos(Sprite[0], 0, 0);
NE_SpriteSetSize(Sprite[0], 128, 128);
// Sprite with the same size as the texture
NE_SpriteSetMaterial(Sprite[0], MaterialIcon);
NE_SpriteSetPos(Sprite[0], 10, 40);
NE_SpriteSetPriority(Sprite[0], 10);
NE_SpriteSetMaterial(Sprite[0], Material);
// Sprite with a different size than the texture (scaled down) and a
// different color
NE_SpriteSetMaterial(Sprite[1], MaterialIcon);
NE_SpriteSetPos(Sprite[1], 114, 32);
NE_SpriteSetSize(Sprite[1], 56, 56);
NE_SpriteSetPriority(Sprite[1], 5);
NE_SpriteSetParams(Sprite[1], 15, 1, NE_Green);
NE_SpriteSetMaterial(Sprite[1], Material);
NE_SpriteSetSize(Sprite[1], 56, 56);
// Sprite with a different size than the texture (scaled down), and with
// transparency.
NE_SpriteSetMaterial(Sprite[2], MaterialIcon);
NE_SpriteSetPos(Sprite[2], 100, 50);
NE_SpriteSetSize(Sprite[2], 56, 56);
NE_SpriteSetPriority(Sprite[2], 1);
NE_SpriteSetMaterial(Sprite[2], Material);
NE_SpriteSetParams(Sprite[2], 15, 2, NE_White);
NE_SpriteSetSize(Sprite[2], 56, 56);
NE_SpriteSetPos(Sprite[3], 256 - 64, 192 - 64);
NE_SpriteSetSize(Sprite[3], 64, 64);
NE_SpriteSetPriority(Sprite[3], 12);
NE_SpriteSetMaterial(Sprite[3], Material);
// The following sprites will only use a small part of the texture
NE_SpriteSetMaterial(Sprite[3], MaterialAssets);
NE_SpriteSetPos(Sprite[3], 50, 60);
NE_SpriteSetMaterialCanvas(Sprite[3], 384, 0, 484, 118);
NE_SpriteSetSize(Sprite[3], 484 - 384, 118 - 0);
NE_SpriteSetMaterial(Sprite[4], MaterialAssets);
NE_SpriteSetPos(Sprite[4], 0, 0);
NE_SpriteSetMaterialCanvas(Sprite[4], 73, 0, 152, 75);
NE_SpriteSetSize(Sprite[4], 152 - 73, 75 - 0);
NE_SpriteSetMaterial(Sprite[5], MaterialAssets);
NE_SpriteSetPos(Sprite[5], 170, 20);
NE_SpriteSetMaterialCanvas(Sprite[5], 0, 77, 72, 175);
NE_SpriteSetSize(Sprite[5], 72 - 0, 175 - 77);
int rot = 0;
int x = 100, y = 50;
printf("PAD: Move\n");
printf("START: Exit to loader\n");
while (1)
{
NE_WaitForVBL(0);
@ -88,9 +130,12 @@ int main(void)
if (keys & KEY_LEFT)
x--;
if (keys & KEY_START)
break;
NE_SpriteSetPos(Sprite[2], x, y);
NE_Process(Draw3DScene);
NE_ProcessDual(Draw3DScene1, Draw3DScene2);
}
return 0;

View File

@ -1,220 +0,0 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,19 +0,0 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
TOOLS=$NITRO_ENGINE/tools
IMG2DS=$TOOLS/img2ds/img2ds.py
mkdir -p data
python3 $IMG2DS \
--input assets/text.png \
--name text \
--output data \
--format A1RGB5
python3 $IMG2DS \
--input assets/text2.png \
--name text2 \
--output data \
--format A1RGB5

View File

@ -1,20 +1,28 @@
SUBDIRS:= $(shell ls)
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2023-2024
#-------------------------------------------------------------------------------
all: examples
#-------------------------------------------------------------------------------
@rm -fr build-all
.PHONY: all clean
MAKE := make
all:
@for i in `ls`; do \
if test -e $$i/Makefile ; then \
cd $$i; \
$(MAKE) --no-print-directory || exit 1 ; \
cd ..; \
fi; \
done;
@mkdir -p build-all
@find . -name "*.nds" -not -path build-all -exec cp -fv {} build-all \;
# TODO: The previous target tries to copy the files from build-all into
# themselves. Exclude them correctly.
examples:
@for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done;
#-------------------------------------------------------------------------------
clean:
#-------------------------------------------------------------------------------
@for i in `ls`; do \
if test -e $$i/Makefile ; then \
cd $$i; \
$(MAKE) clean --no-print-directory || exit 1 ; \
cd ..; \
fi; \
done;
@rm -fr build-all
@for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done;

View File

@ -1,25 +0,0 @@
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2023
.PHONY: all clean
MAKE := make
all:
@for i in `ls`; do \
if test -e $$i/Makefile.blocksds ; then \
$(MAKE) -C $$i -f Makefile.blocksds --no-print-directory || { exit 1;} \
fi; \
done;
@rm -fr build-all
@mkdir -p build-all
@find . -name "*.nds" -not -path build-all -exec cp -fv {} build-all \;
clean:
@for i in `ls`; do \
if test -e $$i/Makefile.blocksds ; then \
$(MAKE) -C $$i -f Makefile.blocksds clean --no-print-directory || { exit 1;} \
fi; \
done;
@rm -fr build-all

View File

@ -1,11 +1,11 @@
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2023
# SPDX-FileContributor: Antonio Niño Díaz, 2023-2024
BLOCKSDS ?= /opt/blocksds/core
BLOCKSDSEXT ?= /opt/blocksds/external
export BLOCKSDS ?= /opt/blocksds/core
export BLOCKSDSEXT ?= /opt/blocksds/external
WONDERFUL_TOOLCHAIN ?= /opt/wonderful
export WONDERFUL_TOOLCHAIN ?= /opt/wonderful
ARM_NONE_EABI_PATH ?= $(WONDERFUL_TOOLCHAIN)/toolchain/gcc-arm-none-eabi/bin/
# User config
@ -17,11 +17,6 @@ GAME_SUBTITLE := Nitro Engine example
GAME_AUTHOR := github.com/AntonioND/nitro-engine
GAME_ICON := $(BLOCKSDS)/sys/icon.bmp
# Source code paths
# -----------------
SOURCEDIRS ?= source
# DLDI and internal SD slot of DSi
# --------------------------------
@ -30,6 +25,22 @@ SDROOT := sdroot
# Name of the generated image it "DSi-1.sd" for no$gba in DSi mode
SDIMAGE := image.bin
# Source code paths
# -----------------
SOURCEDIRS ?= source
INCLUDEDIRS ?=
GFXDIRS ?=
BINDIRS ?=
AUDIODIRS ?=
# A single directory that is the root of NitroFS:
NITROFSDIR ?=
# Defines passed to all files
# ---------------------------
DEFINES ?=
# Libraries
# ---------
@ -40,18 +51,18 @@ LIBDIRS += $(BLOCKSDSEXT)/nitro-engine \
# Build artifacts
# ---------------
BUILDDIR := build
BUILDDIR := build/$(NAME)
ELF := build/$(NAME).elf
DUMP := build/$(NAME).dump
MAP := build/$(NAME).map
ROM := $(NAME).nds
# If NITROFSDIR is set, the output of mmutil will be placed in that directory
# If NITROFSDIR is set, the soundbank created by mmutil will be saved to NitroFS
SOUNDBANKINFODIR := $(BUILDDIR)/maxmod
ifeq ($(strip $(NITROFSDIR)),)
SOUNDBANKDIR := $(BUILDDIR)/maxmod
else
SOUNDBANKDIR := $(NITROFSDIR)
SOUNDBANKDIR := $(BUILDDIR)/maxmod_nitrofs
endif
# Tools
@ -60,6 +71,7 @@ endif
PREFIX := $(ARM_NONE_EABI_PATH)arm-none-eabi-
CC := $(PREFIX)gcc
CXX := $(PREFIX)g++
LD := $(PREFIX)gcc
OBJDUMP := $(PREFIX)objdump
MKDIR := mkdir
RM := rm -rf
@ -98,17 +110,15 @@ SOURCES_CPP := $(shell find -L $(SOURCEDIRS) -name "*.cpp")
# Compiler and linker flags
# -------------------------
DEFINES += -D__NDS__ -DARM9
ARCH := -mthumb -mcpu=arm946e-s+nofp
ARCH := -march=armv5te -mtune=arm946e-s
SPECS := $(BLOCKSDS)/sys/crts/ds_arm9.specs
WARNFLAGS := -Wall
ifeq ($(SOURCES_CPP),)
LD := $(CC)
LIBS += -lc
else
LD := $(CXX)
LIBS += -lstdc++ -lc
endif
@ -117,27 +127,21 @@ INCLUDEFLAGS := $(foreach path,$(INCLUDEDIRS),-I$(path)) \
LIBDIRSFLAGS := $(foreach path,$(LIBDIRS),-L$(path)/lib)
ASFLAGS += -x assembler-with-cpp $(DEFINES) $(ARCH) \
-mthumb -mthumb-interwork $(INCLUDEFLAGS) \
-ffunction-sections -fdata-sections
ASFLAGS += -x assembler-with-cpp $(INCLUDEFLAGS) $(DEFINES) \
$(ARCH) -ffunction-sections -fdata-sections \
-specs=$(SPECS)
CFLAGS += -std=gnu11 $(WARNFLAGS) $(DEFINES) $(ARCH) \
-mthumb -mthumb-interwork $(INCLUDEFLAGS) -O2 \
-ffunction-sections -fdata-sections \
-fomit-frame-pointer
CFLAGS += -std=gnu17 $(WARNFLAGS) $(INCLUDEFLAGS) $(DEFINES) \
$(ARCH) -O2 -ffunction-sections -fdata-sections \
-specs=$(SPECS)
CXXFLAGS += -std=gnu++14 $(WARNFLAGS) $(DEFINES) $(ARCH) \
-mthumb -mthumb-interwork $(INCLUDEFLAGS) -O2 \
-ffunction-sections -fdata-sections \
CXXFLAGS += -std=gnu++17 $(WARNFLAGS) $(INCLUDEFLAGS) $(DEFINES) \
$(ARCH) -O2 -ffunction-sections -fdata-sections \
-fno-exceptions -fno-rtti \
-fomit-frame-pointer
-specs=$(SPECS)
LDFLAGS := -mthumb -mthumb-interwork $(LIBDIRSFLAGS) \
-Wl,-Map,$(MAP) -Wl,--gc-sections -nostdlib \
-T$(BLOCKSDS)/sys/crts/ds_arm9.mem \
-T$(BLOCKSDS)/sys/crts/ds_arm9.ld \
-Wl,--no-warn-rwx-segments \
-Wl,--start-group $(LIBS) -lgcc -Wl,--end-group
LDFLAGS := $(ARCH) $(LIBDIRSFLAGS) -Wl,-Map,$(MAP) $(DEFINES) \
-Wl,--start-group $(LIBS) -Wl,--end-group -specs=$(SPECS)
# Intermediate build files
# ------------------------
@ -174,6 +178,10 @@ ifneq ($(strip $(NITROFSDIR)),)
# Additional arguments for ndstool
NDSTOOL_ARGS := -d $(NITROFSDIR)
ifneq ($(SOURCES_AUDIO),)
NDSTOOL_ARGS += -d $(SOUNDBANKDIR)
endif
# Make the NDS ROM depend on the filesystem only if it is needed
$(ROM): $(NITROFSDIR)
endif
@ -194,7 +202,7 @@ $(ROM): $(ELF)
$(ELF): $(OBJS)
@echo " LD $@"
$(V)$(LD) -o $@ $(OBJS) $(BLOCKSDS)/sys/crts/ds_arm9_crt0.o $(LDFLAGS)
$(V)$(LD) -o $@ $(OBJS) $(LDFLAGS)
$(DUMP): $(ELF)
@echo " OBJDUMP $@"
@ -204,8 +212,7 @@ dump: $(DUMP)
clean:
@echo " CLEAN"
$(V)$(RM) $(ROM) $(DUMP) $(BUILDDIR) $(SDIMAGE) \
$(SOUNDBANKDIR)/soundbank.bin
$(V)$(RM) $(ROM) $(DUMP) build $(SDIMAGE)
sdimage:
@echo " MKFATIMG $(SDIMAGE) $(SDROOT)"
@ -255,12 +262,14 @@ $(BUILDDIR)/%.png.o $(BUILDDIR)/%.h : %.png %.grit
@$(MKDIR) -p $(@D)
$(V)$(BLOCKSDS)/tools/grit/grit $< -ftc -W1 -o$(BUILDDIR)/$*
$(V)$(CC) $(CFLAGS) -MMD -MP -c -o $(BUILDDIR)/$*.png.o $(BUILDDIR)/$*.c
$(V)touch $(BUILDDIR)/$*.png.o $(BUILDDIR)/$*.h
ifneq ($(SOURCES_AUDIO),)
$(SOUNDBANKINFODIR)/soundbank.h: $(SOURCES_AUDIO)
@echo " MMUTIL $^"
@$(MKDIR) -p $(@D)
@$(MKDIR) -p $(SOUNDBANKDIR)
@$(MKDIR) -p $(SOUNDBANKINFODIR)
@$(BLOCKSDS)/tools/mmutil/mmutil $^ -d \
-o$(SOUNDBANKDIR)/soundbank.bin -h$(SOUNDBANKINFODIR)/soundbank.h

View File

@ -1,5 +1,25 @@
SUBDIRS:= `ls`
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2023-2024
.PHONY: all clean
MAKE := make
all:
@for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done;
@for i in `ls`; do \
if test -e $$i/Makefile ; then \
cd $$i; \
$(MAKE) --no-print-directory || exit 1 ; \
cd ..; \
fi; \
done;
clean:
@for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done;
@for i in `ls`; do \
if test -e $$i/Makefile ; then \
cd $$i; \
$(MAKE) clean --no-print-directory || exit 1 ; \
cd ..; \
fi; \
done;

View File

@ -1,25 +0,0 @@
# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Antonio Niño Díaz, 2023
.PHONY: all clean
MAKE := make
all:
@for i in `ls`; do \
if test -e $$i/Makefile.blocksds ; then \
cd $$i; \
$(MAKE) -f Makefile.blocksds --no-print-directory || { exit 1;}; \
cd ..; \
fi; \
done;
clean:
@for i in `ls`; do \
if test -e $$i/Makefile.blocksds ; then \
cd $$i; \
$(MAKE) -f Makefile.blocksds clean --no-print-directory || { exit 1;}; \
cd ..; \
fi; \
done;

View File

@ -1,220 +1,7 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
BINDIRS := data
GFXDIRS := graphics
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,21 +1,14 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
NITRO_ENGINE=../../..
ASSETS=$NITRO_ENGINE/examples/assets
TOOLS=$NITRO_ENGINE/tools
OBJ2DL=$TOOLS/obj2dl/obj2dl.py
IMG2DS=$TOOLS/img2ds/img2ds.py
rm -rf data
mkdir -p data
python3 $OBJ2DL \
--input $ASSETS/sphere.obj \
--output data/sphere.bin \
--texture 256 256
python3 $IMG2DS \
--input $ASSETS/teapot.png \
--name texture \
--output data \
--format A1RGB5

Binary file not shown.

View File

@ -0,0 +1,2 @@
# 16-bit palette, no transparency
-gx -gb -gB16 -gT!

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View File

@ -1,34 +1,39 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2024
//
// This file is part of Nitro Engine
#include <NEMain.h>
#include "texture_tex_bin.h"
#include "texture.h"
#include "sphere_bin.h"
NE_Camera *Camera;
NE_Model *Model, *Model2, *Model3;
NE_Material *Material;
typedef struct {
NE_Camera *Camera;
NE_Model *Model, *Model2, *Model3;
} SceneData;
void Draw3DScene(void)
void Draw3DScene(void *arg)
{
SceneData *Scene = arg;
// Set camera
NE_CameraUse(Camera);
NE_CameraUse(Scene->Camera);
// This has to be used to use fog
NE_PolyFormat(31, 0, NE_LIGHT_ALL, NE_CULL_BACK, NE_FOG_ENABLE);
// Draw models
NE_ModelDraw(Model);
NE_ModelDraw(Model2);
NE_ModelDraw(Model3);
NE_ModelDraw(Scene->Model);
NE_ModelDraw(Scene->Model2);
NE_ModelDraw(Scene->Model3);
}
int main(void)
int main(int argc, char *argv[])
{
SceneData Scene = { 0 };
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
irqSet(IRQ_VBLANK, NE_HBLFunc);
@ -41,39 +46,39 @@ int main(void)
consoleDemoInit();
// Allocate objects
Model = NE_ModelCreate(NE_Static);
Model2 = NE_ModelCreate(NE_Static);
Model3 = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
Scene.Model = NE_ModelCreate(NE_Static);
Scene.Model2 = NE_ModelCreate(NE_Static);
Scene.Model3 = NE_ModelCreate(NE_Static);
Scene.Camera = NE_CameraCreate();
NE_Material *Material = NE_MaterialCreate();
// Set camera coordinates
NE_CameraSet(Camera,
NE_CameraSet(Scene.Camera,
-1, 2, -1,
1, 1, 1,
0, 1, 0);
// Load models
NE_ModelLoadStaticMesh(Model, (u32 *)sphere_bin);
NE_ModelLoadStaticMesh(Model2, (u32 *)sphere_bin);
NE_ModelLoadStaticMesh(Model3, (u32 *)sphere_bin);
NE_ModelLoadStaticMesh(Scene.Model, sphere_bin);
NE_ModelLoadStaticMesh(Scene.Model2, sphere_bin);
NE_ModelLoadStaticMesh(Scene.Model3, sphere_bin);
// Load texture
NE_MaterialTexLoad(Material, NE_RGB5, 256, 256, NE_TEXGEN_TEXCOORD,
(u8 *)texture_tex_bin);
NE_MaterialTexLoad(Material, NE_A1RGB5, 256, 256, NE_TEXGEN_TEXCOORD,
textureBitmap);
// Assign the same material to every model object.
NE_ModelSetMaterial(Model, Material);
NE_ModelSetMaterial(Model2, Material);
NE_ModelSetMaterial(Model3, Material);
NE_ModelSetMaterial(Scene.Model, Material);
NE_ModelSetMaterial(Scene.Model2, Material);
NE_ModelSetMaterial(Scene.Model3, Material);
// Set light and vector of light 0
NE_LightSet(0, NE_White, 0, -1, -1);
// Set position of every object
NE_ModelSetCoord(Model, 1, 0, 1);
NE_ModelSetCoord(Model2, 3, 1, 3);
NE_ModelSetCoord(Model3, 7, 2, 7);
NE_ModelSetCoord(Scene.Model, 1, 0, 1);
NE_ModelSetCoord(Scene.Model2, 3, 1, 3);
NE_ModelSetCoord(Scene.Model3, 7, 2, 7);
// Set initial fog color to black
u32 color = NE_Black;
@ -89,7 +94,7 @@ int main(void)
// Refresh keys
scanKeys();
uint32 keys = keysDown();
uint32_t keys = keysDown();
// Modify parameters
if (keys & KEY_UP)
@ -125,7 +130,7 @@ int main(void)
shift, mass, depth);
// Draw scene
NE_Process(Draw3DScene);
NE_ProcessArg(Draw3DScene, &Scene);
}
return 0;

View File

@ -1,220 +1,6 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
BINDIRS := data
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,6 +1,6 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
NITRO_ENGINE=../../..
ASSETS=$NITRO_ENGINE/examples/assets
TOOLS=$NITRO_ENGINE/tools
OBJ2DL=$TOOLS/obj2dl/obj2dl.py

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2024
//
// This file is part of Nitro Engine
@ -8,29 +8,37 @@
#include "teapot_bin.h"
NE_Camera *Camera;
NE_Model *Model;
typedef struct {
NE_Camera *Camera;
NE_Model *Model;
} SceneData;
void Draw3DScene(void)
void Draw3DScene(void *arg)
{
SceneData *Scene = arg;
// Set rear plane color
NE_ClearColorSet(NE_Red, 31, 63);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
NE_CameraUse(Scene->Camera);
NE_ModelDraw(Scene->Model);
}
void Draw3DScene2(void)
void Draw3DScene2(void *arg)
{
SceneData *Scene = arg;
// Set rear plane color
NE_ClearColorSet(NE_Green, 31, 63);
NE_CameraUse(Camera);
NE_ModelDraw(Model);
NE_CameraUse(Scene->Camera);
NE_ModelDraw(Scene->Model);
}
int main(void)
int main(int argc, char *argv[])
{
SceneData Scene = { 0 };
// This is needed for special screen effects
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
@ -41,24 +49,21 @@ int main(void)
NE_InitConsole();
// Allocate objects...
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Scene.Model = NE_ModelCreate(NE_Static);
Scene.Camera = NE_CameraCreate();
// Setup camera
NE_CameraSet(Camera,
NE_CameraSet(Scene.Camera,
0, 0, -3,
0, 0, 0,
0, 1, 0);
// Load model
NE_ModelLoadStaticMesh(Model, (u32 *)teapot_bin);
NE_ModelLoadStaticMesh(Scene.Model, teapot_bin);
// Set light color and direction
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// Enable shading
NE_ShadingEnable(true);
// Other test configurations
//NE_SpecialEffectNoiseConfig(31);
//NE_SpecialEffectSineConfig(3, 8);
@ -69,8 +74,8 @@ int main(void)
// Refresh keys
scanKeys();
uint32 keys = keysHeld();
uint32 kdown = keysDown();
uint32_t keys = keysHeld();
uint32_t kdown = keysDown();
printf("\x1b[0;0H"
"Pad: Rotate.\nA: Sine effect.\nB: Noise effect.\n"
@ -78,13 +83,13 @@ int main(void)
// Rotate model
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
NE_ModelRotate(Scene.Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
NE_ModelRotate(Scene.Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
NE_ModelRotate(Scene.Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
NE_ModelRotate(Scene.Model, 0, -2, 0);
// Activate effects
if (kdown & KEY_B)
@ -102,7 +107,7 @@ int main(void)
NE_SpecialEffectPause(false);
// Draw 3D scenes
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_ProcessDualArg(Draw3DScene, Draw3DScene2, &Scene, &Scene);
}
return 0;

View File

@ -1,220 +1,6 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
BINDIRS := data
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,6 +1,6 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
NITRO_ENGINE=../../..
ASSETS=$NITRO_ENGINE/examples/assets
TOOLS=$NITRO_ENGINE/tools
OBJ2DL=$TOOLS/obj2dl/obj2dl.py

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022-2023
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2024
//
// This file is part of Nitro Engine
@ -11,27 +11,35 @@
#include "teapot_bin.h"
#include "sphere_bin.h"
NE_Camera *Camera;
NE_Model *Teapot, *Sphere;
typedef struct {
NE_Camera *Camera;
NE_Model *Teapot, *Sphere;
} SceneData;
void Draw3DScene(void)
void Draw3DScene(void *arg)
{
SceneData *Scene = arg;
NE_ClearColorSet(NE_Red, 31, 63);
NE_CameraUse(Camera);
NE_ModelDraw(Teapot);
NE_CameraUse(Scene->Camera);
NE_ModelDraw(Scene->Teapot);
}
void Draw3DScene2(void)
void Draw3DScene2(void *arg)
{
SceneData *Scene = arg;
NE_ClearColorSet(NE_Green, 31, 63);
NE_CameraUse(Camera);
NE_ModelDraw(Sphere);
NE_CameraUse(Scene->Camera);
NE_ModelDraw(Scene->Sphere);
}
int main(void)
int main(int argc, char *argv[])
{
SceneData Scene = { 0 };
// This is needed for special screen effects
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
@ -42,26 +50,23 @@ int main(void)
NE_InitConsole();
// Allocate objects...
Teapot = NE_ModelCreate(NE_Static);
Sphere = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Scene.Teapot = NE_ModelCreate(NE_Static);
Scene.Sphere = NE_ModelCreate(NE_Static);
Scene.Camera = NE_CameraCreate();
// Setup camera
NE_CameraSet(Camera,
NE_CameraSet(Scene.Camera,
0, 0, -2,
0, 0, 0,
0, 1, 0);
// Load models
NE_ModelLoadStaticMesh(Teapot, (u32 *)teapot_bin);
NE_ModelLoadStaticMesh(Sphere, (u32 *)sphere_bin);
NE_ModelLoadStaticMesh(Scene.Teapot, teapot_bin);
NE_ModelLoadStaticMesh(Scene.Sphere, sphere_bin);
// Set light color and direction
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// Enable shading
NE_ShadingEnable(true);
// Other test configurations
//NE_SpecialEffectNoiseConfig(31);
//NE_SpecialEffectSineConfig(3, 8);
@ -71,12 +76,12 @@ int main(void)
NE_WaitForVBL(0);
// Draw 3D scenes
NE_ProcessDual(Draw3DScene, Draw3DScene2);
NE_ProcessDualArg(Draw3DScene, Draw3DScene2, &Scene, &Scene);
// Refresh keys
scanKeys();
uint32 keys = keysHeld();
uint32 kdown = keysDown();
uint32_t keys = keysHeld();
uint32_t kdown = keysDown();
printf("\x1b[0;0H"
"START: Lock CPU until released\n"
@ -93,23 +98,23 @@ int main(void)
// Rotate model
if (keys & KEY_UP)
{
NE_ModelRotate(Sphere, 0, 0, 2);
NE_ModelRotate(Teapot, 0, 0, 2);
NE_ModelRotate(Scene.Sphere, 0, 0, 2);
NE_ModelRotate(Scene.Teapot, 0, 0, 2);
}
if (keys & KEY_DOWN)
{
NE_ModelRotate(Sphere, 0, 0, -2);
NE_ModelRotate(Teapot, 0, 0, -2);
NE_ModelRotate(Scene.Sphere, 0, 0, -2);
NE_ModelRotate(Scene.Teapot, 0, 0, -2);
}
if (keys & KEY_RIGHT)
{
NE_ModelRotate(Sphere, 0, 2, 0);
NE_ModelRotate(Teapot, 0, 2, 0);
NE_ModelRotate(Scene.Sphere, 0, 2, 0);
NE_ModelRotate(Scene.Teapot, 0, 2, 0);
}
if (keys & KEY_LEFT)
{
NE_ModelRotate(Sphere, 0, -2, 0);
NE_ModelRotate(Teapot, 0, -2, 0);
NE_ModelRotate(Scene.Sphere, 0, -2, 0);
NE_ModelRotate(Scene.Teapot, 0, -2, 0);
}
// Activate effects

View File

@ -1,220 +1,7 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
BINDIRS := data
GFXDIRS := graphics
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,11 +1,11 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
NITRO_ENGINE=../../..
ASSETS=$NITRO_ENGINE/examples/assets
TOOLS=$NITRO_ENGINE/tools
OBJ2DL=$TOOLS/obj2dl/obj2dl.py
IMG2DS=$TOOLS/img2ds/img2ds.py
rm -rf data
mkdir -p data
python3 $OBJ2DL \
@ -13,9 +13,3 @@ python3 $OBJ2DL \
--output data/teapot.bin \
--texture 256 256 \
--scale 0.1
python3 $IMG2DS \
--input $ASSETS/teapot.png \
--name teapot \
--output data \
--format A1RGB5

View File

@ -0,0 +1,2 @@
# 16-bit palette, no transparency
-gx -gb -gB16 -gT!

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View File

@ -1,34 +1,40 @@
// SPDX-License-Identifier: CC0-1.0
//
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022
// SPDX-FileContributor: Antonio Niño Díaz, 2008-2024
//
// This file is part of Nitro Engine
#include <NEMain.h>
#include "teapot_bin.h"
#include "teapot_tex_bin.h"
#include "teapot.h"
NE_Camera *Camera;
NE_Model *Model;
NE_Material *Material;
typedef struct {
NE_Camera *Camera;
NE_Model *Model;
int shading, alpha, id;
int shading, alpha, id;
} SceneData;
void Draw3DScene(void)
void Draw3DScene(void *arg)
{
SceneData *Scene = arg;
// Set camera
NE_CameraUse(Camera);
NE_CameraUse(Scene->Camera);
// Set polygon format
NE_PolyFormat(alpha, id, NE_LIGHT_0, NE_CULL_BACK, shading);
NE_PolyFormat(Scene->alpha, Scene->id, NE_LIGHT_0, NE_CULL_BACK,
Scene->shading);
// Draw model
NE_ModelDraw(Model);
NE_ModelDraw(Scene->Model);
}
int main(void)
int main(int argc, char *argv[])
{
SceneData Scene = { 0 };
// This is needed for special screen effects
irqEnable(IRQ_HBLANK);
irqSet(IRQ_VBLANK, NE_VBLFunc);
@ -43,28 +49,28 @@ int main(void)
consoleDemoInit();
// Allocate the objects we will use
Model = NE_ModelCreate(NE_Static);
Camera = NE_CameraCreate();
Material = NE_MaterialCreate();
Scene.Model = NE_ModelCreate(NE_Static);
Scene.Camera = NE_CameraCreate();
NE_Material *Material = NE_MaterialCreate();
// Set camera coordinates
NE_CameraSet(Camera,
NE_CameraSet(Scene.Camera,
0, 0, -3,
0, 0, 0,
0, 1, 0);
// Load mesh from RAM and assign it to a model
NE_ModelLoadStaticMesh(Model, (u32 *)teapot_bin);
// Load teapot from RAM and assign it to a material
NE_MaterialTexLoad(Material, NE_RGB5, 256, 256,
NE_ModelLoadStaticMesh(Scene.Model, teapot_bin);
// Load teapot texture from RAM and assign it to a material
NE_MaterialTexLoad(Material, NE_A1RGB5, 256, 256,
NE_TEXGEN_TEXCOORD | NE_TEXTURE_WRAP_S | NE_TEXTURE_WRAP_T,
(u8 *)teapot_tex_bin);
teapotBitmap);
// Assign material to the model
NE_ModelSetMaterial(Model, Material);
NE_ModelSetMaterial(Scene.Model, Material);
// Set some propierties to the material
NE_MaterialSetPropierties(Material,
// Set some properties to the material
NE_MaterialSetProperties(Material,
RGB15(24, 24, 24), // Diffuse
RGB15(8, 8, 8), // Ambient
RGB15(0, 0, 0), // Specular
@ -75,7 +81,7 @@ int main(void)
NE_LightSet(0, NE_White, -0.5, -0.5, -0.5);
// This enables shading (you can choose normal or toon).
NE_ShadingEnable(true);
NE_SetupToonShadingTables(true);
// This enables outlining in all polygons, so be careful
NE_OutliningEnable(true);
@ -89,7 +95,7 @@ int main(void)
// Refresh keys
scanKeys();
uint32 keys = keysHeld();
uint32_t keys = keysHeld();
printf("\x1b[0;0H"
"Pad: Rotate.\nA: Toon shading.\n"
@ -98,35 +104,35 @@ int main(void)
// Rotate model using the pad
if (keys & KEY_UP)
NE_ModelRotate(Model, 0, 0, 2);
NE_ModelRotate(Scene.Model, 0, 0, 2);
if (keys & KEY_DOWN)
NE_ModelRotate(Model, 0, 0, -2);
NE_ModelRotate(Scene.Model, 0, 0, -2);
if (keys & KEY_RIGHT)
NE_ModelRotate(Model, 0, 2, 0);
NE_ModelRotate(Scene.Model, 0, 2, 0);
if (keys & KEY_LEFT)
NE_ModelRotate(Model, 0, -2, 0);
NE_ModelRotate(Scene.Model, 0, -2, 0);
// Change shading type
if (keys & KEY_A)
shading = NE_TOON_HIGHLIGHT_SHADING;
Scene.shading = NE_TOON_HIGHLIGHT_SHADING;
else
shading = NE_MODULATION;
Scene.shading = NE_MODULATION;
if (keys & KEY_B)
alpha = 15; // Transparent
Scene.alpha = 15; // Transparent
else if (keys & KEY_Y)
alpha = 0; // Wireframe
Scene.alpha = 0; // Wireframe
else
alpha = 31; // Opaque
Scene.alpha = 31; // Opaque
// Change polygon ID to change outlining color
if (keys & KEY_X)
id = 8;
Scene.id = 8;
else
id = 0;
Scene.id = 0;
// Draw scene
NE_Process(Draw3DScene);
NE_ProcessArg(Draw3DScene, &Scene);
}
return 0;

View File

@ -1,220 +1,7 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
# This is a minimal makefile only used for the examples. If you want a makefile
# for your project, take one from the templates inside examples/templates.
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
BINDIRS := data
GFXDIRS := graphics
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
DATA := data
GRAPHICS :=
AUDIO :=
ICON :=
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
# These set the information text in the nds file
GAME_TITLE := $(shell basename $(CURDIR))
GAME_SUBTITLE1 := Nitro Engine example
GAME_SUBTITLE2 := github.com/AntonioND/nitro-engine
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lNE -lfat -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS) $(DEVKITPRO)/nitro-engine
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(PNGFILES:.png=.o) $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(PNGFILES:.png=.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir))\
$(foreach dir,$(LIBDIRS),-I$(dir)/include)\
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
else
ifeq ($(suffix $(ICON)), .grf)
export GAME_ICON := $(CURDIR)/$(ICON)
else
export GAME_ICON := $(CURDIR)/$(BUILD)/$(notdir $(basename $(ICON))).grf
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# source files depend on generated headers
$(OFILES_SOURCES) : $(HFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
@echo convert $(notdir $<)
@grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
include ../../Makefile.example

View File

@ -1,3 +0,0 @@
BINDIRS := data
include ../../Makefile.example.blocksds

View File

@ -1,11 +1,11 @@
#!/bin/sh
NITRO_ENGINE=$DEVKITPRO/nitro-engine
NITRO_ENGINE=../../..
ASSETS=$NITRO_ENGINE/examples/assets
TOOLS=$NITRO_ENGINE/tools
OBJ2DL=$TOOLS/obj2dl/obj2dl.py
IMG2DS=$TOOLS/img2ds/img2ds.py
rm -rf data
mkdir -p data
python3 $OBJ2DL \
@ -13,9 +13,3 @@ python3 $OBJ2DL \
--output data/teapot.bin \
--texture 256 256 \
--scale 0.1
python3 $IMG2DS \
--input $ASSETS/teapot.png \
--name teapot \
--output data \
--format A1RGB5

Some files were not shown because too many files have changed in this diff Show More