memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.2k stars 779 forks source link

rendering not working on my Ubuntu 13.10/Linux system #3

Closed andrewcorrigan closed 10 years ago

andrewcorrigan commented 10 years ago

While I have compiled and ran nanovg successfully on my mac, I was recently trying to run the example code on my Ubuntu 13.10 laptop, which uses either an Intel or NVIDIA GPU (proprietary, binary driver) that I can select in the BIOS.

Running with either GPU, the example code doesn't render correctly, and only text appears, rendered_incorrectly

Not being familiar with the underlying rendering technique, there wasn't much I could do to fix it, but I tried to narrow down the issue slightly, by modifying the shader alpha component calculation from "color.w = strokeAlpha * scissor;", to just "color.w = scissor;", in which case the rest of the scene appears, but the blending appears off:

hacked_shader

memononen commented 10 years ago

Hi, I have not test the shader on many computers yet, so some compatibility issues can be there.

Based on the images, looks like the sdroundrect() does not behave correctly on your set. Can you try to add: "precision highp float;\n", after the #version line in both of the shaders?

--mikko

andrewcorrigan commented 10 years ago

Doesn't help. It looks the same as the original image.

andrewcorrigan commented 10 years ago

FWIW, I think that when I ran on the Mac, it was also an NVIDIA GPU (650M)

memononen commented 10 years ago

My Mac has Intel HD4000, and I always thought they were the lowest common nominator :) What if you truncate the shader main() just to:

"void main(void) {\n" " // Stroke - from [0..1] to clipped pyramid, where the slope is 1px.\n" " float strokeAlpha = min(1.0, (1.0-abs(alpha.x_2.0-1.0))_strokeMult) * alpha.y;\n" 1.0);\n" " vec4 color = innerCol;\n" " // Combine alpha\n" " color.w *= strokeAlpha;\n" " gl_FragColor = color;\n" "}\n";

If that works, you won't get clipping nor gradients, but it should confirm that the sdroundrect() is the culprit.

andrewcorrigan commented 10 years ago

I ran that (after deleting the stray line 1.0);\n"), but it's still the same thing as the original image.

andrewcorrigan commented 10 years ago

Here's another piece of information, if I comment out both calls to glBlendFunc in example.c, everything appears (but obviously rendered incorrectly): blendfunc

memononen commented 10 years ago

Blending should not affect the shader. Does this shadertoy work for you? https://www.shadertoy.com/view/MsS3zz

andrewcorrigan commented 10 years ago

I think so, it looks like: wunderbutton

memononen commented 10 years ago

ok, so oddly enough the same code works in one place but in another :(

Let's see if the inputs are ok. How does this shader look like:

"void main(void) {\n" " gl_FragColor = vec4(alpha.x,alpha.x,alpha.x,1.0);\n" "}\n";

andrewcorrigan commented 10 years ago

I tried that out, and was curious, so I also tried out alpha.y, and then strokeMult. strokeMult was zero, even though the corresponding call to glUniform1f was passing in a value of something like 1.0. What I found is that none of the uniform variables are getting bound since every single call to glGetUniformLocation fails (returns -1, which is not reported by glGetError, so I added additional error checks). I should be to fix the issue of uniform variables not getting bound, will get back to you soon.

andrewcorrigan commented 10 years ago

glGetUniformLocation wasn't the problem -- glUniform1f was simply not working. Apparently this issue is common when glUniform1f isn't dynamically loaded at run-time [1]. A workaround is to use GLEW, which loads the function at run-time. I've added that to my clone of your repository, and will issue a pull request in case you want to merge this workaround.

Thanks for all your help. I'm looking forward to really getting started using nanovg.

[1] http://encelo.netsons.org/2008/03/17/gluniform1f-is-working/

memononen commented 10 years ago

Thank you for taking the time to look into this! That would have been quite tricky to debug remotely :)