Hi everyone,
I have just approached the OpenGl world and I would have a question to ask you:
in my project I would like to add several times the contribution of a texture; using GL_ADD or GL_ADD_SIGNED I succeeded in the intent but I encountered a numeric precision problem…
I use GL_TEXTURE_2D textures configured as GL_RGBA32F but it seems that every subsequent increment necessarily entails a truncation of float precision to int.
I would like to know if there is a way to handle the entire GL_ADD phase in float precision and to demand the rounding to int only one time during the video-making phase.
//Texture Setup
//3x3 texture RGBA
float* pRGBA = new float[9 * 4];
// vector pRGBA filled with float value [0-1] R,G,B and Alpha to 1
//...
glBindTexture(GL_TEXTURE_2D, 0);
glGenTextures(1, &m_texture);
//...
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
3,
3,
0,
GL_RGBA, GL_FLOAT,
pRGBA);
//...
glBindTexture(GL_TEXTURE_2D, 0);
//Texture Draw (called multiple times)
float ValR,ValG,ValB; //color modulation
float X,Y; //Texture center position
//...
glBindTexture(GL_TEXTURE_2D, m_texture);
////////////modulate texure color//////////
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColor4f(ValR, ValG, ValB , 1);
////////////////////////////////////////////
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//ENABLE BLEND
glEnable(GL_BLEND);
//ENABLE TEXTURE 2D MANAGEMENT
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD_SIGNED);
// top left
glTexCoord2f(0, 0); glVertex3f(X-1.5, Y-1.5, 0);
// top right
glTexCoord2f(1, 0); glVertex3f(X+1.5, Y-1.5, 0);
// bottom right
glTexCoord2f(1, 1); glVertex3f(X+1.5, Y+1.5, 0);
// bottom left
glTexCoord2f(0, 1); glVertex3f(X-1.5, Y+1.5, 0);
glEnd();
glDisable(GL_TEXTURE_2D ); //Fine gestione Texture 2D
glDisable(GL_BLEND);
//Release Texture
glBindTexture(GL_TEXTURE_2D,0);
//..
Thanks in advance for any suggestion