i trying to draw ellipse in MFC C++ just use OPENGL. it ran for the resulting ellipse but it is not correct mouse coordinates. My code:
in class Ellispe.cpp
void VeEllispe::putPixel(int x,int y,int xc, int yc)
{
glBegin(GL_POINTS);// bat dau bang ve diem
glVertex2i(xc+x,yc+y);
glVertex2i(xc-x,yc-y);
glVertex2i(xc+x,yc-y);
glVertex2i(xc-x,yc+y);
glEnd();
}
void VeEllispe::Draw(int a, int b,int xc,int yc)
{
int x = 0;
int y = b;
float a2 = (a*a);
float b2 = (b*b);
float p = b2 - a2*b + 0.25*a2;
while(2*b2*x <= 2*y*a2)
{
putPixel(x,y,xc,yc);
if (p < 0) p+= 2*b2*x + 3*b2;
else
{
p+= 2*b2*x + 3*b2 - 2*a2*y + 2*a2;
y--;
}
x++;
}
x = a;
y = 0;
p = a2 - b2*a + 0.25*b2;
while(2*a2*y <= 2*x*b2)
{
putPixel(x,y,xc, yc);
if (p < 0) p+= 2*a2*y + 3*a2;
else
{
p+= 2*a2*y + 3*a2 - 2*b2*x + 2*b2;
x--;
}
y++;
}
}
in class XYZView.cpp
.
.
VeEllispe e;
void Cbaitap1View::OnDraw(CDC* /*pDC*/)
{
Cbaitap1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
wglMakeCurrent(m_hDC,m_hRC);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0,0.0,1.0);
glPointSize(2);
if (state==4)
e.Draw(X2,Y2,X1,Y1);
glFlush();
SwapBuffers(::GetDC(GetSafeHwnd()));
wglMakeCurrent(NULL,NULL);
}
And if possible, can you teach me the document to drawing triangles or parapol use OPENGL?