SDL_DrawLine, SDL_DrawRect, SDL_RenderReadPixels, RectCollide… are not working properly. Has anyone reported it ??
“It doesn’t work” are the least useful words in the history of error reporting. What that actually means is “it’s doing something other than what I expect.” But as you have explained neither what it’s doing nor what you expect, we have nothing to go on.
It would be much more helpful if you reported it like this:
“I’m doing X. [Show code if applicable.] I’m expecting Y to happen, but Z is happening instead.”
Sparky Linux 64, SDL 2.0.14
SDL_RenderDrawLine(SDLRenderer, 1, 1,1, 1); - draws 2 points
SDL_RenderDrawRect - draws an extra point at the corner
SDL_HasIntersection(&SRC,&DST) - RETURNS 0
Older versions have had many problems with line drawing due to using the underlying GPU driver to do the actual line drawing, which varied across GPUs, operating systems, underlying GPU APIs, and even driver revisions. SDL 2.0.20 uses
SDL_RenderGeometry() to draw lines IIRC, so it can specify the exact start and end point
SDL_Rect is origin and then size. A rectangle at (0,0) with a width and height of 10 will have the bottom right at (9,9) (just like making a window 800x600 has coordinates that go from (0,0) to (799,599)). Your second rectangle, whose origin is at (10,0) does not intersect.
Then why when I draw a rectangle, it reaches 10, 10 and not 9, 9? Inconsistent this geometry …
Hi Rosy, that’s a fair point. There is inconsistency because different hardware uses different line algorithms. Older versions of SDL have really struggled to get this to work nicely.
Please upgrade to 2.0.20 and look at
SDL_HINT_RENDER_LINE_METHOD. A lot of work has been done to make this more uniform and to give different line drawing methods which will give you the desired result.
I can’t update because it won’t work on old Android. Although I don’t know how to start it anyway …
I have SDL 2.0.20 and the latest source version working on Android as low as 4.1.1 no problem.
I don’t know how you do it …
With difficulty - I don’t know what steps I took to get it working. Please know that it does work very nicely once it’s set up. I’m using the latest version of Android Studio with the very latest version of Gradle, build tools, etc. I had to do some tweaking. Don’t give up, keep trying.
I think the latest source version of SDL comes with an up to date Gradle project, so it should almost work out of the box now.
But the new NDK no longer supports old versions …
It actually worked in Android, but there are bugs. E.g. the touch does not work …
Touch is working for me. Everything is working as expected. So it’s something your end.
The same works fine in SDL 2.0.8, but let’s go back to the coordinates …
I will insist that the SDL_HasIntersection function is not working properly. Window is different, there the width is given in pixels. In real geometry, we work with points and distance measures. A point has a size of 0 and a pixel of 1. A pixel is a square, it does not exactly represent a point. The square with the coordinates (0,0,10,10) has a width of 10, not 11, although the pixels are 11 if we draw it on a computer.
It’s inclusive of 0, though. Like how an array of 10 elements has indexes 0-9.
The other thing you have to understand is that with
SDL_Rect you aren’t giving two coordinates. You’re giving one coordinate, which is the top left origin (in your case (0,0)), and then the width and height.
SDL_FRect were created for SDL’s drawing functions, so it makes sense that their coordinates are in pixels.
So line 0-2 is 3
What are the coordinates of the line of length 0? What lengths -1? -2?
What is the width in pixels of a circle with a radius of 3? …2 …1 …0?
A line that starts and ends at the same point gets drawn as a single pixel IIRC, since SDL docs state that both end points get drawn.
In terms of 2D computer graphics, there aren’t really any lines of negative length.
I’m not asking for lines at the same point, just an object of length 0.
How is there no negative? I don’t see any contraindications … It gives a negative coordinate or a negative rectangle width, no error comes out.
A line with a start and end at the same point has 0 length.
I didn’t say SDL can’t handle lines with negative coordinates or anything. I just meant that, in terms of 2D graphics, there isn’t really such thing as a line with negative length (negative coordinates != negative length).