更新纹理 [英] update texture
问题描述
嗨:)
有一个函数可以生成纹理:void Render(char * Img);
在openGL的初始化中:
glutInit(&argc, argv); glutInitWindowSize(w, h); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("triunghi"); glutDisplayFunc(afis); glutIdleFunc(idle); glClearColor(0, 0, 0, 0); glEnable( GL_TEXTURE_2D ); texture=LoadTexture();
LoadTexture在哪里
glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, false ? GL_REPEAT : GL_CLAMP ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, false ? GL_REPEAT : GL_CLAMP
并在绘图功能中
glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, texture ); gluBuild2DMipmaps( GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, Img); glBegin(GL_QUADS); glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0); glTexCoord2d(1.0,0.0); glVertex2d(1.0,-1.0); glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0); glTexCoord2d(0.0,1.0); glVertex2d(-1.0,1.0); glEnd(); glutSwapBuffers();
空闲时,将更新Img中的数据,并调用glutPostRedisplay.
麻烦的是,仅显示第一个纹理,在下一帧更新的图像顶部仅显示10%,之后纹理是静态的.可以移动对象,但纹理相同.
即使分配了新的纹理编号并释放了旧的纹理编号,也会发生相同的情况.
Img已正确更新,因为它也已写入可以的文件中.
我做错了什么?
谢谢:)
对不起,问题出在缓冲区中,它没有正确更新...
>
Hi :)
There is function that generates a texture: void Render(char* Img);
At the init of openGL:
glutInit(&argc, argv); glutInitWindowSize(w, h); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("triunghi"); glutDisplayFunc(afis); glutIdleFunc(idle); glClearColor(0, 0, 0, 0); glEnable( GL_TEXTURE_2D ); texture=LoadTexture();
where LoadTexture is
glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, false ? GL_REPEAT : GL_CLAMP ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, false ? GL_REPEAT : GL_CLAMP
and in the drawing function
glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, texture ); gluBuild2DMipmaps( GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, Img); glBegin(GL_QUADS); glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0); glTexCoord2d(1.0,0.0); glVertex2d(1.0,-1.0); glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0); glTexCoord2d(0.0,1.0); glVertex2d(-1.0,1.0); glEnd(); glutSwapBuffers();
in idle, the data in Img is updated, and glutPostRedisplay is called.
The trouble is that only the first texture is displayed, at the next frame only 10% at the top of the image updated and after that the texture is static. The object can be moved, but the texture is the same.
The same thing happens even if a new texture number is assigned and the old one freed.
The Img is updated correctly, because it is also written to a file which is ok.
What am I doing wrong?
Thank you :)
Sorry, the problem was in the buffer, it didn''t update correctly...
这篇关于更新纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!