openglblendingdisplaylist

Can I set a custom function that will alter the color of a display list in OpenGL?


I have geometry stored in a display list, but I'd like to be able to draw the same display list with different "tints" on them. For example, if I had a black and white skull in a display list, I'd like to set a red tint and draw a skull, then set a blue tint and draw the skull.

If I can get the RGBA values I know exactly how to transform them, but I'm not sure where I can intercept them. Currently the display lists do not contain textures, but they probably will in the future so it would be good if the answer works with or without textures.


Solution

  • Conceptually a display list is just a bunch of commands that are excuted when you glCallList. So whatever it contains it will just be as if you used those commands directly (but maybe more performant). So if your display list contains a bunch of geometry commands, how can you color them? Yes, you guessed it, using the usual glColor command right before calling the list:

    glColor(...);
    glCallList(...);
    

    When you want your objects to have a texture and still be colorable you can just use set texture environment to GL_MODULATE (I guess you're not using shaders, otherwise the whole question would be quite obsolete, anyway). If you want your objects lit, well change glColor to glMaterial, of course.

    But if you set the color inside the display list you don't have any chance to get it and change it. But I wouldn't advice you to use display lists, anyway. If you use them to store geometry and for reducing CPU-GPU copies and drawcall overhead, then why not use VBOs, which are exactly made for this (and don't suffer from such an indeterminate implementation).