我是初學者,在開放式GL和我的代碼中,當狀態爲3代碼工作正常,但狀態爲1時,它不能畫線。我想用線連接兩點。 請幫助我如何修復我的if(status==1)
聲明畫出一條線。 這是我的代碼:在OpenGL爲什麼我的drawpoint功能不能正常工作?
void myMouse(int button, int state, int x, int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
if (((x>=30 && x<=70) && ((wh-y)>=400 && (wh-y)<=440)))
status=1;//draw line
else if((x>=30 && x<=70) && ((wh-y)>=280 && (wh-y)<=320))
status=2;
else if((x>=30 && x<=70) && ((wh-y)>=520 && (wh-y)<=560))
status=3;//clear page
else if((x>=30 && x<=70) && ((wh-y)>=160 && (wh-y)<=200))
status=4;
else if((x>=30 && x<=70) && ((wh-y)>=40 && (wh-y)<=80))
status=5;
else drawPoint(x,y);
}
}
void drawPoint(int x,int y)
{
if(status==1)
{
glBegin(GL_LINES);
glVertex2i(x,y);
//glVertex2i(x,y);
glEnd();
glFlush();
}
if(status==3){
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
else{
y=wh-y;
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
glFlush();}
}
如果問題不明確,請先評論。如果它已經不是很清楚,那就給減點!!!! – amIllusionist
「我的功能不好」不是一個可接受的科學問題陳述。 –
您只爲該行指定一個頂點。一條線需要兩個頂點。 –