blending : replace color

Hi,

Well I use display lists in my app to draw some lines, circles, … and for each display list I gived some colors to draw the primitives :

gl.glNewList(index, GL_COMPILE);
gl.glColor3fv(color_vector_1);
gl.glBegin(GL_LINES);
gl.glVertex2d(x, y);
gl.glVertex2d(xp, yp);
gl.glEnd();

gl.glColor3fv(color_vector_2);
gl.glBegin(GL_LINES);
gl.glVertex2d(x2, y2);
gl.glVertex2d(xp2, yp2);
gl.glEnd();

gl.glEndList();

Well at runtime, in some cases I’d like to change all colors of my object by one other

I think I should use some blending function but after several tests I did not found how to do :

gl.glBlendFunc(?, ?);
gl.glColor3fv(blue_vector);
gl.glEnable(GL_BLEND);

// draw the object in blue only
gl.glCallList(index);

gl.glDisable(GL_BLEND);

Someone can help me ?
Thx

It’s easier to give the color out of the displaylist all time…
Why is this advenched question???

Originally posted by Csiki:
It’s easier to give the color out of the displaylist all time…
Why is this advenched question???

Well I have lots of display lists (>50) and it is easier and faster to manipulate them giving colors in the declaration (I use only the index)

Remove the glColor3fv call from the display list. Specify colors outside.

You don’t need blending at all, nor will it help you if you keep your display list compilation as it is.

Originally posted by soda:
Well I have lots of display lists (>50) and it is easier and faster to manipulate them giving colors in the declaration (I use only the index)

The glColor is not an expensive operation. Blending is expensive.
You loose more than gain from taking the glColor in the displaylist. You don’t need blending at all.

Originally posted by Csiki:
[b] [quote]Originally posted by soda:
Well I have lots of display lists (>50) and it is easier and faster to manipulate them giving colors in the declaration (I use only the index)

The glColor is not an expensive operation. Blending is expensive.
You loose more than gain from taking the glColor in the displaylist. You don’t need blending at all.

[/b][/QUOTE]

My problem is similar to this post : http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/008630.html

So I have some display lists looking like that :

gl.glNewList(index_list_12, GL_COMPILE);
gl.glColor3fv(GL_GREEN);
gl.glCallList(subListIndex1);
gl.glColor3fv(GL_WHITE);
gl.glCallList(_subListIndex2);
gl.glCallList(_subListIndex3);
gl.glEndList();

Well if I put colors outside the main display list referenced by index_list_12, I’ll have to call each sublist in my draw method

So as I have lots objects, I’ll loose the benefit of calling one DL for each object using its index !

So an other solution is to duplicate my DL to have my objects drawn with only one color, …, but I’ll do that only if I found anything else…

Originally posted by soda:
Well if I put colors outside the main display list referenced by index_list_12, I’ll have to call each sublist in my draw method
Correct. What’s wrong with that?

So as I have lots objects, I’ll loose the benefit of calling one DL for each object using its index !
What benefit? If you’re concerned about performance, let me tell you, it really doesn’t matter at all.

At least give it a try. That way you can see for yourself.

DLs are for purely static stuff, that’s inherent to their design. They’re simply not the right tool if you want control/flexibility.

You can still call hundreds of display lists with one glCallLists.
If you really want to, you could build display lists with the single color call and put all IDs in an array send it to glCallLists, which is faster than hundreds of glCallList calls.
It’s probably not different to your hierarchy of display lists.
To change the color, you only need to exchange the indices of the color display lists. But you’re wasting a lot of memory instead of calling glColor in immediate mode.

BTW, the original display list can be optimized by leaving away the glEnd-glBegin between the two lines, hey, it’s GL_LINES after all.