Ảnh ngoài màn hình để vẽ vào, dùng cho post-processing. Tiếp...
Các hàm | |
| render_texture_handle | njin::render_texture_load (context &ctx, u32 width, u32 height) |
| Tạo một render texture: ảnh ngoài màn hình để vẽ vào, rồi vẽ lại như một texture. | |
| void | njin::render_texture_unload (context &ctx, render_texture_handle handle) |
| Giải phóng render texture. | |
| vec2 | njin::render_texture_size (const context &ctx, render_texture_handle handle) |
| Kích thước render texture (pixel). | |
| void | njin::render_texture_begin (const context &ctx, render_texture_handle handle) |
| Bắt đầu vẽ vào render texture, giữ nguyên nội dung cũ. | |
| void | njin::render_texture_begin (const context &ctx, render_texture_handle handle, rgba clear) |
| Giống bản trên nhưng xóa render texture bằng màu clear trước. | |
| void | njin::render_texture_end (const context &ctx) |
| Kết thúc vẽ vào render texture. | |
| bool | njin::render_texture_save (context &ctx, render_texture_handle handle, const char *path) |
| Lưu nội dung render texture ra file ảnh, ngay lập tức. | |
| void | njin::render_texture_draw (const context &ctx, render_texture_handle handle, vec2 pos, rgba tint) |
| Vẽ nội dung render texture theo đúng chiều, góc trên trái tại pos. | |
Ảnh ngoài màn hình để vẽ vào, dùng cho post-processing.
| render_texture_handle njin::render_texture_load | ( | context & | ctx, |
| u32 | width, | ||
| u32 | height ) |
Tạo một render texture: ảnh ngoài màn hình để vẽ vào, rồi vẽ lại như một texture.
Dùng cho post-processing hoặc vẽ trước một cảnh phức tạp.
| ctx | Context của engine. |
| width | Chiều rộng (pixel). |
| height | Chiều cao (pixel). |
| void njin::render_texture_unload | ( | context & | ctx, |
| render_texture_handle | handle ) |
Giải phóng render texture.
Handle không hợp lệ bị bỏ qua.
| ctx | Context của engine. |
| handle | Render texture cần giải phóng. |
| vec2 njin::render_texture_size | ( | const context & | ctx, |
| render_texture_handle | handle ) |
Kích thước render texture (pixel).
| ctx | Context của engine. |
| handle | Render texture cần hỏi. |
| void njin::render_texture_begin | ( | const context & | ctx, |
| render_texture_handle | handle ) |
Bắt đầu vẽ vào render texture, giữ nguyên nội dung cũ.
Mọi lệnh vẽ giữa render_texture_begin() và render_texture_end() đi vào render texture, trong hệ pixel của chính nó (không qua camera).
Lệnh này đặt lại phép biến đổi của camera, nên không dùng trong phase_pre_render hay phase_render. Hãy vẽ vào render texture ở phase_post_update hoặc phase_post_render.
| ctx | Context của engine. |
| handle | Render texture cần vẽ vào. Handle không hợp lệ bị bỏ qua. |
| void njin::render_texture_begin | ( | const context & | ctx, |
| render_texture_handle | handle, | ||
| rgba | clear ) |
Giống bản trên nhưng xóa render texture bằng màu clear trước.
| ctx | Context của engine. |
| handle | Render texture cần vẽ vào. Handle không hợp lệ bị bỏ qua. |
| clear | Màu dùng để xóa. |
| void njin::render_texture_end | ( | const context & | ctx | ) |
Kết thúc vẽ vào render texture.
| ctx | Context của engine. |
| bool njin::render_texture_save | ( | context & | ctx, |
| render_texture_handle | handle, | ||
| const char * | path ) |
Lưu nội dung render texture ra file ảnh, ngay lập tức.
Ảnh theo đúng chiều đã vẽ (góc trên trái của hình vẽ là góc trên trái của file) và giữ nguyên từng byte, kể cả kênh alpha: không nhân hay chia alpha, nên một render texture dùng để chứa dữ liệu (sprite sheet đã bake, xem draw_instanced()) lưu ra được đúng như nó chứa.
Định dạng theo đuôi file: .png (nên dùng), .bmp, .tga, .qoi. Thư mục cha được tạo nếu chưa có. Không gọi giữa render_texture_begin() và render_texture_end(). Đọc lại từ GPU nên chậm hơn nhiều so với một lệnh vẽ: dùng khi xuất file, không phải mỗi frame.
| ctx | Context của engine. |
| handle | Render texture cần lưu. Handle không hợp lệ thì trả về false. |
| path | Đường dẫn file. Muốn lưu vào thư mục lưu game thì dùng save_path(). |
| void njin::render_texture_draw | ( | const context & | ctx, |
| render_texture_handle | handle, | ||
| vec2 | pos, | ||
| rgba | tint ) |
Vẽ nội dung render texture theo đúng chiều, góc trên trái tại pos.
| ctx | Context của engine. |
| handle | Render texture cần vẽ. |
| pos | Vị trí góc trên trái. |
| tint | Màu nhân vào ảnh. Màu trắng {1, 1, 1, 1} giữ nguyên ảnh. |