IKEMEN Direct X #1279
Replies: 5 comments 2 replies
-
IKEMEN Direct X build 1: |
Beta Was this translation helpful? Give feedback.
-
This is a tentative process, this will change eventually as we learn more about the Kinc library and hopefully receive feedback from @samhocevar about our process. This is for development/testing purposes only at the moment. Before following these steps, you'll need to have completed all of the steps found here before you can compile any Windows IKEMEN Go build from source. Take note of the "includes" directory of your mingw installation. If installed via chocolatey for example, it could be found here:
Initializing IKEMEN and Kinc Repos
Add Kinc to your system includes:
Build the Ikemen-GO Kinc Project in Visual Studio
Notes
|
Beta Was this translation helpful? Give feedback.
-
First step to make this easier - use Kinc/make --help to see the options. Using --dynlib and --compile will directly create a dll without you even having to open Visual Studio. You can use --to to build in something else but "build". Things like creating directories and manually copying files can be avoided by simply doing it in the kfile - the complete node.js API is available for tasks like that. |
Beta Was this translation helpful? Give feedback.
-
Screenshots: Screenshot support is not implemented yet for the Direct X build. When the func (r *Renderer) ReadPixels(data []uint8, width, height int) {
r.EndFrame()
gl.ReadPixels(data, 0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE)
r.BeginFrame(false)
} for the kinc backend this is just a stub func (r *Renderer) ReadPixels(data []uint8, width, height int) {
sys.errLog.Printf("STUB: ReadPixels()")
} ReadPixels is a native OpenGL function, implimenting similar functionality in Kinc could take some time. Luckily, Kinc seems to support a ReadPixels esque function that it actually uses to generate a screenshot in this sample: static void update(void *data) {
kinc_g4_begin(0);
kinc_g4_render_target_t *render_targets = {&render_target};
kinc_g4_set_render_targets(&render_targets, 1);
kinc_g4_clear(KINC_G4_CLEAR_COLOR, 0xFF000000, 0.0f, 0);
kinc_g4_set_pipeline(&pipeline);
kinc_g4_set_vertex_buffer(&vertices);
kinc_g4_set_index_buffer(&indices);
kinc_g4_draw_indexed_vertices();
kinc_g4_end(0);
kinc_g4_swap_buffers();
uint8_t *pixels = (uint8_t *)malloc(2048 * 2048 * 4);
kinc_g4_render_target_get_pixels(&render_target, pixels);
if (kinc_g4_render_targets_inverted_y()) {
uint8_t *inverted_pixels = (uint8_t *)malloc(2048 * 2048 * 4);
for (int y = 0; y < 2048; ++y) {
for (int x = 0; x < 2048; ++x) {
for (int c = 0; c < 4; ++c) {
inverted_pixels[y * 2048 * 4 + x * 4 + c] = pixels[(2047 - y) * 2048 * 4 + x * 4 + c];
}
}
}
pixels = inverted_pixels;
}
stbi_write_png("test.png", 2048, 2048, 4, pixels, 2048 * 4);
exit(0);
} This involves some setup though, like creating and initializing a render target and rendering into that every frame. So I'm not sure how feasible this method is with our current backend, but it's worth a shot. Will try it today and report my findings. Edit: type Renderer struct {
....
render_target *C.kinc_g4_render_target_t
}
func (r *Renderer) Init() {
....
r.render_target = (*C.kinc_g4_render_target_t)(C.malloc(C.sizeof_kinc_g4_render_target_t))
C.kinc_g4_render_target_init(r.render_target, C.int(sys.window.width), C.int(sys.window.height), C.KINC_G4_RENDER_TARGET_FORMAT_32BIT, 0, 0)
}
func (r *Renderer) BeginFrame(clear bool) {
C.kinc_g4_begin(0)
render_targets := (*C.kinc_g4_render_target_t)(unsafe.Pointer(r.render_target))
C.kinc_g4_set_render_targets(&render_targets, 1)
if clear {
C.kinc_g4_clear(C.KINC_G4_CLEAR_COLOR, 0xff000000, 0.0, 0)
}
}
func (r *Renderer) ReadPixels(data []uint8, width, height int) {
// Use render target's get pixels function to read pixels
C.kinc_g4_render_target_get_pixels(r.render_target, (*C.uint8_t)(unsafe.Pointer(&data[0])))
} |
Beta Was this translation helpful? Give feedback.
-
Edit 3: After thinking it through, dynamic resizing isn't really necessary for a fighting game anyway. Will probably just lock the resize feature on the Direct X build. With regards to the UI elements getting misaligned on resizing. Kinc has a way to set a resize callback Edit: Tried this, turns out it's not that simple. The problem seems to be that that there are objects who have fields that are initialized by One way to handle it is to create a Another way to handle it is an "Immediate Mode" approach, recalculating all values that use the window related fields at the time of their use. This seems expensive but performance costs are said to be negligible. I'm not knowledgeable enough about our rendering yet to know whether such calculations could be too expensive or what objects would need to have the Immediate Mode applied. Perhaps @K4thos could provide some insight on this. Either way, it's not exactly as big as a priority compared to fixing features that were lost. I'd say the next steps would be to take inventory of every object that isinitialized by these fields:
Edit 2: I'm not so sure that my theory is correct anymore because a lot of IKEMEN rendering is already 'immediate mode' in a sense with regards to the window. |
Beta Was this translation helpful? Give feedback.
-
IKEMEN Go Direct X Test Build Here: IKEMEN-Go-DirectX-Test.zip
Disclaimer: This is not an official release
This is a test, the purpose being to work out the kinks in the Kinc library (pun intended) for IKEMEN. If you have any issues, please post them as a response to this thread.
Known Issues
The build instructions below are outdated, will update them soon.
@samhocevar was kind enough to implement multiple rendering and input backends via the Kinc library. This is an attempt to learn how to make Direct X IKEMEN builds.
Here are the instructions on how to build a Direct X version via the Kinc library for IKEMEN Go from sources:
Clone the IKEMEN Go repository if you don't already have it
If you do not currently have Visual Studio (the native application, not VSCode) installed, downland Install Visual Studio Community Edition 2022
Clone the Kinc library somewhere on your computer
Run /path/to/your/Kinc/get_dlc.bat via PowerShell or the command line
Copy the Kinc folder into your IKEMEN directory
Go to the IKEMEN-Go/Kinc/Sources/kinc/system.h file and add the KINC_FUNC definition to export the
kinc_internal_frame
function:KINC_FUNC bool kinc_internal_frame(void);
Replace your render_kinc.go, input_kinc.go, and system_kinc.go with these:
IKEMEN-Go-updated-kinc-files.zip
Rename the build folder to something else (Kinc makes its own "build" folder and though I haven't experienced a conflict I want to prevent them from happening)
Make a Shaders folder and copy the shaders from src/shaders into that folder
Make a Deployment folder (we will find compiled shaders here later)
Make a kfile.js file with the following code and place it in the IKEMEN Go directory
/path/to/Kinc/make.bat windows -g direct3d11
in your IKEMEN directory via PowerShell or the command lineKINC_NO_MAIN ;KINC_DYNAMIC_COMPILE;
Enjoy your Direct X IKEMEN!
Beta Was this translation helpful? Give feedback.
All reactions