Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL glViewport() (resetting coordinates)
    text
    copied!<p>I have a problem with glViewport. In my liitle programm i have two viewports. I can draw a form (with the motionfunc) in one of those viewports and in the other a line is automatically drawn. So far so good.. When i try to draw something with mousefunc the viewport is in a total different place. And it is very difficult to find the new correct coordinates for that viewport. Is there a possibility to reset the coordinates.. I cant use glLoadIdentity in mouse or motion because then nothing is displayed.</p> <p>I hope you understand what i mean. It is a bit difficult to explain.</p> <p>OK here a codesnippet....</p> <pre><code>void mouse (int button, int state, int mx, int my) { if (modus == 0 &amp;&amp; button==GLUT_LEFT_BUTTON &amp;&amp; state != GLUT_DOWN) { ... } else if (modus == 1 &amp;&amp; button==GLUT_LEFT_BUTTON &amp;&amp; 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 &amp;&amp; gruppe == 0) { if (last&gt;=1) { glViewport(10, 10, sw_w1, sw_h1); //works fine glColor3d(R, G, B); for(h+1;h&gt;0;h--){ glRotated(winkel, 0, 0, 1); glBegin(GL_LINE_STRIP); for(int i=last-1;i&lt;=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&lt;=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&lt;=last;i++){ glVertex2i(liste[i].x,liste[i].y); } glEnd(); } glFlush(); } } </code></pre> <p>The second and third viewport works fine. The first one is the same as the second but the picture is displayed much higher.Why is that so? And how could i change it so that i get the same viewport like the second one. I hope you now understand what i mean.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload