I want to see the movement of the Sphere on the screen(OpenGL)











up vote
1
down vote

favorite












I want to see the movement of the Sphere on the screen.
but, If you run the code, you will not be able to update the screen.
How do I change the code to show a change in the location of the phrase I created?



void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);

GLfloat diffuse1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1 = { 0, 0, 0, 1.0 };
GLfloat diffuse2 = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2 = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2 = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2 = { 0, 0, 0, 1 };
GLfloat shine = 300;

glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}

void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}









share|improve this question







New contributor




Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • There is a typo in the code: position should be position1. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
    – Rabbid76
    Nov 18 at 14:53

















up vote
1
down vote

favorite












I want to see the movement of the Sphere on the screen.
but, If you run the code, you will not be able to update the screen.
How do I change the code to show a change in the location of the phrase I created?



void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);

GLfloat diffuse1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1 = { 0, 0, 0, 1.0 };
GLfloat diffuse2 = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2 = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2 = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2 = { 0, 0, 0, 1 };
GLfloat shine = 300;

glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}

void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}









share|improve this question







New contributor




Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • There is a typo in the code: position should be position1. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
    – Rabbid76
    Nov 18 at 14:53















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to see the movement of the Sphere on the screen.
but, If you run the code, you will not be able to update the screen.
How do I change the code to show a change in the location of the phrase I created?



void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);

GLfloat diffuse1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1 = { 0, 0, 0, 1.0 };
GLfloat diffuse2 = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2 = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2 = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2 = { 0, 0, 0, 1 };
GLfloat shine = 300;

glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}

void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}









share|improve this question







New contributor




Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I want to see the movement of the Sphere on the screen.
but, If you run the code, you will not be able to update the screen.
How do I change the code to show a change in the location of the phrase I created?



void display() {
glLoadIdentity();
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);

GLfloat diffuse1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat ambient1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular1 = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position1 = { 0, 0, 0, 1.0 };
GLfloat diffuse2 = { 0.5, 0.5, 0.5, 1 };
GLfloat ambient2 = { 0.1, 0.1, 0.1, 1 };
GLfloat specular2 = { 0.5, 0.5, 0.5, 1 };
GLfloat emission2 = { 0, 0, 0, 1 };
GLfloat shine = 300;

glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular1);
glPushMatrix();
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
glMaterialfv(GL_FRONT, GL_EMISSION, emission2);
glMaterialf(GL_FRONT, GL_SHININESS, shine);
glRotatef(mer_revolution, 0, 0, 1);
glTranslatef(0, 0.8, 0);
glRotatef(mer_rotate, 0, 0, 1);
glutSolidSphere(1, 300, 300);
glPopMatrix();
glFlush();
}

void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("");
glClearColor(0, 0, 0, 0);
glColor3f(1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(move);
glutMainLoop();
}






c++ opengl






share|improve this question







New contributor




Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 18 at 14:13









Paul Z.

61




61




New contributor




Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Paul Z. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • There is a typo in the code: position should be position1. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
    – Rabbid76
    Nov 18 at 14:53




















  • There is a typo in the code: position should be position1. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
    – Rabbid76
    Nov 18 at 14:53


















There is a typo in the code: position should be position1. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
– Rabbid76
Nov 18 at 14:53






There is a typo in the code: position should be position1. Furhter the projection matrix is missing, so the sphere is not in clip space and not "visible". Please correct that, to make it a Minimal, Complete, and Verifiable example
– Rabbid76
Nov 18 at 14:53














2 Answers
2






active

oldest

votes

















up vote
2
down vote













Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
The screen must be initialized when performing a function. Only then will the screen continue to change.






share|improve this answer




























    up vote
    0
    down vote













    There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay.



    Further you should incrementally change the angles mer_revolution and mer_rotate to animate the scene:



    void display( void )
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    ....

    glFlush();
    glutPostRedisplay();

    mer_revolution += 1.0f;
    mer_rotate += 0.5f;
    }





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });






      Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.










       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361819%2fi-want-to-see-the-movement-of-the-sphere-on-the-screenopengl%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
      The screen must be initialized when performing a function. Only then will the screen continue to change.






      share|improve this answer

























        up vote
        2
        down vote













        Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
        The screen must be initialized when performing a function. Only then will the screen continue to change.






        share|improve this answer























          up vote
          2
          down vote










          up vote
          2
          down vote









          Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
          The screen must be initialized when performing a function. Only then will the screen continue to change.






          share|improve this answer












          Move 'gL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT' at the top of the display.
          The screen must be initialized when performing a function. Only then will the screen continue to change.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 at 14:21









          Sera

          462




          462
























              up vote
              0
              down vote













              There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay.



              Further you should incrementally change the angles mer_revolution and mer_rotate to animate the scene:



              void display( void )
              {
              glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

              ....

              glFlush();
              glutPostRedisplay();

              mer_revolution += 1.0f;
              mer_rotate += 0.5f;
              }





              share|improve this answer

























                up vote
                0
                down vote













                There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay.



                Further you should incrementally change the angles mer_revolution and mer_rotate to animate the scene:



                void display( void )
                {
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                ....

                glFlush();
                glutPostRedisplay();

                mer_revolution += 1.0f;
                mer_rotate += 0.5f;
                }





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay.



                  Further you should incrementally change the angles mer_revolution and mer_rotate to animate the scene:



                  void display( void )
                  {
                  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                  ....

                  glFlush();
                  glutPostRedisplay();

                  mer_revolution += 1.0f;
                  mer_rotate += 0.5f;
                  }





                  share|improve this answer












                  There are 2 issues. Of course you have to clear the framebuffer at the begin of every frame glClear. But you have to "tell" the display to be continuously redisplayed, too. ths can be done by glutPostRedisplay.



                  Further you should incrementally change the angles mer_revolution and mer_rotate to animate the scene:



                  void display( void )
                  {
                  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                  ....

                  glFlush();
                  glutPostRedisplay();

                  mer_revolution += 1.0f;
                  mer_rotate += 0.5f;
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 18 at 14:39









                  Rabbid76

                  30.4k112842




                  30.4k112842






















                      Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.










                       

                      draft saved


                      draft discarded


















                      Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.













                      Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.












                      Paul Z. is a new contributor. Be nice, and check out our Code of Conduct.















                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361819%2fi-want-to-see-the-movement-of-the-sphere-on-the-screenopengl%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Create new schema in PostgreSQL using DBeaver

                      Deepest pit of an array with Javascript: test on Codility

                      Costa Masnaga