内存资源不停地增加
Memory resource increase non stop
我是GLFW的新手,做了一个简单的纹理映射程序。问题是在运行程序时内存资源不停地增加,我可以在任务管理器中清楚地看到。
运行程序几分钟后,计算机的风扇加速,出现发热问题。如何解决此问题?
这是纹理加载功能的代码
GLuint LoadTexture(const char* TextureName)
{
GLuint Texture; //variable for texture
glGenTextures(1,&Texture); //allocate the memory for texture
glBindTexture(GL_TEXTURE_2D,Texture); //Binding the texture
if(glfwLoadTexture2D(TextureName, GLFW_BUILD_MIPMAPS_BIT)){
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
return Texture;
}else return -1;
}
这是绘制函数的代码
void display()
{
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); //clear background screen to black
//Clear information from last draw
glClear( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
glTranslatef(0.0f,0.0f,-35.0f); //Translate whole scene to -ve z-axis by -35 unit
GLuint text2D;
text2D = LoadTexture("cicb.tga"); //loading image for texture
glEnable(GL_TEXTURE_2D); //Enable texture
glBindTexture(GL_TEXTURE_2D,text2D);//Binding texture
glPushMatrix();
glBegin(GL_POLYGON); //Begin quadrilateral coordinates
glNormal3f(0.0f, 0.0f, 1.0f);//normal vector
glTexCoord2f(0.0f, 0.0f); //Texture co-ordinate origin or lower left corner
glVertex3f(-10.0f,-11.0f,5.0f);
glTexCoord2f(1.0f, 0.0f); //Texture co-ordinate lower right corner
glVertex3f(10.0f,-11.0f,5.0f);
glTexCoord2f(1.0f, 1.0f);//Texture co-ordinate top right corner
glVertex3f(10.0f,-1.0f,-15.0f);
glTexCoord2f(0.0f, 1.0f);//Texture co-ordinate top left corner
glVertex3f(-10.0f,-1.0f,-15.0f);
glEnd(); //End quadrilateral coordinates
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,text2D);
glPushMatrix();
glBegin(GL_POLYGON);
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);//Texture co-ordinate origin or lower left corner
glVertex3f(-10.0f,-1.0f,-15.0f);
glTexCoord2f(10.0f, 0.0f); //Texture co-ordinate for repeating image ten times form
//origin to lower right corner
glVertex3f(10.0f,-1.0f,-15.0f);
glTexCoord2f(10.0f, 10.0f);//repeat texture ten times form lower to top right corner.
glVertex3f(10.0f,15.0f,-15.0f);
glTexCoord2f(0.0f, 10.0f);//repeat texture ten time form top right to top left corner.
glVertex3f(-10.0f,15.0f,-15.0f);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D); //Disable the texture
glfwSwapBuffers();
}
如果有人想通过运行exe来查看问题,那么我可以提供下载链接。
每次调用display()
时,您似乎都在加载纹理。(基本上每帧一次)我想这就是在某个时候占用你所有记忆的原因。您只需要在显示功能之外执行此操作一次。
相关文章:
- 具有瞬态资源的RAII类
- 数组索引的值没有增加
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 为什么我的代码在输出中增加了93天
- 有效地使用std::unordered_map来插入或增加键的值
- 允许从 std::map 的密钥窃取资源?
- 参考资源文件VC++中的$(SolutionDir)
- 如何维护资源管理器项目视图中当前可见的项目列表
- 将 std::allocate_shared 与多态资源分配器一起使用
- C++ 动态数组每次添加时将大小增加 1 - 错误
- 使用RAII在给定次数的迭代后重新分配资源
- 资源管理设计模式
- 为什么要增加导致崩溃的指针
- 如何跨平台将二进制资源构建到程序中?
- SetDlgItemInt 不会更改嵌入资源的编辑框
- Klocwork Inside的资源泄漏
- 从存储为 Windows 资源 (c++) 的 png 中获取 png 文件数据
- C++链接时间资源"allocation"而不定义
- 增加传递地址的值
- 内存资源不停地增加