[Plib-users] Applying the same texture twice
Brought to you by:
sjbaker
From: <jo...@lu...> - 2005-07-12 02:33:09
|
Hi all, first of all a thank you for probiding and maintaining plib! I got a minor problem with textures and ssg. I am drawing icons in a loop, and it can sometimes happen that the same icon (i.e. texture) has to be drawn twice: for(i ...) { //(1) icon(i) -> apply (); //icon(i) is an ssgSimpleState glBegin ( GL_QUADS ) ; glColor4f ( 1, 1, 1, 1 ) ; glTexCoord2f ( 0, 0 ) ; glVertex2i ( x , y ) ; glTexCoord2f ( 1, 0 ) ; glVertex2i ( x+55, y ) ; glTexCoord2f ( 1, 1 ) ; glVertex2i ( x+55, y+55 ) ; glTexCoord2f ( 0, 1 ) ; glVertex2i ( x , y+55 ) ; glEnd () ; } If it happens that icon(i)==icon(i+1), the second icon does not get displayed. This seems to be caused by the lazy evaluation in apply(), since it does not bind the texture the second time. It figures out that the texture wasn't changed, and does not to the glBindTExture call again. I don't know enough about OpenGL to know if this is correct, but for now I assume it is. Since I assume that I am not the only person having this experienced, and I am not much of an OpenGL wizard: what is the proper solution to handle this? I can work around the problem by either: 1) call icon->force() at (1), since this will bind the texture again (even if it's not changed). To optimise this further: I can compare icon(i) with the previous icon and only do this (probably expensive) force() call if the same icon is drawn twice (which is really an exception) 2) I can manually bind the texture at (1) 3) I can probably reset the current texture to 0 before calling apply() 4) ??? Any comments and suggestions are welcome! Thanks a lot! Joerg |