NSOpenGLView and ScreenSaverView

Member
Posts: 148
Joined: 2003.03
Post: #1
I'm taking a swing at making an OpenGL-rendered screensaver for MacOS X. I've got just about everything working, except I can't get blending to work for some reason. What I want to is draw a quad with a mask texture (black gets trashed, white stays), then draw the color texture over top of it. It works fine in other applications I have written. Here is what I'm trying to do..

[sourcecode]
- (void)updateDisplay
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();

glColor4d(1.0,1.0,1.0,1.0);

glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

glBlendFunc(GL_DST_COLOR, GL_ZERO);

[mask_image use]; //equiv to glBindTexture(..)
glBegin(GL_QUADS);
glTexCoord2d(0.0,1.0);
glVertex3d(-0.512,0.512,0.0);
glTexCoord2d(1.0,1.0);
glVertex3d(0.512,0.512,0.0);
glTexCoord2d(1.0,0.0);
glVertex3d(0.512,-0.512,0.0);
glTexCoord2d(0.0,0.0);
glVertex3d(-0.512,-0.512,0.0);
glEnd();
[mask_image stopUse];

glBlendFunc(GL_ONE, GL_ONE);

[color_image use];
glBegin(GL_QUADS);
glTexCoord2d(0.0,1.0);
glVertex3d(-0.512,0.512,0.0);
glTexCoord2d(1.0,1.0);
glVertex3d(0.512,0.512,0.0);
glTexCoord2d(1.0,0.0);
glVertex3d(0.512,-0.512,0.0);
glTexCoord2d(0.0,0.0);
glVertex3d(-0.512,-0.512,0.0);
glEnd();
[color_image stopUse];

glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);

glPopMatrix();

glFlush();

}

[/sourcecode]

The result is a quad with the entire color_image texture on it, no blending, etc. I was wondering if NSOpenGLView acts differently when acting as a subview for a ScreenSaverView. At first, I though it was my pixel format, but it doesn't appear to be so...

Code:
NSOpenGLPixelFormatAttribute attribs[] ={
            NSOpenGLPFANoRecovery,
            NSOpenGLPFAAllRenderers,
            NSOpenGLPFAAccelerated,
            NSOpenGLPFAAlphaSize,
            16,
            NSOpenGLPFADepthSize, 8,
            0
        };

Can anybody offer any insight? Thanks.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Well, you won't be getting 16-bit destination alpha, I can tell you that... though I don't see why that would make a difference...

Might be worthwhile changing it to 8...
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #3
Thanks for pointing that out OSC.

Anyway, it turns out I had my mask colors inverted, so I fixed that, and it still doesn't work. To figure out what is going on, I commented out the color_image quad. What I see is what I should be seeing, a black shape representing the image mask. However, whenever I draw the color_image quad, it doesn't conform to the mask. Any ideas on what is going on?
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #4
:doh: Blink Silly me! I just realized I am using a white background for the color_image texture, and I'm assuming that the background has to be black (since it works now Grin). I never realized this before, I thought the method I am using (obtained for the NeHe tutorial) was the same as conventional masking routines (where the pixels in the mask image simply knock out the corresponding pixels in the color image). I guess I was mistaken. ZZZ
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Nothing showing up in NSOpenGLView [newb] binaryinsomnia 6 6,310 Nov 29, 2011 07:04 PM
Last Post: binaryinsomnia
  Cocoa controls on top of NSOpenGLView wadesworld 5 5,810 Apr 6, 2009 01:38 AM
Last Post: arekkusu
  Antialiasing and NSOpenGLView attributes Jar445 2 6,469 Jan 20, 2009 10:42 AM
Last Post: maximile
  Adding NSOpenGLView class in Xcode/Interface Builder 3.0 Graphic Ace 2 3,669 Dec 5, 2007 02:15 PM
Last Post: Blacktiger
  Double-Buffering with NSOpenGLView DesertPenguin 3 5,650 Aug 1, 2006 07:17 AM
Last Post: DesertPenguin