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 :)