# Graphics::drawHorizontalLine() broken on GIT head?

**URL:** <https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518>\
**Category:** General JUCE discussion\
**Created:** [November 15, 2009, 11:04am UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518 "2009-11-15T11:04:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [November 15, 2009, 11:04am UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/1 "2009-11-15T11:04:40Z")

</div>

Hello,

Using the current GIT head (after the iPhone update) drawHorizontalLine() seems to draw in the wrong place.

I have a scope that looks like this (using the GIT from 2009-09-25 1700hrs):

![](http://www.cems.uwe.ac.uk/~mgrobins/scope_juce_git20090925_1700.png)

But with the GIT head the faint lines (drawn with drawHorizontalLine()) are in the wrong position:

![](http://www.cems.uwe.ac.uk/~mgrobins/scope_juce_git20091115_1020%5Bmostrecent%5D.png)

The waveform is a bit fuzzier too, which is drawn using multiple calls to drawVerticalLine at each horizontal pixel position (not sure if this is related to other Graphics changes but not a major issue like this one). The text is brighter too, look perhaps like everything is drawn twice or perhaps the transparency is working differently.

This test illustrates the drawHorizontalLine problem:

```auto
class TestDrawHorizontalLine : public Component      
{
public:
	TestDrawHorizontalLine () { }
	~TestDrawHorizontalLine () { }
		
	void paint (Graphics& g) {
		g.fillAll(Colours::black);
		g.setColour(Colours::white);
		int height = getHeight();
		int width = getWidth();
		g.drawHorizontalLine(height/2, 0, width);
	}	
};

class TestDrawLine : public Component      
{
public:
	TestDrawLine () { }
	~TestDrawLine () { }
	
	void paint (Graphics& g) {
		g.fillAll(Colours::black);
		g.setColour(Colours::white);
		int height = getHeight();
		int width = getWidth();
		g.drawLine(0, height/2, width, height/2);
	}
};

class MainComponent : public Component      
{
private:
	TestDrawHorizontalLine *test1;
	TestDrawLine *test2;
	
public:
	MainComponent () {
		addAndMakeVisible(test1 = new TestDrawHorizontalLine());
		addAndMakeVisible(test2 = new TestDrawLine());
	}
	
	~MainComponent () {
		deleteAllChildren();
	}
	
	void resized () {
		test1->setBounds(20, 20, 200, 200);
		test2->setBounds(240, 20, 200, 200);
	}
};
```

Both components should look about the same but the first one doesn’t look right. The vertical psoition of the line seems to be dependent on the parent component size.

---

<div class="post-metadata">

**Author:** ![jsolo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jsolo/32/30_2.png) [@jsolo](https://forum.juce.com/u/jsolo)\
**Post date:** [November 15, 2009, 5:30pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/2 "2009-11-15T17:30:00Z")

</div>

Hey Martin

I think Jules is on this one…

Last two posts here.  
[http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=4663](http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=4663)

I just replaced all my drawHorizontalLine stuff with fillRect.  
HTH

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 15, 2009, 8:44pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/3 "2009-11-15T20:44:39Z")

</div>

The fonts are drawn directly by CoreGraphics now, so the gamma is a bit different.

I’m a little surprised that the vertical lines aren’t anti-aliasing as I’d expect them to - I’ll take a look at that for you.

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [November 15, 2009, 9:46pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/4 "2009-11-15T21:46:03Z")

</div>

Ah thanks. Sorry about the drawHorizontalLine stuff, I admit I looked at the recent topics but didn’t do a search…

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [November 17, 2009, 12:46am UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/5 "2009-11-17T00:46:55Z")

</div>

Regarding the non-antialising - I tried using drawLine() instead with the same results. But turning off USE\_COREGRAPHICS\_RENDERING does fix it. I tried explicitly turning on anti aliasing for the context on each call and that had no affect. Perhaps the parent has AA disabled? But then again the text is antialiased ok…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 17, 2009, 9:09am UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/6 "2009-11-17T09:09:41Z")

</div>

I need to dig around a bit to see what’s going on with those vertical lines, it’s very odd - I’ve used the same CoreGraphics rectangle method to draw vertical lines with no problem, so not sure why it’s coming out like that for you.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 19, 2009, 1:43pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/7 "2009-11-19T13:43:44Z")

</div>

Hi Martin - I did some tests with drawVerticalLine, but it all seems to be working perfectly - I don’t understand why you’d be seeing the aliasing. You weren’t drawing the vertical lines with drawLine, were you?

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [November 21, 2009, 7:46am UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/8 "2009-11-21T07:46:22Z")

</div>

sorry this probably should move to the Mac forum but since we started it here…

ok.

- fresh clone of the juce git
- build juce debug/release libs (BTW need to remove the 10.3 setting from the release target as 10.3 now longer supported, I also change the arch in the debug build to native arch only)
- build an app with the following component:

[code]class MainComponent : public Component  
{  
public:  
MainComponent () { }  
~MainComponent () { }

```
void paint(Graphics &g)
{
	int start = 10;
	int end = 50;
	int fall = 5;
	float step = float(fall) / (end-start);
	float top = 10;
	float length = 20.25;
	
	for(int i = start; i < end; i++, top += step)
	{
		g.drawVerticalLine(i, top, top+length);
	}
}

```

};[/code]

Produces this:  
 ![](http://www.cems.uwe.ac.uk/~mgrobins/juce-vertlines.png)

I thought it MIGHT be 10.4/10.5 sdks - I’ve tried setting everything to 10.5 (project, base, deployment) - same result.

I’m on an intel macbook, 10.5.8, Xcode 3.1.4.

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [November 21, 2009, 7:50am UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/9 "2009-11-21T07:50:24Z")

</div>

BTW reverting back to svn r780 (which I have archved):  
 ![](http://www.cems.uwe.ac.uk/~mgrobins/juce-r780-vertlines.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 21, 2009, 9:11am UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/10 "2009-11-21T09:11:26Z")

</div>

That’s bizarre - I tried almost exactly the same thing, but got a perfect result.

I wonder if it’s some setting on your mac that’s different - perhaps somehow CoreGraphics has anti-aliasing turned off by default…?

If so, then explicitly turning it on would probably fix things:

` CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
        : context (context_),
          flipHeight (flipHeight_)
    {
        CGContextRetain (context);
        CGContextSetShouldSmoothFonts (context, true);
        CGContextSetShouldAntialias (context, true);
`

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [November 21, 2009, 1:45pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/11 "2009-11-21T13:45:00Z")

</div>

Grrrr… I was hopeful on that one but no… still the same.

BTW I did a clean build (not falling into the juce\_NativeIncludes.mm not being touched after changing one of its included files… that got me a couple of times before!) both Juce lib and the app.

Very weird. I’ll keep thinking too.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 21, 2009, 3:39pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/12 "2009-11-21T15:39:40Z")

</div>

Well, all that I can think is that maybe it’s something that’s being done by the graphics card, and some cards don’t anti-alias that particular type of rectangle… If you use fillRect instead (the float version), does that get also get snapped to the nearest pixel?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 21, 2009, 3:40pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/13 "2009-11-21T15:40:29Z")

</div>

(actually, ignore that last question, fillRect uses paths internally so isn’t relevant)

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [November 21, 2009, 10:15pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/14 "2009-11-21T22:15:08Z")

</div>

all these in that inner loop from a few posts back do the same:

`g.drawVerticalLine(i, top, top+length);
g.drawLine(float(i), top, float(i), top+length);
g.fillRect(float(i), top, 1.f, length);`

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 22, 2009, 10:21am UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/15 "2009-11-22T10:21:56Z")

