win32 openGL adding line segments

closed account (DSvMDjzh)
The goal of the program is for line segments to be drawn every 20ms that follow the cursor. Right now I have it so it follows the cursor with one attached point, I am at a loss to get it to draw continuously. This is how I how I tried doing it but couldn't figure out how to add vertices on th go.
This is where I would like more vertices to be added.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
			
			// OpenGL animation code goes here
			
			glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
			glClear( GL_COLOR_BUFFER_BIT );
			
			glPushMatrix();
			glBegin(GL_LINE_STRIP);
			for(int i=0;i<Index;i++){
				glColor3f(1.0f,0.0f,0.0f); glVertex2f(-1.0,-1.0);
				glColor3f(1.0f,0.0f,0.0f); glVertex2f(xPosg, yPosg);	
			}//end for i 
			glEnd();

			glPopMatrix();
			
			SwapBuffers( hDC );
			
		}

This is the array and timer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
bool InitTimer(HWND hWnd){
	bool out=FALSE;

	out = SetTimer(hWnd,TIMER_ID,TIMER_INTERVAL,(TIMERPROC)TimerTick);

	
	return out;
}//end TimerControl

bool StopTimer(HWND hWnd){
	bool out=FALSE;

	out = KillTimer(hWnd,TIMER_ID);


	return out;
}//end Stoptimer


 //Called every TIMER_INTERVAL milliseconds*/
void TimerTick(void){
	/*Data[x][0] -> X position
	  Data[x][1] -> Y Position
	  */

	static int count=0;

	if(count==20){
		count=0;
		Data[Index][0]=xPosg;
		Data[Index][1]=yPosg;
		Index++;

	}
	
	
}//end TimerTick 



Thanks,

Josh
Last edited on
Try moving glBegin and glEnd to within your for loop.
closed account (DSvMDjzh)
Wouldn't that just show the one line strip... It wouldn't add another vertex point.
It would create a new line every iteration of the loop.
closed account (DSvMDjzh)
It works now. Had to change up the for loop a little bit but no major alterations.

Thank you very much,

Josh
Topic archived. No new replies allowed.