# Color of dots / glvertex2f changes with movement

This topic is 2826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone, I have a display of random dots projected onto a ground plane. When I add movement in the z and x direction, the color and or brightness of most of the dots get brighter. To me, it seems like the dots get drawn in the same position for a few frames, and the RGB values get added together, making the dot brighter. so maybe something to do with a buffer? I appreciate any help, thanks!

##### Share on other sites
Are you calling glClear() between frames? If not, you might be blending the results of several frames together - but I don't reckon this to be particularly likely.

##### Share on other sites
Yes, I have called glClear after each frame.

glClear(GL_COLOR_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clears the buffer to draw again

##### Share on other sites
Can you show the code where you set up the camera and whatnot?

##### Share on other sites
Here is a portion of my extensive code, I hope this is enough. All the "trials" and "conditions" are part of variables I am manipulating.

void ShowStars(void){	int n;			//Index	float x0, y0;	//X and y coordinates		glColor3f(conditionS[order[trial]].dotbright, conditionS[order[trial]].dotbright, conditionS[order[trial]].dotbright); //Set dot color	glPointSize(2.0);				//Set dot size	glBegin(GL_POINTS);				//Begins list of vertices		for (n = 0; n < conditionS[order[trial]].numpoints; n++)	{		if(trialS[trial].point[n].z < 0)		{			trialS[trial].point[n].x = (float)rand()/(float)(RAND_MAX+1)*plane_width-plane_width/2.;			trialS[trial].point[n].z += MAXPOS;		}				if(abs(trialS[trial].point[n].x) > (display_width/2)/e*trialS[trial].point[n].z)		{			trialS[trial].point[n].x = -trialS[trial].point[n].x;		}		x0 = e*trialS[trial].point[n].x /(trialS[trial].point[n].z);		y0 = e*trialS[trial].point[n].y /(trialS[trial].point[n].z);			glVertex2f(x0,y0);				//Draws the dots		}	glEnd();							//End the list of vertices}void Initialize(){	glClearColor(0.0, 0.0, 0.0, 0.0);					//Clears the color bit	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	//Really Nice Perspective Calculations	firstframe = 1;							//	vis_ang = 2*atan((display_width/2)/e);	//	plane_width = display_width/e*MAXPOS;	//	srand((unsigned int) time(NULL));				//	initial_time = ((int)(clock()/CLOCKS_PER_SEC));	//	Sinusoid();								//Creates the sinusoidal function	CreateDisplays();						//Creates list of display numbers	GenerateConditions();					//Generate the conditions	MakeRandomOrder();						//Randomize the conditions	ticks1 = clock();						//	return;}void ReshapeScene(GLsizei width, GLsizei height){	if (height == 0)	{	  height = 1;		//Prevent from dividing by zero	}	glViewport(0, 0,width, height);		//Reset The Current Viewport	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluOrtho2D(-display_width/2, display_width/2, -display_width/2*height/width, display_width/2*height/width);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	return;}void RenderScene(){	glLoadIdentity();	//Clears all states to start drawing			if (move == TRUE)	//If move has been set on, move stars	{		MoveStars();	//Gets new coordinates		UpdateStars();	//Clears screen		ShowStars();	//Draws the dots	}	else				//If move not set, don't move dots	{		UpdateStars();	//Clears screen		ShowStars();	//Draws the dots	}		//glFlush();}void IllustrateScene(){	glClearColor(	conditionS[order[trial]].backbright,					conditionS[order[trial]].backbright,					conditionS[order[trial]].backbright,					0.0);								//Sets background color		glClear(GL_COLOR_BUFFER_BIT);	//Clears the color buffer bit	RenderScene();					//Draws the scene	return;}

##### Share on other sites
While moving objects will appear slightly brighter, due to imperfections in the monitor and the human eye. For example, a white point on a black background moving left will leave a small (1-2px) dark grey trail behind it, because the pixel cannot turn completely off instantly. The effect is larger on CRT monitors, as Phosphorus compounds continue to glow for a while. Your eye, for its part, suffers from something called "persistence of vision", which is essentially the same thing.

This may not be your problem, or I could just be misunderstanding you. If not, you can help it by using larger, blurrier points or moving more slowly, or not at all.

You might also want to be clearing the depth buffer somewhere in there--I didn't notice such a call.

Hope this helps,
-G

##### Share on other sites
Quote:
 Original post by GeometrianWhile moving objects will appear slightly brighter, due to imperfections in the monitor and the human eye. For example, a white point on a black background moving left will leave a small (1-2px) dark grey trail behind it, because the pixel cannot turn completely off instantly. The effect is larger on CRT monitors, as Phosphorus compounds continue to glow for a while. Your eye, for its part, suffers from something called "persistence of vision", which is essentially the same thing.This may not be your problem, or I could just be misunderstanding you. If not, you can help it by using larger, blurrier points or moving more slowly, or not at all. You might also want to be clearing the depth buffer somewhere in there--I didn't notice such a call.Hope this helps,-G

Thanks for your input. I have only tried the program on a 19" LCD monitor and a 46" LCD monitor. The issue is more apparent on the larger screen. I have tried increasing the point size, but with no improvement. The movement at its current speed is necessary, so eliminating that is not an option for me.

I have recently added the depth buffer clearing into the code. It does not seem to be making a noticeable difference.

##### Share on other sites
Someone suggested that I try using a high resolution timer. Does this seem like a possible solution? And why would it be?

##### Share on other sites
The points I draw have global coordinate positions. It is possible that two points that are near each other globally get drawn to the same pixel on the screen, hence the accumulation.

If this is the case, is there a way to prevent drawing to a pixel if it has been drawn to already?

##### Share on other sites

This topic is 2826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.