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

Author Topic: How do I clear Pixels?  (Read 3193 times)

0 Members and 1 Guest are viewing this topic.

Felheart

  • Newbie
  • *
  • Posts: 23
    • View Profile
How do I clear Pixels?
« on: February 29, 2012, 01:06:58 pm »
Im using C# and I have a "RenderTexture".

Now I want to clear a line of pixels from the RenderTexture.
(So they should all have the argb value of 0,0,0,0)

Code: [Select]

vertices[0].Color = new Color(0, 0, 0, 0);
vertices[1].Color = new Color(0, 0, 0, 0);
vertices[0].Position = new Vector2f(x, 0);
vertices[1].Position = new Vector2f(x, 200);
myRenderTexture.Draw(vertices, PrimitiveType.Lines);


The problem is that its using alpha blending, so nothing is happening :(

I don't want that, I want to clear the pixels in that line.
What's the easiest way of doing that with the .NET bindings ?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
How do I clear Pixels?
« Reply #1 on: February 29, 2012, 01:16:52 pm »
Since you are using a RenderTexture, the only way I see to manipulate that buffer's data, is to convert it to a sf::Image, do the transformation you want,
then convert back to a RenderTexture...

Felheart

  • Newbie
  • *
  • Posts: 23
    • View Profile
How do I clear Pixels?
« Reply #2 on: February 29, 2012, 01:42:38 pm »
I use this renderTexture as a cache for a histogram.
I could also save the values to a array, but then I'd have to redraw the complete image of the histrogram every frame / everytime a value changes.

I'd prefer removing one histogram bar, and drawing a new line at that place.

Should I use something else then a rendertexture maybe?
Is there no "Replace pixel values" blend mode?
I can see Alpha, Add, Multiply and None. But no "replace" or "set".

Ill go with the convert to image solution for now, thanks

Would it be a good idea to have a "Vertex[]", that contains all the lines,
then drawing that in one big batch to the texture?
So I only have to modify the endpoint of the line that changes in order to change one bar of the histogram.

Would that be faster than modifying the pixels directly everytime?

Oh and another related question:
When and why should I use VertexArray instead of Vertex[] ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How do I clear Pixels?
« Reply #3 on: February 29, 2012, 04:02:00 pm »
Quote
The problem is that its using alpha blending

The problem is that you are using alpha blending ;)
Code: [Select]
vertices[0].Color = new Color(0, 0, 0);
vertices[1].Color = new Color(0, 0, 0);
vertices[0].Position = new Vector2f(x, 0);
vertices[1].Position = new Vector2f(x, 200);
myRenderTexture.Draw(vertices, PrimitiveType.Lines);

Or
Code: [Select]
vertices[0].Color = new Color(0, 0, 0, 0);
vertices[1].Color = new Color(0, 0, 0, 0);
vertices[0].Position = new Vector2f(x, 0);
vertices[1].Position = new Vector2f(x, 200);
myRenderTexture.Draw(vertices, PrimitiveType.Lines, new RenderStates(BlendMode.None));

(yes, "None" means "Replace")
Depends on what result you want.

Quote
When and why should I use VertexArray instead of Vertex[] ?

VertexArray = Array<Vertex> + PrimitiveType.
That's it, it's just there for convenience.
Laurent Gomila - SFML developer

Felheart

  • Newbie
  • *
  • Posts: 23
    • View Profile
How do I clear Pixels?
« Reply #4 on: February 29, 2012, 04:17:01 pm »
Yeah you're right (as always ;D)
Thanks for the answer, both work as intended.