The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
How about an SDL_RenderFillQuad function?
SeanOConnor


Joined: 15 Jun 2016
Posts: 9
I need to draw a graph in my game but it looks like the SDL_RenderDrawLine only draws lines 1 pixel wide. With a bit of maths I can work out the 4 points needed to draw a line of any width but the only SDL function that draws a primitive seems to be:

SDL_RenderFillRect

which only draws rectangles with no rotation.

I'm guessing this SDL function just draws two triangles to make this rectangle based on the SDL_Rect it's sent, so surely it'd be trivial to create a new function SDL_RenderFillQuad that accepts four SDL_Points and draws two triangles based on that?

And maybe an SDL_RenderFillTriangle too that takes three SDL_Points?
How about an SDL_RenderFillQuad function?
Jonny D


Joined: 12 Sep 2009
Posts: 932
It would probably be better to have a function for arbitrary geometry composed of triangles, like this one (SDL_RenderGeometry()):https://bugzilla.libsdl.org/show_bug.cgi?id=1734


But that feature has been waiting for over three years...  and this related one is 5 years old:
https://bugzilla.libsdl.org/show_bug.cgi?id=1138



Either of those would enable us to implement rotated quad rendering and keep the API lean.


In the meantime, I've suggested SDL_gpu if you really need this now.


Jonny D





On Fri, Sep 30, 2016 at 8:37 AM, SeanOConnor wrote:
Quote:
I need to draw a graph in my game but it looks like the SDL_RenderDrawLine only draws lines 1 pixel wide. With a bit of maths I can work out the 4 points needed to draw a line of any width but the only SDL function that draws a primitive seems to be:

SDL_RenderFillRect

which only draws rectangles with no rotation.

I'm guessing this SDL function just draws two triangles to make this rectangle based on the SDL_Rect it's sent, so surely it'd be trivial to create a new function SDL_RenderFillQuad that accepts four SDL_Points and draws two triangles based on that?

And maybe an SDL_RenderFillTriangle too that takes three SDL_Points?


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

How about an SDL_RenderFillQuad function?
Melker Narikka
Guest

If you're not too worried about performance, you could draw a
rectangle into an SDL_Texture
and then draw it rotated with SDL_RenderCopyEx. Of course you'd have
to do a bit more
additional arithmetic yourself as the function takes an angle in degrees.

--
Melker Narikka

On Fri, Sep 30, 2016 at 3:37 PM, SeanOConnor wrote:
Quote:
I need to draw a graph in my game but it looks like the SDL_RenderDrawLine
only draws lines 1 pixel wide. With a bit of maths I can work out the 4
points needed to draw a line of any width but the only SDL function that
draws a primitive seems to be:

SDL_RenderFillRect

which only draws rectangles with no rotation.

I'm guessing this SDL function just draws two triangles to make this
rectangle based on the SDL_Rect it's sent, so surely it'd be trivial to
create a new function SDL_RenderFillQuad that accepts four SDL_Points and
draws two triangles based on that?

And maybe an SDL_RenderFillTriangle too that takes three SDL_Points?

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SeanOConnor


Joined: 15 Jun 2016
Posts: 9
For now I've done:

Code:

for (xx=-1; xx<=+1; xx++)
{
   for (yy=-1; yy<=+1; yy++)
   {
      SDL_RenderDrawLine(m_pRenderer,
                     ptFrom.x + xx,
                     ptFrom.y + yy,
                     ptTo.x + xx,
                     ptTo.y + yy);
   }
}



I just thought that adding a quad, triangle or arbitrary number of points function would be so easy (as rects are drawn with triangles anyway) it might as well be added, and I was surprised those functions weren't there already.

I took a look at SDL_gpu but I'm wary of trying something without much documentation and potential future support. It does seem to use floating points for coordinates though which is another thing I don't get why SDL doesn't use.
How about an SDL_RenderFillQuad function?
Sanette
Guest

for lines, you can store a line in a texture (or, for that matter, you can simply store a pixel)
and then rotate and strech the texture with SDL_RenderCopyEx

Le 30/09/2016 à 17:07, SeanOConnor a écrit :

Quote:
For now I've done:








Code:
for (xx=-1; xx<=+1; xx++)
{
   for (yy=-1; yy<=+1; yy++)
   {
      SDL_RenderDrawLine(m_pRenderer,
                     ptFrom.x + xx,
                     ptFrom.y + yy,
                     ptTo.x + xx,
                     ptTo.y + yy);
   }
}




I just thought that adding a quad, triangle or arbitrary number of points function would be so easy (as rects are drawn with triangles anyway) it might as well be added, and I was surprised those functions weren't there already.

