PDA

View Full Version : Problems with smoothed GL_POINTS


Twilight
2005.03.24, 05:10 AM
Hi,

when I use smoothed GL_POINTS with blending and draw them into the context, I get this:
http://www.pro-pixelmedia.de/rene/gl_points.gif

Some of the gl_points have black corners while others blended correctly.
I use the following code:


OpenGL Setup:

glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable( GL_POINT_SMOOTH );
glEnable( GL_DEPTH_TEST );
glDepthFunc(GL_LEQUAL);
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0,1.0,-1.0,1.0, 1.0, 10.0);
glTranslatef(0.0,0.0,-2.0);


Drawing Routine:

glClearColor( 0.0, 0.0, 0.0, 0.0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable (GL_DEPTH_TEST);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glPointSize( 16.0 );
glBegin( GL_POINTS );
float tempZ;
int i;
for(i=0;i<numOfStars;i++) {
tempZ = stars[i].posZ;
if(stars[i].posX > 1.0) stars[i].posX = -1.0;
stars[i].posX = stars[i].posX + 0.001f;

glColor3f (tempZ, tempZ, tempZ );
glVertex3f(stars[i].posX, stars[i].posY, tempZ);
}
glEnd( );
CGLFlushDrawable( contextObj );



What's wrong with this?

OneSadCookie
2005.03.24, 06:04 AM
looks like depth testing -- the transparent pixels of points close to the front are still written to the depth buffer, so points further back are obscured by them. If these need to be drawn in a particular order, you'll need to sort 'em back to front.

Twilight
2005.03.24, 06:38 AM
True, I don't z-order the points manually but OpenGL draws them in the right order, only the blending seems to make trouble then.
If I disable the depth mask then blending works fine but z-ordering becomes strange (upper part of the screen is ok but in the lower half z-order is scrambled o.o):

http://www.pro-pixelmedia.de/rene/gl_point_nomask.jpg
(The black lines are because of double buffering)

Do I really need to sort them manually? Hard to believe that OpenGL can't handle z-ordering simple points correctly. Maybe I made a mistake in the CGL-Context setup section? I used the following attributes:


CGLPixelFormatAttribute attribs[] = {
kCGLPFADoubleBuffer,
kCGLPFAFullScreen,
kCGLPFADisplayMask, displayMask,
kCGLPFADepthSize, 16,
NULL } ;

OneSadCookie
2005.03.24, 07:20 AM
z-ordering points works fine, but semitransparent objects of any kind must be drawn back to front, a) to get the blending right, and b) to avoid problems like this :)

Twilight
2005.03.24, 07:42 AM
Yep, works fine now! With z-sorting before I draw it....

Thanks for the info :)

arekkusu
2005.03.24, 01:24 PM
Blending is incompatible with z buffering.

Also, don't forget to run your app on a Radeon earlier than the 9600, you will be surprised.