</div>

Weird. Why would things not be anti-aliased for you… I’ll try restarting my mac with the other graphics card enabled, in case that makes a difference…

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [January 16, 2010, 1:13pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/16 "2010-01-16T13:13:11Z")

</div>

Hello,

Any more throughts on this (just tried the tip). I’m still having to set USE\_COREGRAPHICS\_RENDERING to 0 to get antialiasing. Anyone else got this problem, again I’m on 10.5.8?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 16, 2010, 1:31pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/17 "2010-01-16T13:31:02Z")

</div>

No idea at all, unless it’s a 10.5 thing - I don’t have a 10.5 installation any more to try. (Seems unlikely though… CoreGraphics has always been anti-aliased)

What kind of mac have you got?

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [January 16, 2010, 2:02pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/18 "2010-01-16T14:02:18Z")

</div>

It’s a MacBook Pro 2.4GHz

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 16, 2010, 2:20pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/19 "2010-01-16T14:20:22Z")

</div>

Same as mine. Well, I’ve no idea!

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [January 16, 2010, 3:30pm UTC](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518/20 "2010-01-16T15:30:16Z")

</div>

I suppose it could be my work’s slightly non-standard install of Leopard. I’ve been reading the GeForce 8600M GT can be a bit fussy. Though I’m assuming it’s not the fatal problem for which Apple have extended the warranty where these chips are installed (mine is in the potentially promblematic batch I think). I’d expect other problems too.

[Next page](https://forum.juce.com/t/graphics-drawhorizontalline-broken-on-git-head/4518.md?page=2)
