How to create single color texture without loading it from file?

#1

Hi!

I need a Handle to a texture that is 1x1 in pixels and single color, how can I achieve this without loading a 1x1 image file? Right now I have something like this:

    let mut renderer = Renderer::new().unwrap();
    let single_color_texture = renderer
        .create_texture(
            Texture::from_color_val([1.0, 1.0, 1.0, 1.0]).with_size(1, 1)
        )
        .unwrap();

It however panics with:
Error InvalidOperation creating texture: Info { kind: D2(1, 1, Single), levels: 1, format: R8_G8_B8_A8, bind: SHADER_RESOURCE, usage: Data }

The renderer create_texture method returns a Texture, how can I convert it to a Handle?

0 Likes

(Théo Degioanni) #2

I’ve never used it myself, but I believe you can use the load_from_data method on the asset loader to load a texture directly from in-memory data. Hope this helps.

0 Likes

#3

Is as @Moxinilian says, check it out this example

0 Likes