Hello guys,
I’m using OpenGL with MFC to draw 2d scenes. I wnat to draw 1000 lines, rectangles, polygons and ellipses per second. The problem is it takes 100% cpu time. Even if I try to draw just a single line every 200 ms, it takes 100% cpu. What could be the problem ? I’m giving the code for OnDraw() function below:
void OnDraw()
{
CRect r;
GetClientRect(&r);
// Set our palette
if ( m_hPalette != NULL )
{
SelectPalette(pDC->m_hDC, m_hPalette, FALSE);
RealizePalette(pDC->m_hDC);
} // if
// Draw the OpenGL scene
wglMakeCurrent(pDC->m_hDC, m_hRC);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (int i = 0; i < 1000; i++)
{
glPushMatrix();
glBegin(GL_LINE_LOOP);
glColor3f(1,0,0);
glVertex2d(0,0);
glColor3f(0,1,0);
glVertex2d(r .right,0);
glColor3f(0,0,1);
glVertex2d(r .right,r .bottom);
glColor3f(1,1,0);
glVertex2d(0,r .bottom);
glEnd();
glColor3f(1,0,0);
glRectd(100,100, 200, 200);
glRectd(100,440, 200, 480);
glPopMatrix();
}
SwapBuffers(pDC->m_hDC);
wglMakeCurrent(pDC->m_hDC, NULL);
}