Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: (Full code inside!) Is my pixel-by-pixel drawing method right enough?  (Read 2542 times)

0 Members and 1 Guest are viewing this topic.

LakySimi1

  • Newbie
  • *
  • Posts: 35
    • View Profile
Hi everyone!
I'm making a game and i'm questioning if my drawing method is right enough or can be improved.
I really like to draw a pixel at a time.

I pick the color of the pixel i want to draw from and image and than i transfer the RGB data on a 'pixels' array. Then i transfer this 'pixels' array into a Texture, then it into a Sprite and then i display the final Window, this last part (last 3 rows) are a mistery to me, i've seen it online ^^

CODE
(click to show/hide)


EDIT
What's 'better': use a pixel array and transfer to a Texture OR using an Image and then transfer it to a Texture?

I provide two full code which show that the PixelArray solution is faster but maybe is also stressful for the PC?
(click to show/hide)
« Last Edit: April 20, 2022, 09:23:51 pm by LakySimi1 »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Is my pixel-by-pixel drawing method right enough?
« Reply #1 on: April 18, 2022, 01:09:53 pm »
Another approach is to use graphical objects rather than updating a texture every frame.

For example, you can simply draw a vertex for each pixel you want to colour. All of them if you wish. To do this, you could use a vector of vertices - one for each pixel - and either draw them all each frame, or draw them all to a render texture and then draw that as a sprite/quad; this reduces the number of vertices needed to draw if they don't constantly change.

Another example is to to cover the window with a tile-like object that you can colour each tile individually. If those tiles are pixel sized, you have your pixel control. If they are larger, than the "resolution" appears lower. e.g. if the tiles are 2x2, the "resolution" could seem slightly pixelated but if they are 16x16, they definitely will.

If you decide to try out the latter suggest I gave, you could also try out Selba Ward's Pixel Display, designed to simplify this sort of thing. It's technically designed for lower resolution/colour-paletted display emulation but it's up to you whether or not it's a good approach for actual pixel-by-pixel manipulation.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

LakySimi1

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Is my pixel-by-pixel drawing method right enough?
« Reply #2 on: April 20, 2022, 10:41:30 am »
Another approach is to use graphical objects rather than updating a texture every frame.

For example, you can simply draw a vertex for each pixel you want to colour. All of them if you wish. To do this, you could use a vector of vertices - one for each pixel - and either draw them all each frame, or draw them all to a render texture and then draw that as a sprite/quad; this reduces the number of vertices needed to draw if they don't constantly change.

Another example is to to cover the window with a tile-like object that you can colour each tile individually. If those tiles are pixel sized, you have your pixel control. If they are larger, than the "resolution" appears lower. e.g. if the tiles are 2x2, the "resolution" could seem slightly pixelated but if they are 16x16, they definitely will.

If you decide to try out the latter suggest I gave, you could also try out Selba Ward's Pixel Display, designed to simplify this sort of thing. It's technically designed for lower resolution/colour-paletted display emulation but it's up to you whether or not it's a good approach for actual pixel-by-pixel manipulation.

But what do you think about my method? Is it enough right? Is somehow wrong and sloppy or inefficient (slow)?

I'm intersted in both of your methods, do they speed up a little the rendering confronted to mine?
If you can please provide a simple code to test them it would be great!

Uh you've made your own function library, nice!

 

anything