OpenGLComponent draws stuff blurry

Hey there,

i am new to juce and first want to say: wow, nice thingy, lots of useful stuff, well documented, consistent coding style and everything i looked into made sense!

But i’ve also got a annoying little problem i tried to takle all night long:

I have created an OpenGLComponent that is a child of a AudioProcessorEditor. In my dar-code i do nothing fancy, i just draw simple lines, horizontally and vertically. GL_LINE_SMOOTH is disabled and LineWidth is set to 1.0.
The Problem is, that the rendered image looks blurry, as if it where rendered to a texture and incorrectly mapped to the screen. the lines also flicker when i resize the Window.

i tried to call glViewPort in different locations of my code, but nothing changed. Then i googled and stubled across discussions about HiDPI and that the coordinates have to be transformed somehow. i tried that ( and learned to hate obj-c even more ) but the results suggested, that that the problem might be somewhere else.

maybe that is helpful:

search for blurry and look at the imaging.

did anyone encounter similar problems or does anyone have an idea how to fix that?

best regards

You’re headed the wrong way with that resolution independence stuff. It’s mostly disabled anyway.

If you post some code, people might look at it and be able to offer suggestions.

The OpenGLComponent will certainly draw properly on all platforms - you probably have some OpenGL errors.


//here's what i do
void Renderer::renderOpenGL()

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();							// Reset The Projection Matrix
	glOrtho(0, getWidth(), getHeight(), 0, -1, 1);

	glMatrixMode(GL_MODELVIEW);						// Select The Modelview Matrix
	glLoadIdentity();							// Reset The Modelview Matrix

	for (int x = 0; x < getWidth(); x += 2)
		glVertex2f( x, 0 );
		glVertex2f( x, getHeight() );

What would you expect does the output look like? I’d expect alternating white and black lines. But that’s not the case. The output image is 50% grey. I was surprised by that, because the same code in a different setup ( gl contexts created differently ) yielded the expected result.

But this here appears to explain that:

In the past i created my rendering-context via agl, and according to the thread above it was behaving incorrectly. Offsetting the drawing by .5f fixes the issue. And hopefully produces consistent results on different Hardware.

best regards

But seriously: this sucks!

Yeah, that’s not at all surprising, it’s how anti-aliasing works. TBH if you’re drawing 2d stuff, and especially if you’re drawing pixel-aligned lines, you’d probably be better of not using opengl at all, and just using the Graphics class.

I’d prefer to be able to disable antialiasing somehow.

According to to the thread, it works as intended, and your version that looked the way you wanted was an accident. OpenGL seems full of odd stuff like that, and there’s lots that doesn’t work the way you expect. Your current version should be consistent - it doesn’t rely on undefined behavior.

Huh? It’s computers. It’s not meant to be easy. Suck it up.


But in your example code you explicitly turn it on!

Uh? But where am i doing that, i thought via glDisable(GL_LINE_SMOOTH); i was explicitly turning if off?

Another thing: that can’t be it. it looks incredibly awful when i draw a line that is << almost >> horizontal or vertical. And offsetting does not help here. There must be a way to disable this behaviour. I mean this is definitively not my first OpenGL-Application. I must repeat, that i do feel, that i am not drawing “directly” to the screen and that there’s some kind of buffering in between (and i do not mean the double-buffering ^^ ) … Is multisampling somehow enabled by default?

(Sorry, I misread it and thought you were enabling it).

But seriously, if you want to draw some non-antialised horizontal lines, don’t use openGL or any kind of primitive that’s designed for drawing arbitrarily angled or scaled lines. Use Graphics::fillRect() with some integer coords.

The solution, plain and simple: glDisable(GL_MULTISAMPLE);



Wow! That’s great. I’ve been looking for that solution for several hours all over the Internet. Glad I decided to check here! Works perfectly. I was wondering why all my GL_LINES were partially grey instead of solid white like I asked.