D
D
DeOxygen2020-09-23 20:56:58
Windows
DeOxygen, 2020-09-23 20:56:58

How to optimize drawing in SFML Image?

I'm drawing directly to image using setpixel, colormap. Everything was fine when checking the paint tools until it came to a brush with different sizes, the fact is that with fast mouse movements, the FPS drops to 30. Although I know that the problem is with loops and frequent calls to setPixel, but so far I do not know another way. I thought about a variant with fragment shaders.

inline void drawLineDDA(sf::Image* image, sf::Vector2f p0, sf::Vector2f p1, sf::Color color)
  {
    int dx = p1.x - p0.x;
    int dy = p1.y - p0.y;
    int steps;
    float x = p0.x;
    float y = p0.y;
    if (abs(dx)>abs(dy)) steps = abs(dx);
    else steps = abs(dy);
    float xi = dx / (float)steps;
    float yi = dy / (float)steps;
    
    //image->setPixel((x), (y), color);
    for (int i = -40; i <= 40; i++)
    {
      for (int j = -40; j <= 40; j++)
        image->setPixel(x + i, y + j, color);
    }
    for (int k = 0; k < steps; k++)
    {
      x += xi;
      y += yi;
      //image->setPixel(x, y, color);
      for (int i = -40; i <= 40; i++)
      {
        for (int j = -40; j <= 40; j++)
          image->setPixel(x + i, y + j, color);
      }
    }
  }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey, 2015-11-17
@Dier_Sergio_Great

In total commander there is a search option Find files NOT containing the text

0
074909, 2015-11-18
@074909

findstr.exe /s /m /v /c:"defined( '_JEXEC' )" *.php

(COMPUTER\user) C:\Users\user\
>findstr /?
Finding strings in files.
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [ /F:file]
[/C:line] [/G:file] [/D:folderlist] [/A:colors] [/OFF[LINE]]
lines
/B Search for pattern only at the beginning of lines.
/E Look for pattern only at the end of lines.
/L Search strings verbatim.
/R Search for strings as regular expressions.
/S Searches for files in the current folder and all its subfolders.
/I Specifies that the search will be case-insensitive.
/X Print lines that match exactly.
/V Print lines that do not match the search strings.
/N Prints the line number where the match is found.
/M Prints only the name of the file where the match is found.
/O Prints found lines separated by an empty line.
/P Skip lines containing non-printable characters.
/OFF[LINE] Do not skip files with the Offline attribute set.
/A:colors Two hexadecimal digits are color attributes. See "COLOR /?"
/F:file Reads a list of files from the specified file (/ for console).
/C:string Uses the given string as the search phrase to be searched.
/G:file Get lines from the specified file (/ for console).
/D:folderlist Searches in the list of folders (separated by a semicolon).
string The search text.
[drive:][path]filename
Specifies the name of the file or files.
Use spaces to separate multiple search strings unless the argument
is prefixed with /C. For example, 'FINDSTR "Hello world" ab' looks for "Hello" or "world" in file ab, and '
FINDSTR /C:"Hello world" ab' looks for the string
"Hello world" in file ab
:
. Any character.
* Repeat: zero or more occurrences of the previous character or
class
^ Position in the string:
$ Position in string: end of string
[class] Character class: any single character from the set
[^class] Reverse character class: any single character from complement
[xy] Range: any characters from the specified range
\x Service character: character designation of a service character x
\ Word position: at the end of a word
For complete information about FINDSTR regular expressions, see the
online documentation available.

M
maaGames, 2020-09-24
@DeOxygen

For example, create a buffer image the size of a brush diameter and draw a brush texture into this image (this is not necessarily a circle, you can make any shape by the way). And only then draw the picture of the brush repeatedly on the canvas. Not pixel by pixel, but by the function of drawing a picture. It should be much faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question