# How can i draw a line on image-source?



## nemo (Aug 16, 2017)

i want to write a plugin provide painting feature that shows in the image.


----------



## nemo (Aug 21, 2017)

here is the answer:

```
struct pen_source *context = bzalloc(sizeof(struct pen_source));
    context->source = source;

    if (context->tex)
        gs_texture_destroy(context->tex);

    struct obs_video_info ovi;
    obs_get_video_info(&ovi);
    context->width = (int)ovi.base_width;
    context->height = (int)ovi.base_height;
    size_t len = sizeof(char) * context->width * context->height * 4;
    context->data = bzalloc(len);
    memset(context->data, 0xff, len);

    obs_enter_graphics();
    context->tex = gs_texture_create(context->width, context->height, GS_RGBA, 1,
        &context->data, GS_DYNAMIC);
    obs_leave_graphics();

     .......
   
    obs_enter_graphics();
    gs_effect_set_texture(gs_effect_get_param_by_name(effect, "image"), context->tex);
    gs_draw_sprite(context->tex, 0, context->width, context->height); 
    obs_leave_graphics();
```


----------



## nemo (Aug 25, 2017)

a better implementation.

```
obs_enter_graphics();
        gs_render_start(true);
        gs_vertex2f(x2, y2);
        gs_vertex2f(x1, y1);
        gs_vertex2f(x2 + x_offset, y2 + y_offset);
        gs_vertex2f(x1 + x_offset, y1 + y_offset);
        line->buf = gs_render_save();
        obs_leave_graphics();
```


----------



## nemo (Aug 28, 2017)

you can find source code here:
https://github.com/nemoofnemo/obs-multiple-image-source


----------



## David Carver (Aug 30, 2017)

nemo said:


> you can find source code here:
> https://github.com/nemoofnemo/obs-multiple-image-source



I've been looking for something like this for doing for some live video commentary.  Any chance of packaging this up into a proper plugin and having it work across the platforms (i.e. windows, mac, and linux?)


----------



## nemo (Aug 31, 2017)

David Carver said:


> I've been looking for something like this for doing for some live video commentary.  Any chance of packaging this up into a proper plugin and having it work across the platforms (i.e. windows, mac, and linux?)


i'm working on it


----------



## David Carver (Aug 31, 2017)

Cool, when you get it to a state that you feel comfortable it is ready to test, I'll be a guinea pig.


----------



## c3r1c3 (Sep 28, 2017)

https://github.com/sam0737/TransparentPaint


----------



## c00lnerd (Aug 18, 2019)

This is in Visual c#. Did you create an install for it, or an executable? I can't do that on this computer. Maybe I'll try to do that on my other computer where I do c#.


----------

