PDA

View Full Version : Textures: glEnableClientState vs glEnable



ManuelBast
09-26-2008, 02:30 AM
Hi!
English is not my primary language, so please exuse me for poor sentences.

I need to disable textures to select the objects using colors pick technique.
Actual code organization is (pseudo code*):

----------------------------
on init:
glEnable(GL_TEXTURE_2D);

for each object to draw:
...
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, uvcoords);
glDrawArrays(GL_TRIANGLES,0,ntriangles);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
...

when read color:
glDisable(GL_TEXTURE_2D);
...
glReadPixels(x, viewport[3] - y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, color_picked );
...
glEnable(GL_TEXTURE_2D);
-----------------------------




**QUESTION 1**
Anyway, with the sequence above I've notice of some strange artifact under Ubuntu.
The artifacts are fixed using, in read color, glEnableClientState/glDisableClientState
instead glEnable/glDisable:

-----------------------------
when read color:
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
...
glReadPixels(x, viewport[3] - y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, color_picked );
...
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-----------------------------

It's a correct usage?




**QUESTION 2**
Because the experiment above, I have thought that glEnable(GL_TEXTURE_2D) and
glEnableClientState(GL_TEXTURE_COORD_ARRAY) was redundant, so I've tried to use only
the second, but it don't work. I need at least a glEnable(GL_TEXTURE_2D) in init function.
So I just want know more about this aspect.



**QUESTION 3**
It's needed to call the glEnableClientState/glDisableClientState for each
object to draw? I've tried to enable all just one time, in init function, and
disable all only when exit from the sw. It seem to work, but I don't know if it's
formally correct. Can you help me?


Thanks,

Manuel

Full code: http://makehuman.svn.sourceforge.net/viewvc/makehuman/trunk/mh_phoenix/src/glmodule.c?view=markup

trinitrotoluene
09-26-2008, 08:20 AM
1) Use both glDisableClientState(GL_TEXTURE_COORD_ARRAY) and glDisable(GL_TEXTURE_2D) when you are in read color mode.



2)
glEnable(GL_TEXTURE_2D) and glEnableClientState(GL_TEXTURE_COORD_ARRAY)
enable 2 different things. When you do not use shaders, the first enable the use of texturing when rendering. The second tell OpenGL that you will use a texture array and the data for that texture array is specified by glTexCoordPointer.


3) No you do not need to call for each object glEnableClientState/glDisableClientState if they all use the same type of arrays.

skynet
09-26-2008, 09:11 AM
1) I'm 99,999% sure, that neither glDisableClientState(GL_TEXTURE_COORD_ARRAY) nor glDisable(GL_TEXTURE_2D) have anything to do with glReadPixels().

pjcozzi
09-26-2008, 09:15 AM
3) No you do not need to call for each object glEnableClientState/glDisableClientState if they all use the same type of arrays.

Furthermore, I'd suggest not to redundently enable or disable these for performance reasons. When rendering 1,000s of low triangle count objects with simple fixed function pipeline, I received up to a 40% boost in frame rate by removing the redundant glEnableClientState calls.

ManuelBast
09-27-2008, 01:46 AM
@trinitrotoluene:

Thanks. But unfortunately using both glDisableClientState(GL_TEXTURE_COORD_ARRAY) and glDisable(GL_TEXTURE_2D) don't fix the problem, while using only glDisableClientState(GL_TEXTURE_COORD_ARRAY) fix it.

The artifacts are very strange and apparently random. I've captures some shots for you:

http://www.makehuman.org/tmp/Screenshot.png
http://www.makehuman.org/tmp/Screenshot-1.png
http://www.makehuman.org/tmp/Screenshot-2.png

Note the click don't alter the geometry, just disable/enable textures, so I can't understand why the "explosions" of polygons...

Any suggestions?

@pjcozzi : thanks

@skynet: I know glReadPixels() is not related to the client state. I have added it just to show the reason I need to enable and disable textures (to read only the verts colors).

Again, thanks to all.

Manuel