我有一個glViewport的問題。在我的程序中,我有兩個視口。我可以在其中一個視口中繪製一個窗體(使用motionfunc),另一個窗體會自動繪製。 到目前爲止這麼好.. 當我嘗試用mousefunc畫一些東西的時候,這個視口在一個完全不同的地方。並且很難找到該視口的新正確座標。 是否有可能重置座標.. 我不能在鼠標或運動中使用glLoadIdentity,因爲沒有顯示任何內容。OpenGL glViewport()(重置座標)
我希望你明白我的意思。這有點難以解釋。
OK這裏codesnippet ....
void mouse (int button, int state, int mx, int my)
{
if (modus == 0 && button==GLUT_LEFT_BUTTON && state != GLUT_DOWN)
{
...
}
else if (modus == 1 && button==GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
**glViewport(10,10 , sw_w1, sw_h1);**
//the drawing is much higher than in the first viewport in motion.
//But it should be the same viewport like the first in motion.
glBegin()...glEnd()
glFlush();
}
}
void motion(int mousex,int mousey)
{
GLdouble h=12;
GLdouble winkel=360/h;
Line liste[num];
liste[++last].x =(mousex)-((sw_w1+2*GAP)/2);
liste[last].y =(mousey)-((sw_h1+2*GAP)/2);
if (modus==0 && gruppe == 0) {
if (last>=1)
{
glViewport(10, 10, sw_w1, sw_h1); //works fine
glColor3d(R, G, B);
for(h+1;h>0;h--){
glRotated(winkel, 0, 0, 1);
glBegin(GL_LINE_STRIP);
for(int i=last-1;i<=last;i++){
glVertex2i(liste[i].x,liste[i].y);
}
glEnd();
}
glLineWidth(linewidth+0.5);
glColor3f(1, 0, 0);
glBegin(GL_LINE_STRIP);
for(int i=last-1;i<=last;i++){
glVertex2i(liste[i].x,liste[i].y);
}
glEnd();
glViewport(1020,10 , sw_w2, sw_h2); //works fine
glColor3f(1, 0, 0);
glBegin(GL_LINE_STRIP);
for(int i=last-1;i<=last;i++){
glVertex2i(liste[i].x,liste[i].y);
}
glEnd();
}
glFlush();
}
}
第二和第三視窗正常工作。第一個和第二個是一樣的,但是圖片顯示得更高。那爲什麼呢? 我怎樣才能改變它,讓我得到像第二個一樣的視口。 我希望你現在明白我的意思。
我不明白 – 2011-06-16 11:34:17
也許你應該張貼一些代碼來澄清你想要做什麼,因爲你的despriptions不是很好,描述性。 – 2011-06-16 12:12:17
在頂部,您會看到我對我的問題所做的更改。 – buddy 2011-06-16 13:19:24