Jump to content

GPU Drawing - lines not 1px wide?


Recommended Posts

I've created this little French Tiling plugin. Can someone please tell me why it is rendering a 2px thick lines? (I expected a single pixel).

 

Something to do with AA maybe?

 

// Name:
// Submenu:
// Author:
// Title:
// Version:
// Desc:
// Keywords:
// URL:
// Help:

// For help writing a GPU Drawing plugin: https://boltbait.com/pdn/CodeLab/help/tutorial/drawing/

#region UICode
IntSliderControl tileSize = 10; // [8,100] Tile size
IntSliderControl numberOfRows = 100; // [2,100] Number of Rows
IntSliderControl numberOfColumns = 100; // [2,100] Number of Columns
IntSliderControl hOffset = 0; // [0,5] Left to Right offset
IntSliderControl vOffset = 0; // [0,5] Top to Bottom offset
#endregion

protected override unsafe void OnDraw(IDeviceContext deviceContext)
{
    // TODO: replace this DrawImage statement with your GPU Drawing statements
    deviceContext.DrawImage(Environment.SourceImage);

    // define the pattern
    int[,] tilePattern = {
        {3,3,1,3,2,0},
        {1,2,0,3,1,3},
        {0,3,3,2,0,2},
        {0,2,3,1,1,2},
        {3,1,2,0,0,3},
        {2,0,3,1,3,1}
    };

    ISolidColorBrush outlineBrush = deviceContext.CreateSolidColorBrush(LinearColors.Black);

    for (int row = 0; row < numberOfRows; row++)
    {
        for (int col = 0; col < numberOfColumns; col++)
        {
            int x = col * tileSize;
            int y = row * tileSize;

            switch (tilePattern[(row+vOffset) % 6, (col+hOffset) % 6])
            {
                case 0:
                    // No borders on this cell
                    break;
                case 1:
                    // North border only
                    deviceContext.DrawLine(x,y,x+tileSize,y,outlineBrush);
                    break;
                case 2:
                    // West border only
                    deviceContext.DrawLine(x,y,x,y+tileSize,outlineBrush);
                    break;
                case 3:
                    // Both North and West borders
                    deviceContext.DrawLine(x,y,x+tileSize,y,outlineBrush);
                    deviceContext.DrawLine(x,y,x,y+tileSize,outlineBrush);
                    break;
            }
        }
    }
}

 

Link to comment
Share on other sites

Thanks Rick!!

 

Alright. I have something that is.......workable :)

 

// Name:
// Submenu:
// Author:
// Title:
// Version:
// Desc:
// Keywords:
// URL:
// Help:

// For help writing a GPU Drawing plugin: https://boltbait.com/pdn/CodeLab/help/tutorial/drawing/

#region UICode
IntSliderControl tileSize = 10; // [8,100] Tile size
IntSliderControl numberOfRows = 100; // [2,100] Number of Rows
IntSliderControl numberOfColumns = 100; // [2,100] Number of Columns
IntSliderControl hOffset = 0; // [0,5] Left to Right offset
IntSliderControl vOffset = 0; // [0,5] Top to Bottom offset
#endregion

protected override unsafe void OnDraw(IDeviceContext deviceContext)
{
    // TODO: replace this DrawImage statement with your GPU Drawing statements
    deviceContext.DrawImage(Environment.SourceImage);

    // define the pattern
    int[,] tilePattern = {
        {3,3,1,3,2,0},
        {1,2,0,3,1,3},
        {0,3,3,2,0,2},
        {0,2,3,1,1,2},
        {3,1,2,0,0,3},
        {2,0,3,1,3,1}
    };

    ISolidColorBrush outlineBrush = deviceContext.CreateSolidColorBrush(LinearColors.Black);

    for (int row = 0; row < numberOfRows; row++)
    {
        for (int col = 0; col < numberOfColumns; col++)
        {
            float x = col * tileSize+0.5f;
            float y = row * tileSize+0.5f;

            Point2Float start = new Point2Float(x, y);
            Point2Float endX = new Point2Float(x+tileSize+0.5f, y);
            Point2Float endY = new Point2Float(x,y+tileSize+0.5f);

            switch (tilePattern[(row+vOffset) % 6, (col+hOffset) % 6])
            {
                case 0:
                    // No borders on this cell
                    break;
                case 1:
                    // North border only
                    deviceContext.DrawLine(start,endX,outlineBrush);
                    break;
                case 2:
                    // West border only
                    deviceContext.DrawLine(start,endY,outlineBrush);
                    break;
                case 3:
                    // Both North and West borders
                    deviceContext.DrawLine(start,endX,outlineBrush);
                    deviceContext.DrawLine(start,endY,outlineBrush);
                    break;
            }
        }
    }
}

 

Feels a bit hacky, but it 's not like I'm going to release it :)

 

  • Upvote 1
Link to comment
Share on other sites

  • Ego Eram Reputo changed the title to GPU Drawing - lines not 1px wide?
16 minutes ago, Ego Eram Reputo said:

Feels a bit hacky

 

Indeed. You don't need to offset each point.

You can set the offset once with UseTranslateTransform.

https://forums.getpaint.net/topic/131297-gpu-drawing-lines-not-1px-wide/

 

  • Upvote 1

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

59 minutes ago, toe_head2001 said:

 

Indeed. You don't need to offset each point.

You can set the offset once with UseTranslateTransform.

https://forums.getpaint.net/topic/131297-gpu-drawing-lines-not-1px-wide/

 

Thanks for that. Can't believe that thread has exactly the same title - and yet I missed it :mrgreen:

Link to comment
Share on other sites

30 minutes ago, Ego Eram Reputo said:

Can't believe that thread has exactly the same title - and yet I missed it

 

It didn't... those posts were deeply buried in another forum topic, and I split them out.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...