#create texture in code

2 messages · Page 1 of 1 (latest)

gray hare
#

I ran into this today trying to make a texture that was just a background fill color, with another texture drawn on top of it.

What I would really like, is some way to use the standard draw_ functions (like draw_circle()) on Images
As someone who used Gamemaker until last year, not being able to do this can sting sometimes

Here is the code I ended up going with

var working_image := Image.create_empty(dimensions.x,dimensions.y,false,Image.FORMAT_RGBA8)
    var fill_color:Color
    if from.mobility:
        fill_color=mobility_color
    else:
        fill_color=offense_color
        
    working_image.fill(fill_color)
    var og_image:=from.graphic.get_image()
    #why
    for x in dimensions.x:
        for y in dimensions.y:
            var old_color:Color = working_image.get_pixel(x,y)
            var new_color:Color = og_image.get_pixel(x,y)
            working_image.set_pixel(x,y,old_color.blend(new_color))
    
    var final_texture := ImageTexture.create_from_image(working_image)

It works fine, but it seems likely less efficient than a draw_texture() call could be
if I wanted something very much more complicated, I think I would be forced to code my own implementation of stuff like draw_circle, draw_texture, and so on)
I know one can use viewports, but I really want something that doesn't involve messing with the scene tree and can be down very quickly on the main thread in code, such that I could assign the generated texture on the next line

If anyone knows a good way to do this, or wants further discussion or clarification, please at me

#

Discord wouldn't let me put more words

Just for fun, here is an old snippet from a gamemaker project do demonstrate how easy it was

swid=sprite_get_width(guy.sprite_index)
    sheight=sprite_get_height(guy.sprite_index)
    surf = surface_create(2048,2048)
    surface_set_target(surf);
    draw_clear_alpha(c_black, 0)
    draw_sprite(guy.spriteog,0,0,0)
    for(i=0;i<children;i++)
    {
        if(childrencontainers[i].inventoryslotsfull[0])
        {
            draw_sprite(childrencontainers[i].inventoryslotscontain[0].spriteog,0,0,0)
        }
    }
    createdsprite=sprite_create_from_surface(surf,0,0,swid,sheight,0,0,0,0)