Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:04:35+00:00 2026-05-23T04:04:35+00:00

I have a problem with glViewport. In my liitle programm i have two viewports.

  • 0

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.

I hope you understand what i mean. It is a bit difficult to explain.

OK here a 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();

}
}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:04:36+00:00Added an answer on May 23, 2026 at 4:04 am

    You should check your modelview/projection matrices and see if they are what you expect them to be in each function.

    Also, as Christian’s commented, it is not necessary, nor recommended, to draw in the motion func. Update your application state per the input and call glutPostRedisplay to signal that you want to redraw your window. That way, your application will have a cleaner design and it will be easier to make it behave consistently.

    (added my comment as answer since that was the problem, and added Christian’s comment, since that is the proper solution. Don’t draw in motionfunc!.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with the CSS. I'm changing dynamically one div's content. The problem
I seem to have a curious problem. I set up OpenGL like this: glViewport(0,
i have problem passing data from one page to another using GET, for example
I have problem about django template-db query relationship. For example, I created two tables
i have problem with substitution. I have a file with 1 line of random
i have problem in javascript email validation, I wrote code something like, //emp.php <form
I have problem with $_POST data. Some fields are missing from input form when
I have used the following lines of code to draw a line from point
I have problem in some JavaScript that I am writing where the Switch statement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.