   line overwrite
  Hi. I am working on an MFC Dialog Based OpenGL Application. I use double buffering. My problem is: I have a gridline in grey and when I draw another line (which is yellow) on top of it, my new line does not completely cover the old one. I see some random grey points on yellow. My pixel format is as below. Does anyone know how I can fix this problem?BOOL CMyDlg::SetWindowPixelFormat(HDC hDC){PIXELFORMATDESCRIPTOR pfd;pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); // Size of this pfdpfd.nVersion = 1; // Version number : must be 1pfd.dwFlags = PFD_DRAW_TO_WINDOW | // Support windowPFD_SUPPORT_OPENGL | // Support OpenGLPFD_DOUBLEBUFFER | // Double bufferedPFD_STEREO_DONTCARE; // Support either monoscopic or stereoscopicpfd.iPixelType = PFD_TYPE_RGBA; // RGBA typepfd.cColorBits = 0; // Specifies the number of color bitplanes in each color bufferpfd.cRedBits = 0; // Specifies the number of red bitplanes in each RGBA color bufferpfd.cRedShift = 0; // Specifies the shift count for red bitplanes in each RGBA color bufferpfd.cGreenBits = 0; // Specifies the number of green bitplanes in each RGBA color bufferpfd.cGreenShift = 0; // Specifies the shift count for green bitplanes in each RGBA color bufferpfd.cBlueBits = 0; // Specifies the number of blue bitplanes in each RGBA color bufferpfd.cBlueShift = 0; // Specifies the shift count for blue bitplanes in each RGBA color bufferpfd.cAlphaBits = 0; // Specifies the number of alpha bitplanes in each RGBA color buffer. Alpha bitplanes are not supportedpfd.cAlphaShift = 0; // Specifies the shift count for alpha bitplanes in each RGBA color buffer. Alpha bitplanes are not supportedpfd.cAccumBits = 0; // Specifies the total number of bitplanes in the accumulation bufferpfd.cAccumRedBits = 0; // Specifies the number of red bitplanes in the accumulation bufferpfd.cAccumGreenBits = 0; // Specifies the number of green bitplanes in the accumulation bufferpfd.cAccumBlueBits = 0; // Specifies the number of blue bitplanes in the accumulation bufferpfd.cAccumAlphaBits = 0; // Specifies the number of alpha bitplanes in the accumulation bufferpfd.cDepthBits = 0; // Specifies the depth of the depth (z-axis) bufferpfd.cStencilBits = 0; // Specifies the depth of the stencil bufferpfd.cAuxBuffers = 0; // Specifies the number of auxiliary buffers. Auxiliary buffers are not supportedpfd.iLayerType = PFD_MAIN_PLANE; // Ignored. Earlier implementations of OpenGL used this member, but it is no longer usedpfd.bReserved = 0; // Specifies the number of overlay and underlay planespfd.dwLayerMask = 0; // Ignored. Earlier implementations of OpenGL used this member, but it is no longer usedpfd.dwVisibleMask = 0; // Specifies the transparent color or index of an underlay planepfd.dwDamageMask = 0; // Ignored. Earlier implementations of OpenGL used this member, but it is no longer usedint m_GLPixelIndex = ChoosePixelFormat(hDC, &pfd;// Attempts to match an appropriate pixel format supported by a device context to a given pixel format specificationif(m_GLPixelIndex == 0) // Choose default{m_GLPixelIndex = 1;if(DescribePixelFormat(hDC, m_GLPixelIndex, // Obtains information about the pixel format identified by iPixelFormat of the device associated with hdcsizeof(PIXELFORMATDESCRIPTOR), &pfd)==0)return FALSE;}if(!SetPixelFormat(hDC, m_GLPixelIndex, &pfd)) //Sets the pixel format of the specified device context to the format specified by the iPixelFormat indexreturn FALSE;return TRUE;}Note: I also tried many nonzero value combinations but I could not make it work. 
  Is this running in 16bit color?  could this be some dithering artifact?lonesock   Piranha are people too. ;quote:Original post by lonesock  Is this running in 16bit color?  could this be some dithering artifact?Sorry but I could not understand what you mean. Are you making fun of my code? Anyway, Program does not draw properly and I thought it might be due to pixelformat settings. ;  This would have nothing to do with your pixel format. It's most likely Z-fighting. Post the portions of your code where you set up your model-view and projection matrices, and where you actually draw the lines."Sneftel is correct, if rather vulgar." --Flarelocke   [edited by - sneftel on February 12, 2004 8:32:11 PM];  Screenshot? ;quote:Original post by Sneftel  This would have nothing to do with your pixel format. It''s most likely Z-fighting. Post the portions of your code where you set up your model-view and projection matrices, and where you actually draw the lines."Sneftel is correct, if rather vulgar." --Flarelocke   [edited by - sneftel on February 12, 2004 8:32:11 PM]Code is too long actually. My applyPerspective function is as below.applyPerspective(){GLintviewport[4];glGetIntegerv(GL_VIEWPORT, viewport);double H;H=sqrt(pow(TotalX,2.0)+pow(TotalY,2.0)+pow(TotalZ,2.0));gluPerspective(45.0f/m_ScaleZ, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]),1.20*H, 2.307*H);}My main drawing function isDrawScene(){glMatrixMode(GL_MODELVIEW);glLoadIdentity();glClearColor(0.0f, 0.0f, 0.0f, 0.0f);glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPushMatrix();   DrawGrids();   DrawYellowLines();glPopMatrix();    HWND hWnd = GetSafeHwnd();HDC hDC = ::GetDC(hWnd);glFinish();SwapBuffers(hDC);}I applyPerspective whenever zoom or size change occurs. So, any recommendations now. By the way how do I post images(screenshot) here? ;  sorry, I should have been more clear.on some cards, 16-bit color = 16-bit z-buffer.  If that is the case, and if the driver does some kind of dithering (increasing apparent bit-depth by sometimes adding 1 [kind of like rounding to the nearest integer, but using probability]) you can get z-fighting.  So sometimes the point will be considered "above" the previous pixel, and sometimes it won''t.you may want to disable the depth-buffer and see if that makes it work as expected.I wasn''t making fun of your code, sorry it seemed that way (though "blithering" _is_ a cool word [8^)lonesock Piranha are people too. ;  Is the problem that the yellow line is drawn in different pixels from the first line (and so leaving the grey showing still), or is it that some of the yellow pixels fail to overwrite the pixels of the first line?If the first, check you''re using the *exact* same values for the start and end points, and drawing them in the same manner, without tinkering with the GL state inbetween.If its the second, its probably z-fighting. Try turning off depth checks when drawing the second line. If that fixes it then consider using a depth offset when drawing the second line. ;  couple of tips, when posting code put [source.] and [/source.]  or [code.] [/code.] (without the dots in both cases) around the code (source for long blocks, code for a couple of lines)to post images just use the html &ltimg src="http://location.of.img/here.jpg &gt and try to use jpg images and dont make ''em huge and i''m with the crowd on this one, it does sound like z-fighting as based on that pfd you''ll probably get a 16bit color buffer with a 16bit z-buffer (or even no z-buffer) as you didnt request a format, you are just leting windows decide, try putting proper values in the pfd (if you zero the pfd you can avoid setting all the unused members, saving some typing time)you might want to look at NeHe''s website for a better example of setting up the pfd...  ;Forum FAQ