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 6090003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:09:51+00:00 2026-05-23T12:09:51+00:00

Possible Duplicate: how to rotate this openGl code… below is my code and it

  • 0

Possible Duplicate:
how to rotate this openGl code…

below is my code and it work fine.. i draw 5 ring in this.

#include <GL/glut.h>
#include <math.h>

static void redraw(void);
#define PI 3.14159265 
#define EDGES 90
#define factor 10


void display (void) 
{
    glClearColor(1.0,1.0,1.0,0.0);
     glMatrixMode (GL_MODELVIEW);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();   


//ring1 
glPushMatrix();
glColor3f (0.0, 0.0 ,1.0);
glTranslatef(-30.0,10.0,-100.0);
redraw();
glutSwapBuffers();
glPopMatrix();

//ring2
glPushMatrix();
glColor3f (0.0, 0.0, 0.0);
glTranslatef(-8.0,10.0,-100.0);
redraw();
glutSwapBuffers();
glPopMatrix();

//ring3
glPushMatrix();
glColor3f (1.0, 0.0 ,0.0);
glTranslatef(14.0,10.0,-100.0);
redraw();
glutSwapBuffers();
glPopMatrix();

//ring4
glPushMatrix();
glColor3f (1.0, 1.0, 0.0);
glTranslatef(-19.0,-2.0,-100.0);
redraw();
glutSwapBuffers();
glPopMatrix();

//ring5
glPushMatrix();
glColor3f (0.0, 1.0, 0.0);
glTranslatef(4.0,-2.0,-100.0);
redraw();
glutSwapBuffers();
glPopMatrix();

}

static void redraw(void)
{
for (int i = 0; i < EDGES; i++)
    { 
      glBegin(GL_LINE_LOOP); 
      glVertex2f(factor*cos((2*PI*i)/EDGES),factor*sin((2*PI*i)/EDGES)); 
      glVertex2f(factor*cos((2*PI*(i+1))/EDGES),factor*sin((2*PI*(i+1))/EDGES)); 
      glEnd();
     } 
}

int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(110*3, 110*3);
glutCreateWindow("draw circle");
glPointSize(3); 
glShadeModel (GL_FLAT); 
glutDisplayFunc(display);
glMatrixMode(GL_PROJECTION);    
gluPerspective(45,1.0,10.0,200.0);
glMatrixMode(GL_MODELVIEW);
glutMainLoop();
return 0; 
}

so i want to rotate all of this circle.. how can i do??

  • 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-23T12:09:51+00:00Added an answer on May 23, 2026 at 12:09 pm

    You should call glutSwapBuffers only once in the drawing function.

    For an animation you have to call glutPostRedisplay, to ensure that the display function will be called again.

    The glBegin and glEnd calls only have to be called once per circle. In the for loop you just supply vertices with calls to glVertex.

    To simplify debugging I installed a keyboard handler that closes the window when the escape key is pressed.

     // compile in linux: gcc ogl.c -lglut -lGLU
    
    #include <GL/glut.h>
    #include <math.h>
    #include <stdlib.h>
    
    static void redraw(void);
    #define PI 3.14159265 
    
    enum{
      EDGES=90,
    };
    
    static void 
    circle(float radius)
    {
      int i;
      glBegin(GL_LINE_LOOP); 
      for (i = 0; i < EDGES; i++){ 
        glVertex2f(radius*cos((2*PI*i)/EDGES),
               radius*sin((2*PI*i)/EDGES)); 
        glVertex2f(radius*cos((2*PI*(i+1))/EDGES),
               radius*sin((2*PI*(i+1))/EDGES)); 
      } 
      glEnd();
    }
    
    
    int count=0;
    void display (void) 
    {
      float r=10;
      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();   
    
      glRotated(count,0,0,1);
      count++;
      if(count>360)
        count=0;
    
      glPushMatrix();
      // ring1
      glColor3f (0.0, 0.0 ,1.0);
      glTranslatef(-30.0,10.0,-100.0);
      circle(r);
      glPopMatrix();
    
      glPushMatrix();
      // ring2
      glColor3f (0.0, 0.0, 0.0);
      glTranslatef(-8.0,10.0,-100.0);
      circle(r);
      glPopMatrix();
    
      glPushMatrix();
      //ring3
      glColor3f (1.0, 0.0 ,0.0);
      glTranslatef(14.0,10.0,-100.0);
      circle(r);
      glPopMatrix();
    
      glPushMatrix();
      //ring4
      glColor3f (1.0, 1.0, 0.0);
      glTranslatef(-19.0,-2.0,-100.0);
      circle(r);
      glPopMatrix();
    
      glPushMatrix();
      //ring5
      glColor3f (0.0, 1.0, 0.0);
      glTranslatef(4.0,-2.0,-100.0);
      circle(r);
      glPopMatrix();
    
      glutSwapBuffers();
      glutPostRedisplay();
    }
    
    static void 
    keyb(unsigned char key, int x, int y)
    {
      switch (key) {
      case 27:  /* Escape key */
        exit(0);
      }
    }
    
    
    void
    init()
    {
      glPointSize(3); 
      glShadeModel (GL_FLAT); 
      glMatrixMode(GL_PROJECTION);    
      gluPerspective(45,1.0,10.0,200.0);
      glMatrixMode(GL_MODELVIEW);
      glClearColor(1.0,1.0,1.0,0.0);
      glLineWidth(2);
    }
    
    int
    main(int argc, char **argv)
    {
      glutInit(&argc,argv);
      glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
      glutInitWindowPosition(100,100);
      glutInitWindowSize(110*3, 110*3);
      glutCreateWindow("draw circle");
      glutDisplayFunc(display);
      glutKeyboardFunc(keyb);
      init();
      glutMainLoop();
      return 0; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can someone Explain this jQuery code? I have posted this before, but
Possible Duplicate: Calling virtual functions inside constructors Look at this code. In the constructor
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Algorithm to rotate an image 90 degrees in place? (No extra memory)
Possible Duplicate: Can you write object oriented code in C? Hi, can someone point
Possible Duplicate: how to use foursquare API in android application? This is a question
Possible Duplicate: How to Rotate a UIImage 90 degrees? How to programmatically rotate image
Possible Duplicate: You must include the platform port before the LWUIT in the classpath
Possible Duplicate: Objective C: How can you rotate text for UIButton and UILabel? I

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.