OpenGLComponent draws stuff blurry


#1

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:
http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/HiDPIOverview/HiDPIOverview.pdf

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


#2

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.

Bruce


#3
//here's what i do
void Renderer::renderOpenGL()
{
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	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

	glLineWidth(1.0f);
	glDisable(GL_LINE_SMOOTH);
	glColor4f(1,1,1,1);
	glBegin(GL_LINES);
	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
Ben

But seriously: this sucks!


#4

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.


#5

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


#6

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.

Bruce


#7

But in your example code you explicitly turn it on!


#8

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


#9

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?


#10

(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.


#11

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

:wink:

cheers


#12

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.