这个算opengl的bug还是我的程序的问题?
用vc2008新建一个MFC的单文档程序,
在view的OnDraw函数中写入如下代码:
static bool first_draw = true;
if(first_draw)
{
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
32, // 32-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 iPixelFormat;
iPixelFormat = ChoosePixelFormat(*pDC, &pfd);
SetPixelFormat(*pDC, iPixelFormat, &pfd);
hglrc=wglCreateContext(*pDC);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
first_draw=false;
}
GetClientRect(&wholerect);
wglMakeCurrent (*pDC, hglrc);
glClear(GL_COLOR_BUFFER_BIT);
int m=221;
int n=900;
unsigned char * img=new unsigned char[m*n];
for(int i=0;i<m*n;++i)
{
img[i]=100;
}
glRasterPos2f(-1,-1);
glPixelZoom((GLfloat)(wholerect.Width())/(GLfloat)(m),
(GLfloat)(wholerect.Height())/(GLfloat)(n));
glDrawPixels(m,n,GL_LUMINANCE,GL_UNSIGNED_BYTE,img);
glFlush();
SwapBuffers(*pDC);
delete [] img;
这样程序运行后整个窗口应该都是灰色的,但实际上最上面的一条(宽度不定)是乱的。
如果把m的值改为220,就没有问题了。当m为不同的值的时候,有可能会出现这种状况,也
可能没有异常。
我在不同的电脑上都试过了,都是这样。包括nvidia的显卡和intel的显卡。
会是哪里出了问题啊?