• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: FxPlug / OpenGL Smooth Line Artifact
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FxPlug / OpenGL Smooth Line Artifact


  • Subject: Re: FxPlug / OpenGL Smooth Line Artifact
  • From: George King <email@hidden>
  • Date: Fri, 17 Oct 2008 17:56:03 -0700


On Oct 17, 2008, at 5:12 PM, Darrin Cardani wrote:


On Oct 17, 2008, at 5:10 PM, George King wrote:

I am seeing an odd artifact in my FxPlug OpenGL context when I draw a white line on a white background using GL_LINE_SMOOTH. In my test app that uses an NSOpenGL context (with no multisampling), i get pure white. However, when I run the same code in my FxPlug, I get dark artifacts where the line is blending. It looks as though the smooth line rasterizer is fading the color to black as the alpha fades to zero. As an example, take a white line with a small positive slope (almost horizontal). If I disable GL_BLEND, then I see two series of horizontal gradients in a staircase pattern, fading white to black and black to white. If I enable GL_BLEND, then the alpha for each gradient goes to zero as the color goes to black, leaving semi-transparent dark spots for every pixel of vertical rise.

I hope that makes some sense! Attached are a few screen shots which should make the problem apparent.

Note that this is not affected by glBlendColor, or the GL_TEXTURE_ENV_COLOR; changing either of those does not alter the black coloring. The problem occurs with and without texturing. Below is example code that can be pasted directly into the default FxFilter Xcode project. Insert it just before the glPopAttrib() call. You should also change *canRenderSoftware to NO to force OpenGL use.

I'm hoping that I'm just missing some gl state call, but I've been scouring the red book all day to no avail. Let me know if I should post this to the OpenGL list too; I thought I'd ask here first since it works in regular contexts.

Thanks,

George King


glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I think the above is your problem. Since colors in OpenGL are already premultiplied, I think you want to use:


glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

Otherwise, you're applying the source alpha twice to the line color. I've always found this really confusing, too, fwiw.

Darrin
--
Darrin Cardani
email@hidden





Hi Darrin,

That fixes my test case, but unfortunately it introduces a similar problem elsewhere. Now my lines are getting white 'feathers' instead of black. Below is a screenshot from my project; I'll have to work at a better test case. Remember that using (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) works fine in a fresh NSOpenGLContext.

I'm not sure what you mean about premultiplication. My limited understanding of that term is that when a function requires premultiplied color data, the color must multiply each color component by the alpha component ahead of time. So the quadruple for 100% red at 50% transparency is (.5, 0, 0, .5). When I want that color in OpenGL I call glColor4f(1, 0, 0, .5). Please let me know if I am misunderstanding the concept.

Thanks,

George

PNG image


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Pro-apps-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: FxPlug / OpenGL Smooth Line Artifact
      • From: Darrin Cardani <email@hidden>
References: 
 >Releasing after -getBitmap -- memory not recovered? (From: Matt Rhodes <email@hidden>)
 >Re: Releasing after -getBitmap -- memory not recovered? (From: Darrin Cardani <email@hidden>)
 >Re: Releasing after -getBitmap -- memory not recovered? (From: Matt Rhodes <email@hidden>)
 >Re: Releasing after -getBitmap -- memory not recovered? (From: Steve Christensen <email@hidden>)
 >FxPlug / OpenGL Smooth Line Artifact (From: George King <email@hidden>)
 >Re: FxPlug / OpenGL Smooth Line Artifact (From: Darrin Cardani <email@hidden>)

  • Prev by Date: Re: FxPlug / OpenGL Smooth Line Artifact
  • Next by Date: Timecode from audio track?
  • Previous by thread: Re: FxPlug / OpenGL Smooth Line Artifact
  • Next by thread: Re: FxPlug / OpenGL Smooth Line Artifact
  • Index(es):
    • Date
    • Thread