user1302064
user1302064

Reputation: 91

Highlight points with different colors using opengl

I have plotted a series of points using glVertex3f() in certain color. Now, when the user clicks on a point, I need to display related points in a different color, while the other ones remain in old color. Tried using the condition mentioned below but color remains the same, which was set first. Is there a way to plot points in different colors?

   if((highlightColor)&&(i==0)){                      
         glColor3f(0,1,0);                    
         glVertex3f(tempx,calcy,0);
   } else{
         glColor3f(0,0,1);       
         glVertex3f(tempx,calcy,0);
   }   

Initially, all points are blue. Then I set the variable highlightColor to true if I want to highlight some points with a different color and call this method again. Color does not change to green. Can someone please tell me where I have gone wrong?

Upvotes: 0

Views: 2123

Answers (1)

Preet Kukreti
Preet Kukreti

Reputation: 8607

If you have depth testing enabled, if the highlighted draw is not first, it might be getting rejected because it would fail the depth test against the z-buffer. It could also be that you aren't clearing the depth buffer? If you dont want to turn depth testing off (e.g. to avoid state switch), then you could shift the z of the highlighted point closer so it passes the depth test.

Also, are you sure that the if condition passes at all? if so, as a sanity check, you could draw to slightly shifted/offsetted (x,y) in some empty space just to make sure that it is actually entering that block.

It could simply be that another blue point could drawn on top of it. You will have to post more code to show what you are doing.

Upvotes: 1

Related Questions