I haven’t got access to another system to test it at the moment. Would find it difficult to test with C++ as well, since my knowledge of it isn’t great. Although I have done similar things before, I have never had any problem like this - but then I wouldn’t expect to since to, since I have found that it happens under very specific circumstances.
Although I can’t explain why it happens, I have worked out when it happens, and how it can be avoided. The deciding factor seems to be whether calls to glColor3f are placed inside or outside glBegin… glEnd.
I would summarise the situation like this:
If Object B is plotted after Object A, then Object A may lose its assigned colours and inherit the colour of Object B on the next loop if:
- A display list is used for Object A, and
- glColor3f is called for each primitive in Object A, and
- glColor3f is called only once for Object B, to apply to all primitives.
It can be prevented from happening by assigning the same colour to all primitives in Object A i.e.
glColor3f 1, 0, 0 ’ red - OUTSIDE LOOP
glBegin GL_POINTS
__For each point
____glVertex3f x, y, z
__Next point
glEnd
Rather than:
glBegin GL_POINTS
__For each point
____glColor3f 1, 0, 0 ’ red - INSIDE LOOP
____glVertex3f x, y, z
__Next point
glEnd
But of course that may not be practical since Object A may be multicoloured.
It can also be prevented by assigning colours individually to the primitives in Object B, even if they are all the same colour i.e.
glBegin GL_LINE_LOOP
__glColor3f 0, 0, 1 ’ blue
__glVertex3f x1, y1, z1
__glVertex3f x2, y2, z2
__glVertex3f x3, y3, z3
__glVertex3f x4, y4, z4
glEnd
Rather than:
glColor3f 0, 0, 1 ’ blue
glBegin GL_LINE_LOOP
__glVertex3f x1, y1, z1
__glVertex3f x2, y2, z2
__glVertex3f x3, y3, z3
__glVertex3f x4, y4, z4
glEnd
(For this to work, glColor3f must go inside each glBegin…glEnd pair.)
So, in this case I can avoid the problem by using individual colours in Object B rather than a single glColor3f call at the beginning of the function.