如何释放OPENGL的后台内存
我使用双缓冲,内存只吃不吐,向专家请教,给分
配置代码如下:
hrenderDC=::GetDC(this->GetSafeHwnd()); //获取设备DC
//必须先设置设备兼容的像素格式,再创建设备兼容的RC,以便绘图
//设置设备兼容的像素格式
//先 ChoosePixelFormat 再 SetPixelFormat
PIXELFORMATDESCRIPTOR pixelDesc;
pixelDesc.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pixelDesc.nVersion = 1;
pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER |
PFD_TYPE_RGBA;
pixelDesc.iPixelType = PFD_TYPE_RGBA;
pixelDesc.cColorBits = 32;
pixelDesc.cRedBits = 0;
pixelDesc.cRedShift = 0;
pixelDesc.cGreenBits = 0;
pixelDesc.cGreenShift = 0;
pixelDesc.cBlueBits = 0;
pixelDesc.cBlueShift = 0;
pixelDesc.cAlphaBits = 0;
pixelDesc.cAlphaShift = 0;
pixelDesc.cAccumBits = 0;
pixelDesc.cAccumRedBits = 0;
pixelDesc.cAccumGreenBits = 0;
pixelDesc.cAccumBlueBits = 0;
pixelDesc.cAccumAlphaBits = 0;
pixelDesc.cDepthBits = 0;
pixelDesc.cStencilBits = 1;
pixelDesc.cAuxBuffers = 0;
pixelDesc.iLayerType = PFD_MAIN_PLANE;
pixelDesc.bReserved = 0;
pixelDesc.dwLayerMask = 0;
pixelDesc.dwVisibleMask = 0;
pixelDesc.dwDamageMask = 0;
//创建设备兼容的像素格式
PixelFormat = ChoosePixelFormat(hrenderDC,&pixelDesc);
if(PixelFormat==0) // Choose default
{ //创建失败,选择默认
PixelFormat = 1;
//获取与设备相关的第一像素格式值
if(DescribePixelFormat(hrenderDC,PixelFormat,
sizeof(PIXELFORMATDESCRIPTOR),&pixelDesc)==0)
{
return ;
}
}
//设置与设备相关的像素格式值
if(SetPixelFormat(hrenderDC,PixelFormat,&pixelDesc)==FALSE)
{
return ;
}
//创建与设备HDC相适应的 OPENGL RC
hrenderRC = wglCreateContext(hrenderDC);
if(hrenderRC==NULL)
return ;
//使指定 OPENGL RC 为线程的当前RC
if(wglMakeCurrent(hrenderDC,hrenderRC)==FALSE)
return ;
//一些绘图前的配置
glEnable(GL_TEXTURE_2D); //启动OPENGL,2D纹理
//glShadeModel(GL_SMOOTH); //选择光滑阴影
GetClientRect(&m_ViewPortRect);
glViewport(0,0,m_ViewPortRect.right,m_ViewPortRect.bottom);
glMatrixMode(GL_PROJECTION); //设置矩阵模式为 PROJECTION MATRIX STACK
glLoadIdentity(); //使用标识矩阵替换当前矩阵
gluPerspective(45,1,0.1,100.0); //创建视角矩阵
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.44f, 0.5f, 0.41f, 1.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
绘制代码如下,具体画什么不用在意:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //使用预设颜色值
glLoadIdentity();
glTranslatef(0.0f,0.0f,-4.0f); //转换矩阵 Move Left 1.5 Units And Into The Screen 6.0
glRotated(m_yRotate, 1.0, 0.0, 0.0); //旋转坐标轴,每次稍微旋转
bool b=1;
int cubecolor=1;
double pi=3.1415926;
double cosine=0;
double sine=0;
double sidelength=0.05;
double radius=1;
LONGLONG i,j;
i=j=0;
for(radius=1,j=0;radius>0.5;radius-=0.05,j++,sidelength-=0.002)
{
for(i=0;i<100 && j*100+i<m_llNumBlocks;i++)
{
if(m_pInfoPerBlock)
{
m_pTempInfoPerBlock=m_pInfoPerBlock+j*100+i;
if(m_pTempInfoPerBlock->free==0)
glColor3f(0.69,0.96,0.9); //浅灰蓝
else
{
if(m_pTempInfoPerBlock->system==1)
glColor3f(1.0,0.75,0.796); //浅红
else
{
if(m_pTempInfoPerBlock->folder==1)
glColor3f(0.96,0.64,0.38); //黄
else
{
if(m_pTempInfoPerBlock->continuity >= m_pTempInfoPerBlock->fragment)
glColor3f(0.0,0.79,0.34); //绿
else
glColor3f(0.89,0.09,0.05); //红
}
}
}
}
else
glColor3f(0.69,0.96,0.9);
cosine=radius*cos(i*2*pi/100.0);
sine=radius*sin(i*2*pi/100.0);
glTranslated(sine,cosine,0);
gluSphere(gluNewQuadric(),sidelength,10,10);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-4.0f);
glRotated(m_yRotate, 1.0, 0.0, 0.0);
}
}
SwapBuffers(hrenderDC); //双缓冲,更改当前缓冲 就是这里,每次触发更新,内存都是只吃不吐
求教解决办法,立刻送分