How to apply one surface to another?
yeheshuah opened this issue · comments
∞ commented
Is there a way to create surface and apply its to another one?
Furthermore, can I transform surface when applying?
Sample code:
#include "plutovg.h"
int main(void)
{
unsigned char data[] = { /* omission */ };
plutovg_surface_t* surface1 = plutovg_surface_create(300, 200);
plutovg_t* pluto = plutovg_create(surface1);
plutovg_surface_t* surface2 = plutovg_surface_create(300, 200);
surface2 = plutovg_surface_create_for_data(data, 300, 200, 4);
/*
Until here I don't have any problems.
If I do `plutovg_surface_write_to_png(surface2, "surface2.png");`, image is OK.
Problem is how to apply surface2 to surface1.
There is `plutovg_set_texture_surface`, but I didn't understand can I use it to satisfy the above conditions.
*/
}
Goal is to draw surface2 to surface1:
Thanks in advance!
Samuel Ugochukwu commented
plutovg_surface_t* surface1 = plutovg_surface_create(300, 200);
plutovg_surface_t* surface2 = plutovg_surface_create(300, 200);
plutovg_t* pluto = plutovg_create(surface1);
plutovg_set_texture_surface(pluto, surface2, x, y);
/**
plutovg_set_operator(pluto, mode);
plutovg_set_opacity(pluto, opacity);
plutovg_set_matrix(pluto, matrix);
**/
plutovg_paint(pluto);
∞ commented
Thank you for answer. Very helpful!
The code below is how I was able to implement it.
But I have a question, shall I call plutovg_save
and plutovg_restore
in below case?
※ Actually it works without plutovg_save
and plutovg_restore
※ Also, it works without plutovg_set_operator
and plutovg_set_opacity
.
//plutovg_save(pluto);
texture = plutovg_set_texture(pluto, surface, plutovg_texture_type_plain);
plutovg_identity_matrix(pluto);
plutovg_rect(pluto, x, y, w, h);
plutovg_clip(pluto);
plutovg_matrix_init_identity(&matrix);
plutovg_matrix_translate(&matrix, x, y);
plutovg_matrix_scale(&matrix, w, y);
plutovg_set_operator(pluto, plutovg_operator_src);
plutovg_set_opacity(pluto, 1.0);
plutovg_set_matrix(pluto, &matrix);
plutovg_paint(pluto);
//plutovg_restore(pluto);