Using glEvalCoord1f

Hey guys, I am trying to create bezier spline as the user clicks on the screen. I am using Visual Studio 6 and I am using MFC for the application. Now as the user clicks the screen, a point is created and inserted into an array. And then I call the glMap1() everytime a new point is created to update the function parameter for the no. of control points and enable it. And then I render it using glEvalCoord1f(). Now for everytime the user clicks the screen, the glMap1() is called for the new point being inserted in the array.

I dont get it to work…that is the curve displayed is a straight line that goes into infinity.

Can anyone help me? Should I paste the code ?

Originally posted by <infinitecmdz>:
Should I paste the code ?
Yes, please. But only the GL side of things, for brevity’s sake. MFC code can get a bit unwieldy :slight_smile:

Below snippet is from the OnDraw() which what gets called everytime for rendering…

  

if(pDoc->m_bBezierCreate)
{
::glDisable(GL_LIGHTING) ;
::glColor3f(0.0f , 1.0f , 0.0f) ;

	::glPointSize(10.0f) ;

		m_ClickOglPoints = GetOglPos(m_CurrentPoint) ;
		
		//Check if the point clicked is in the plane.
		if(m_bIsClicked)
		{
			if(CurvePlane.IsPointInPolygon(Vector2(m_ClickOglPoints.x , m_ClickOglPoints.z)))
			{
				//Insert it into the control point list.
				pDoc->m_pSpline->InsertPoint(m_ClickOglPoints) ;
				pDoc->m_pSpline->InitDrawing() ;
			}
		}

		pDoc->m_pSpline->DrawCurve(0.0f , 1.0f , 1.0f) ;
		//pDoc->m_pSpline->DrawControlPoints() ;
		m_bIsClicked = FALSE ;

	::glEnable(GL_LIGHTING) ;
}
  
  
BOOL CSpline::InitDrawing()
{
	if(m_pControlPoints && Iterator > 0)
	{
		//Store the control points in an array.

		for(int i = 0 ; i < Iterator ; i++)
		{
			pControlPoints[i][0] = m_pControlPoints[i].x ;
			pControlPoints[i][1] = m_pControlPoints[i].y ;
			pControlPoints[i][2] = m_pControlPoints[i].z ;
		}

		if(m_nControlPoints > 1 && m_iSplineType == 1)
		{
			::glMap1f(GL_MAP1_VERTEX_3 , 0.0 , 1.0 , 3 , Iterator , &pControlPoints[0][0]) ;
			::glEnable(GL_MAP1_VERTEX_3) ;
		}

		return TRUE ;
	}

	return FALSE ;
}
  
BOOL CSpline::DrawCurve(float fRed , float fGreen , float fBlue)
{
	//::glClear(GL_COLOR_BUFFER_BIT) ;
	::glColor3f(fRed , fGreen , fBlue) ;

	if(m_pControlPoints)
	{
		if(m_iSplineType == 1) //Its a bezier curve
		{
			::glBegin(GL_LINE_STRIP) ;

			for(int i = 0 ; i < 30 ; i++)
				::glEvalCoord1f(GLfloat(i/30.0f)) ;
				
			::glEnd() ;

			DrawControlPoints() ;
		}

		if(m_iSplineType == 2) //Its a B-Spline curve
		{

		}

		if(m_iSplineType == 3) //Its a NURBS
		{

		}

		return TRUE ;
	}

	return FALSE ;
}

Please bear in mind that the code is very incomplete but …not so incomplete with regards to Bezier curve…

Thanx …yours Sid

This is the output i am getting

http://img126.imagevenue.com/img.php?image=75632_Bezier_122_517lo.jpg

Can anyone here help me out? I have given all the information i can…