I had this problem a long time ago and recently I got some clues on it but still not very clear.
I basically render a texture to a existing figure using depth-testing. The function works fine under nvdia graphics card, but not on intel graphics card (sometimes the picture not stable, some times just junks).
First I think this might be the card problem. Recently I found if I changed the display mode in choosepixelformat,it works also great on the intel card.
I tried also the mode chosen by the getpixelformat function, and guess it might be due to the depth precision problem, I tried some techniques recommended on opengl FAQ, but no success. I tried several RGBA display modes, and they are (only modes with double buffers are used and they are 2,4,6,9,10, 13,14):
Draw Pixel Color Depth Stencil Double Stereo Aux
Index To Type Bits R G B A Bits Bits Buffer Buffer Buffers
======================================================================
2 win rgba 32 8 8 8 8 . . yes . .
4 win rgba 32 8 8 8 8 16 . yes . .
6 win rgba 32 8 8 8 8 24 8 yes . .
9 win rgba 32 8 8 8 . 32 8 yes . .
10 win rgba 32 8 8 8 . 16 8 yes . .
13 win rgba 32 8 8 8 8 32 8 yes . .
14 win rgba 32 8 8 8 8 16 8 yes . .
The modes which display correctly are 2, 9, 10, 13, 14. The failed ones are 4, 6. The windows chooses mode 4.
Anyone can give me some hints?
Thanks for the comments and here I add the bad rendering & the good rendering picture on the same machine. One is mode 4 and one is mode 10:
sorry! The system does not allow me to paste the image here
The bad one pasted here is just one of them, some may show other strange pictures.
Partial code: OpenGL initialization
m_pDC = new CClientDC(this);
//m_pDC = new CPaintDC(this);
m_hDC=m_pDC->GetSafeHdc();
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
16, // 16-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int m_PixelFormat;
//we may need to rewrite this function since it does not need the alpha bits
m_PixelFormat = ::ChoosePixelFormat(m_hDC, &pfd);
::SetPixelFormat(m_hDC, m_PixelFormat, &pfd);
//::SetPixelFormat(m_hDC, 10, &pfd);
//
m_hRC = ::wglCreateContext( m_hDC );
wglMakeCurrent( m_hDC, m_hRC );
wglMakeCurrent(NULL,NULL);
return TRUE;
Rendering is in the WM_PAINT message function: ::glEnable( GL_DEPTH_TEST ); ::glPolygonMode( GL_FRONT_AND_BACK,GL_FILL);
::glViewport( 0, 0, rcClient.Width() , rcClient.Height() );
....
draw(...);
The draw function will be like this:
gluPerspective(90, width/height, 0.001, height/1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(cx,cy,cz,cx,cy,0,0,1,0);
then draw the map here...... glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
then draw the lines & other objects here...
all objects are all in 2D vertex format, no any 3D depth values.