Draw a shape when clicked - Shape is not rendering?

Hi all, I am currently working on a MFC app and is trying to draw a shape on click. However, when i clicked, the shape is not rendering - I simply cant see it on screen. The render function works fine when it’s called in OnDraw, but not when I call it in a function. Can someone tell me what is wrong?

void CTutorial2View::OnLButtonDblClk(UINT nFlags, CPoint point)
{

CView::OnLButtonDblClk(nFlags, point);
TRACE("Left Clicked!\n");
RenderScene();
InvalidateRect(0, FALSE);

}

void CTutorial2View::RenderScene()
{

 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 glShadeModel(GL_SMOOTH);

 glScalef(m_fScale, m_fScale, m_fScale);
 glTranslatef(xtrans, ytrans, ztrans);
 glRotatef(xrot, 1, 0, 0);
 glRotatef(yrot, 0, 1, 0);

 ////Triangle
 glNormal3f(0.0, 0.0, 1.0);
 glBegin(GL_TRIANGLES);
 glVertex3f(0.0f, 2.0f, 0.0f);
 glVertex3f(-2.0f, -2.0f, 0.0f);
 glVertex3f(2.0f, -2.0f, 0.0f);
 glEnd();

 glFlush();

}

You shouldn’t be attempting to draw to a window other than in response to a request from the window system (i.e. outside of the draw callback). If you want to change the rendered image, change the data used to render it then force a redraw (e.g. by calling InvalidateRect).

Thanks! This makes me realise what I should have done!

For the record, here’s what I have done to achieve what I wanted to do:

void CTutorial2View::RenderScene()
{

 ...
 ////Triangle
 if (show_tri)
 {
      glNormal3f(0.0, 0.0, 1.0);
      glBegin(GL_TRIANGLES);
      glVertex3f(0.0f, 2.0f, 0.0f);
      glVertex3f(-2.0f, -2.0f, 0.0f);
      glVertex3f(2.0f, -2.0f, 0.0f);
      glEnd();

}

 glFlush();

}

void CTutorial2View::OnLButtonDblClk(UINT nFlags, CPoint point)
{

 CView::OnLButtonDblClk(nFlags, point);
 TRACE("Left Clicked!\n");
 show_tri = true;
 InvalidateRect(0, FALSE);

}