Little difference between Bitmap and Texture
I all, I have a little difference between my bitmap and rendering texture on screen. If my bitmap is just one color like RGB(0.128.64) then on screen I got one color (great ;-) ) but it is RGB(0.127.63) What's happening ??? Thanks a lot for any help... // Create MipMapped Texture glDeleteTextures(1, &m_texture[0]); glGenTextures(1, &m_texture[0]); glBindTexture(GL_TEXTURE_2D, m_texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_simpleDib.m_sizeDIB.cx, m_simpleDib.m_sizeDIB.cy, GL_BGR_EXT, GL_UNSIGNED_BYTE, m_simpleDib.m_pBits); // Draw glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glEnable(GL_TEXTURE_2D); glDisable (GL_BLEND); glDisable(GL_ALPHA_TEST); glBindTexture(GL_TEXTURE_2D, m_bkObject.m_texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f( 1.0f, -1.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f( 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f, 1.0f); glEnd(); glPopMatrix(); glFlush();
A bitmap stores its colours in a BGR format but OpenGL wants it in RGB, hence the colour looks wrong. There is an extension to automatically sort this out for you but I forget its name. I find it much easier to just do a byte-swap after loading the bitmap.
Happy coding.
Happy coding.
--
Cheers,
Darren Clark
Cheers,
Darren Clark
Thanks for your answer eSCHEn but my bitmap is a Dib section with BI_RGB format. So bytes are already in the right ordrer.
In fact texture appears quite perfectly on screen exept a little difference of 1 for each RGB value...
May I have to play with these 2 functions ???
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
In fact texture appears quite perfectly on screen exept a little difference of 1 for each RGB value...
May I have to play with these 2 functions ???
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
A difference of 1/255 really means nothing.
When GL uploads the data to video card, conversions MAY occur. Since GL does most computations in floating-point arithmethic (well, the model, not most implementations) it's perfectly fine to have little differences.
GL is not meant to be pixel-perfect.
So, unless you see bad artifacts, you can guess GL is doing its job.
Think this little data loss as the price you pay for speed.
When GL uploads the data to video card, conversions MAY occur. Since GL does most computations in floating-point arithmethic (well, the model, not most implementations) it's perfectly fine to have little differences.
GL is not meant to be pixel-perfect.
So, unless you see bad artifacts, you can guess GL is doing its job.
Think this little data loss as the price you pay for speed.
Previously "Krohm"
Ooops, sorry Lilive, I wasn't paying attention there. That'll teach me to post full of codine with no sleep ;)
--
Cheers,
Darren Clark
Cheers,
Darren Clark
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement