Well, I'm really stumped here. All I want to do is to generate a bitmap from scratch (in a buffer, because it gives such an option) and copy to a surface for further processing. However, whenever I actually try doing that, I instead end up clearing the surface somehow.
If someone has a basic code that e.g. generates entirely white bitmap and copies that to a surface (a buffer_set_surface "hello world" of sorts), I'd really appreciate it.
Generally, here is some code I used for testing (in Draw Event). Feel free to copy it to dummy object if you want to test it:
The behaviour I observed is confusing, to say the least.
Anyone has idea how to correctly generate surfaces from buffers? That behaviour is unfathomable to me. I later tried adding more buffers, and it seems like the surface most recently retrieved via buffer_get_surface is the one actually drawn. It's all the more confusing since I heard from some people they used buffer_get_surface without issues...
Kind of like, the program looks at the buffer, makes sure it's valid and that it's not undersized (otherwise it fail silently drawing that buffer, apparently), then decides to draw whichever surface was last passed to buffer_get_surface. Kinda reminds me of that quote:
(and yet, buffer_get_surface seems to work just fine, populating the buffer and stuff; it's just buffer_set_surface that works in mysterious, incomprehensible ways...)
If someone has a basic code that e.g. generates entirely white bitmap and copies that to a surface (a buffer_set_surface "hello world" of sorts), I'd really appreciate it.
Generally, here is some code I used for testing (in Draw Event). Feel free to copy it to dummy object if you want to test it:
Code:
// source surface
var src = surface_create(64, 64);
surface_set_target(src);
draw_clear(c_black);
surface_reset_target();
// buffer
var b = buffer_create(64 * 64 * 4, buffer_fixed, 4);
buffer_get_surface(b, src, 0, 0, 0);
buffer_fill(b, 0, buffer_u32, $ffffffff, buffer_get_size(b));
// destination surface
var dest = surface_create(64, 64);
surface_set_target(dest);
draw_clear(c_red);
surface_reset_target();
//b = buffer_create(64 * 64 * 4, buffer_fixed, 4);
// copying data to destination and drawing the surface
buffer_set_surface(b, dest, 0, 0, 0);
draw_surface(dest, x, y);
// cleaning up
buffer_delete(b);
surface_free(src);
surface_free(dest);
- if I comment out buffer_set_surface line, the drawn surface is red, which is actually kinda obvious (the destination surface is initialised as red, and without buffer_set_surface is not affected any further)
- if I comment out buffer_get_surface line, the drawn surface is transparent, as if after being first painted red it gets replaced with all #00000000 pixels (kind of like the buffer is empty)
- if I don't comment out the buffer_get_surface line, the drawn surface is instead black, as if the buffer is successfully filled with #FF000000 pixels from the source surface
- buffer_fill doesn't change the drawn surface; I'd expect it to make the represented bitmap all white; instead, all I get is the initially copied surface
- uncommenting later buffer_create line doesn't change anything either; if buffer_get_surface line is executed, the drawn surface will be black like that source surface that copied itself to the buffer I'm not even referencing anymore
Anyone has idea how to correctly generate surfaces from buffers? That behaviour is unfathomable to me. I later tried adding more buffers, and it seems like the surface most recently retrieved via buffer_get_surface is the one actually drawn. It's all the more confusing since I heard from some people they used buffer_get_surface without issues...
Kind of like, the program looks at the buffer, makes sure it's valid and that it's not undersized (otherwise it fail silently drawing that buffer, apparently), then decides to draw whichever surface was last passed to buffer_get_surface. Kinda reminds me of that quote:
Seriously, like the actual data from the buffer isn't used at all. ^^'Every time the Tardis materialises in a new location, within the first nanosecond of landing, it analyses its surroundings, calculates a 12-dimensional data map of everything within a thousand mile radius, and determines which outher shell would blend in best with the enviroment. And then it disguises itself as a police telephone box from 1963.
(and yet, buffer_get_surface seems to work just fine, populating the buffer and stuff; it's just buffer_set_surface that works in mysterious, incomprehensible ways...)