Nạp và vẽ texture từ file ảnh. Tiếp...
Classes | |
| struct | njin::atlas_desc |
| Cách tạo một atlas, xem atlas_create(). Tiếp... | |
| struct | njin::texture_draw_desc |
| Tham số đầy đủ cho texture_draw_ex(). Tiếp... | |
Enumerations | |
| enum | njin::texture_filter { njin::filter_nearest , njin::filter_linear , njin::filter_mipmap } |
| Cách lấy mẫu khi texture bị co giãn. Tiếp... | |
Các hàm | |
| atlas_handle | njin::atlas_create (context &ctx, const atlas_desc &desc={}) |
| Tạo một atlas: nơi ghép nhiều ảnh nhỏ vào một texture lớn. | |
| texture_handle | njin::atlas_load (context &ctx, atlas_handle atlas, const char *path) |
| Nạp một file ảnh và xếp vào atlas. | |
| void | njin::atlas_destroy (context &ctx, atlas_handle atlas) |
| Hủy atlas: giải phóng các trang. | |
| void | njin::texture_set_filter (context &ctx, texture_handle handle, texture_filter filter) |
| Đổi cách lấy mẫu của texture. | |
| void | njin::render_texture_set_filter (context &ctx, render_texture_handle handle, texture_filter filter) |
| Đổi cách lấy mẫu của render texture. | |
| void | njin::texture_draw_ex (const context &ctx, texture_handle handle, const texture_draw_desc &desc) |
| Vẽ texture với vùng nguồn, tỉ lệ, điểm neo, góc xoay và lật. | |
| void | njin::texture_set_shader (context &ctx, texture_handle handle, shader_handle shader) |
| Gắn một shader "vật liệu" cố định vào texture: không cần bọc shader_begin()/shader_end() quanh mỗi lần vẽ nữa. | |
| texture_handle | njin::texture_load (context &ctx, const char *path) |
| Nạp một texture từ file ảnh. | |
| void | njin::texture_unload (context &ctx, texture_handle handle) |
| Giải phóng texture. | |
| vec2 | njin::texture_size (const context &ctx, texture_handle handle) |
| Kích thước texture (pixel). | |
| void | njin::texture_draw (const context &ctx, texture_handle handle, vec2 pos, rgba tint) |
| Vẽ texture với góc trên trái tại pos. | |
Nạp và vẽ texture từ file ảnh.
| enum njin::texture_filter |
Cách lấy mẫu khi texture bị co giãn.
| Enumerator | |
|---|---|
| filter_nearest | Giữ nguyên từng pixel, sắc cạnh. Dùng cho pixel art. |
| filter_linear | Làm mượt. Mặc định. |
| filter_mipmap | Làm mượt ở mọi khoảng cách: tạo mipmap và lọc tam tuyến. Cho ảnh lặp lại trên mặt 3D lớn nhìn từ xa (tường, sàn), nơi filter_linear lấp lánh. Ảnh trong atlas và render texture lấy filter_linear. |
| atlas_handle njin::atlas_create | ( | context & | ctx, |
| const atlas_desc & | desc = {} ) |
Tạo một atlas: nơi ghép nhiều ảnh nhỏ vào một texture lớn.
Raylib gom các lệnh vẽ liền nhau dùng chung texture thành một. Sprite xếp theo layer hoặc theo y mà dùng nhiều texture khác nhau thì lệnh vẽ bị ngắt mỗi lần đổi texture; ảnh cùng atlas là cùng texture, nên các lệnh đó nhập lại thành một. Xem số lệnh vẽ ước tính trong njin_inspector.
Ảnh nạp bằng atlas_load() cho ra texture_handle thường, dùng được ở mọi nơi nhận texture_handle: sprite, tilemap, hạt, UI, texture_draw().
| ctx | Context của engine. |
| desc | Kích thước trang, viền và bộ lọc. |
| texture_handle njin::atlas_load | ( | context & | ctx, |
| atlas_handle | atlas, | ||
| const char * | path ) |
Nạp một file ảnh và xếp vào atlas.
Atlas thêm trang mới khi trang cũ hết chỗ. Ảnh chỉ xếp vào atlas được nếu vừa một trang; ảnh lớn hơn được nạp như texture_load() và có cảnh báo trong log.
Khác với texture_load():
| ctx | Context của engine. |
| atlas | Atlas cần xếp vào. |
| path | Đường dẫn file ảnh. |
| void njin::atlas_destroy | ( | context & | ctx, |
| atlas_handle | atlas ) |
Hủy atlas: giải phóng các trang.
Mọi texture_handle lấy từ atlas này thành không hợp lệ. Handle không hợp lệ bị bỏ qua.
| ctx | Context của engine. |
| atlas | Atlas cần hủy. |
| void njin::texture_set_filter | ( | context & | ctx, |
| texture_handle | handle, | ||
| texture_filter | filter ) |
Đổi cách lấy mẫu của texture.
| ctx | Context của engine. |
| handle | Texture cần đổi. |
| filter | Cách lấy mẫu. |
| void njin::render_texture_set_filter | ( | context & | ctx, |
| render_texture_handle | handle, | ||
| texture_filter | filter ) |
Đổi cách lấy mẫu của render texture.
Render texture mới tạo lấy mẫu kiểu filter_nearest. Đặt filter_linear khi shader của game (xem draw_instanced()) đọc nó ở kích thước khác kích thước đã vẽ.
| ctx | Context của engine. |
| handle | Render texture cần đổi. |
| filter | Cách lấy mẫu. |
| void njin::texture_draw_ex | ( | const context & | ctx, |
| texture_handle | handle, | ||
| const texture_draw_desc & | desc ) |
Vẽ texture với vùng nguồn, tỉ lệ, điểm neo, góc xoay và lật.
| ctx | Context của engine. |
| handle | Texture cần vẽ. |
| desc | Tham số vẽ. |
| void njin::texture_set_shader | ( | context & | ctx, |
| texture_handle | handle, | ||
| shader_handle | shader ) |
Gắn một shader "vật liệu" cố định vào texture: không cần bọc shader_begin()/shader_end() quanh mỗi lần vẽ nữa.
Từ lần vẽ kế tiếp, mọi texture_draw() và texture_draw_ex() vẽ handle tự bật shader này (kể cả các ảnh phụ đã gắn bằng shader_set_texture()), rồi tắt lại ngay sau khi vẽ xong. Cách cũ vẫn dùng được nguyên vẹn và luôn thắng: nếu đang ở giữa một shader_begin() khác (kể cả của một texture có vật liệu khác), texture_draw()/texture_draw_ex() giữ nguyên shader đó, không thay bằng vật liệu của mình. Đặt uniform bằng shader_set_*() trước khi vẽ, như shader_begin().
Không áp dụng cho sprite/tilemap/particle vẽ qua ECS: những hệ đó tự quản shader riêng (ví dụ flash/dissolve của njin_fx.h).
| ctx | Context của engine. |
| handle | Texture cần gắn. |
| shader | Shader cần gắn, hoặc handle có id 0 để gỡ vật liệu. |
| texture_handle njin::texture_load | ( | context & | ctx, |
| const char * | path ) |
Nạp một texture từ file ảnh.
Handle không hợp lệ hoặc đã unload bị mọi hàm texture bỏ qua.
| ctx | Context của engine. |
| path | Đường dẫn file ảnh. |
| void njin::texture_unload | ( | context & | ctx, |
| texture_handle | handle ) |
Giải phóng texture.
Handle không hợp lệ bị bỏ qua.
| ctx | Context của engine. |
| handle | Texture cần giải phóng. |
| vec2 njin::texture_size | ( | const context & | ctx, |
| texture_handle | handle ) |
Kích thước texture (pixel).
| ctx | Context của engine. |
| handle | Texture cần hỏi. |
| void njin::texture_draw | ( | const context & | ctx, |
| texture_handle | handle, | ||
| vec2 | pos, | ||
| rgba | tint ) |
Vẽ texture với góc trên trái tại pos.
tint được nhân vào từng pixel, màu trắng {1, 1, 1, 1} giữ nguyên ảnh. Phải gọi giữa lúc bắt đầu và kết thúc vẽ của frame.
| ctx | Context của engine. |
| handle | Texture cần vẽ. |
| pos | Vị trí góc trên trái. |
| tint | Màu nhân vào ảnh. |