I took a look at SDL_gpu but I'm wary of trying something without much documentation and potential future support. It does seem to use floating points for coordinates though which is another thing I don't get why SDL doesn't use.


Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SeanOConnor


Joined: 15 Jun 2016
Posts: 9
I also want the line to be any colour (set by what the player chooses) so I couldn't use a fixed PNG file for my texture. I suppose I could create the texture on the fly and fill it with an SDL_RenderFillRect and then rotate that, but it seems like a hell of a lot of work for something that ought to be trivial.
Naith


Joined: 03 Jul 2014
Posts: 158
SeanOConnor wrote:
I also want the line to be any colour (set by what the player chooses) so I couldn't use a fixed PNG file for my texture. I suppose I could create the texture on the fly and fill it with an SDL_RenderFillRect and then rotate that, but it seems like a hell of a lot of work for something that ought to be trivial.

If you want to let the user control the color of a texture you can load, for example, a PNG-image containg a white quad and when the texture is created, use SDL_SetTextureColorMod to set the color of the texture.
rtrussell


Joined: 10 Feb 2016
Posts: 88
SeanOConnor wrote:
It does seem to use floating points for coordinates though which is another thing I don't get why SDL doesn't use.

Hear hear! I've tried SDL_gfx but that is very disappointing too. For example the routine which draws anti-aliased lines takes integer (pixel) coordinates for the end points, and the routines for drawing arcs and sectors take the start and end angles as integer degrees! Sorry, but this is fundamentally wrong.

Richard.
How about an SDL_RenderFillQuad function?
Jonny D


Joined: 12 Sep 2009
Posts: 932
Well, it's better than integer radians. Wink

Jonny D




On Fri, Sep 30, 2016 at 4:25 PM, rtrussell wrote:
Quote:



SeanOConnor wrote:

It does seem to use floating points for coordinates though which is another thing I don't get why SDL doesn't use.



Hear hear! I've tried SDL_gfx but that is very disappointing too. For example the routine which draws anti-aliased lines takes integer (pixel) coordinates for the end points, and the routines for drawing arcs and sectors take the start and end angles as integer degrees! Sorry, but this is fundamentally wrong.

Richard.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

How about an SDL_RenderFillQuad function?
Sik


Joined: 26 Nov 2011
Posts: 905
2016-09-30 12:07 GMT-03:00, SeanOConnor:
Quote:
I just thought that adding a quad, triangle or arbitrary number of points
function would be so easy (as rects are drawn with triangles anyway) it
might as well be added, and I was surprised those functions weren't there
already.

Because of the software renderer. That one is using dedicated
algorithms instead of triangles. And honestly a good reason why we
need triangle routines for it, because then at worst we can just build
everything else on top of that.

This is a problem that has been going on for a long while though. SDL
supports multiple backends for the renderer (software, different
OpenGL versions, different Direct3D versions), but they don't want to
add a new function that doesn't work in all backends. And then what
happens is somebody contributes a new function for one backend, but
then nobody wants to bother implementing the function in the other
backends, and the end result is that the function goes nowhere and
gets forgotten. On top of the fact most people don't want to use the
renderer anyway (they either use SDL_gpu or, more likely, they just go
straight with their own OpenGL code).

Actually heck, adding triangle functions would probably solve it for
all backends.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
How about an SDL_RenderFillQuad function?
Travis McKinney
Guest

I've been messing around with AGG to draw quality lines.
http://www.antigrain.com/index.html

There's a basic hello world integrating SDL2 and AGG at
https://github.com/koopdi/draw


On 30 September 2016 at 15:18, Sik the hedgehog wrote:
Quote:
2016-09-30 12:07 GMT-03:00, SeanOConnor:
Quote:
I just thought that adding a quad, triangle or arbitrary number of points
function would be so easy (as rects are drawn with triangles anyway) it
might as well be added, and I was surprised those functions weren't there
already.

Because of the software renderer. That one is using dedicated
algorithms instead of triangles. And honestly a good reason why we
need triangle routines for it, because then at worst we can just build
everything else on top of that.

This is a problem that has been going on for a long while though. SDL
supports multiple backends for the renderer (software, different
OpenGL versions, different Direct3D versions), but they don't want to
add a new function that doesn't work in all backends. And then what
happens is somebody contributes a new function for one backend, but
then nobody wants to bother implementing the function in the other
backends, and the end result is that the function goes nowhere and
gets forgotten. On top of the fact most people don't want to use the
renderer anyway (they either use SDL_gpu or, more likely, they just go
straight with their own OpenGL code).

Actually heck, adding triangle functions would probably solve it for
all backends.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org