Moving an object towards x-axis

Hello,i am a very beginner and iam trying to make movement of a character in a scene,i tried making this by using gltranslatef(),but when use this function the charecter will disaapear.
I am posting my code below please correct my mistakes.and my character is a rectangle now.i am using keyboard function to move character.


int main( int argc,char **argv)
{
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
   glutInitWindowSize(1000,1000);
   glutCreateWindow("Nakkur's Village");
   glutKeyboardFunc(myKey);
   glutDisplayFunc(display);

  //glutTimerFunc(1000,mytimer,0);

   glutMainLoop();
  return 0;
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluOrtho2D(-1000,1000,-1000,1000);

        nyt();
        wall();
        mountain();
        house();
        //movenakkur(cx);

        tree();
        blinkstars();
        moon();

        glPushMatrix();
        glTranslatef(k,0,0);
        cloud();
        cloud1();
        cloud2();
        k+=100;
        glutPostRedisplay();
        glPopMatrix();


glFlush();
glutSwapBuffers();


    }

void wall()
{int i,j;
  glBegin(GL_QUADS);//basement
  glColor3f(0.545,0.271,0.075);
  glVertex2f(-1000,-700);
  glVertex2f(-1000,-1000);
  glColor3f(0.627,0.322,0.176);
  glVertex2f(1000,-1000);
  glVertex2f(1000,-700);
  glEnd();



  glBegin(GL_QUADS);//grass basement
  glColor3f(0.196,0.804,0.196);
  glVertex2f(-1000,-650);
  glColor3f(0,0,0);
  glVertex2f(-1000,-700);
  glColor3f(0,0,0);
  glVertex2f(1000,-700);
   glColor3f(0.196,0.804,0.196);
  glVertex2f(1000,-650);
  glEnd();
  glBegin(GL_POLYGON);//floor
  glColor3f(0.000,1.000,0.341);
  glVertex2f(-1000,-500);
  glColor3f(0.00,0.392,0.00);
  glVertex2f(-1000,-650);
  glColor3f(0.00,0.392,0.00);
  glVertex2f(1000,-650);
  glColor3f(0.000,1.000,0.341);
  glVertex2f(1000,-500);
  glEnd();

}
void house()
{
 glBegin(GL_QUADS);//wall
  glColor3f(0.184,0.310,0.310);
  glVertex2f(-900,-600);
  glColor3f(0.184,0.310,0.310);
  glVertex2f(-500,-600);
  glColor3f(0.439,0.502,0.565);
  glVertex2f(-500,-300);
  glColor3f(0.439,0.502,0.565);
  glVertex2f(-900,-300);
  glEnd();

  glBegin(GL_QUADS);//terrase
  glColor3f(0.412,0.412,0.412);
  glVertex2f(-1000,-300);
  glColor3f(0.412,0.412,0.412);
  glVertex2f(-400,-300);
  glColor3f(0.722,0.525,0.043);
  glVertex2f(-600,-100);
  glColor3f(0.722,0.525,0.043);
  glVertex2f(-800,-100);
  glEnd();

  glBegin(GL_QUADS);//door
  glColor3f(0,0,0);
  glVertex2f(-750,-600);
  glVertex2f(-650,-600);
  glVertex2f(-650,-400);
  glVertex2f(-750,-400);
  glEnd();
}

void tree()
{
  glBegin(GL_POLYGON);//root
  glColor3f(0.545,0.271,0.075);
  glVertex2f(500,-650);
  glVertex2f(525,-650);
  glVertex2f(525,-300);
  glColor3f(0.824,0.706,0.549);
  glVertex2f(510,-280);
  glVertex2f(490,-290);
  glVertex2f(510,-310);
  glEnd();

  glPushMatrix();//branches
  glColor3f(0.133,0.545,0.133);
  glTranslatef(40,80,0);
  circle(450+dx/8,-350-dy,90);
  glPopMatrix();


  glPushMatrix();
  glColor3f(0.133,0.545,0.133);
  glTranslatef(20,90,0);
  circle(450+dx/8,-350-dy,90);
  glPopMatrix();


    glPushMatrix();
    glColor3f(0.133,0.545,0.133);
    glTranslatef(420,100,0);
    circle(160+dx/8,-350-dy,90);
    glPopMatrix();

    glPushMatrix();
    glColor3f(0.133,0.545,0.133);
    glTranslatef(360,80,0);
    circle(180+dx/2,-350-dy,90);
    glPopMatrix();


    glPushMatrix();
    glColor3f(0.133,0.545,0.133);
    glTranslatef(400,110,0);
    circle(190+dx/2,-345-dy,90);
    glPopMatrix();

    glPushMatrix();
    glColor3f(0.133,0.545,0.133);
    glTranslatef(400,110,0);
    circle(90+dx/2,-325-dy,120);
    glPopMatrix();

}

void cloud()
{

glColor3f(0.52,0.537,0.52);
circle(800,350,40);

glColor3f(0.52,0.537,0.52);
circle(810,295,30);

glColor3f(0.52,0.537,0.52);
circle(840,265,30);

glColor3f(0.52,0.537,0.52);
circle(820,300,40);

glColor3f(0.52,0.537,0.52);
circle(860,340,40);
}

void cloud1()
{

glColor3f(0.52,0.537,0.52);
circle(320,90,20);

glColor3f(0.52,0.537,0.52);
circle(420,100,10);

glColor3f(0.52,0.537,0.52);
circle(360,80,40);

glColor3f(0.52,0.537,0.52);
circle(400,110,40);
glColor3f(0.52,0.537,0.52);
circle(440,80,20);

glColor3f(0.52,0.537,0.52);
circle(320,90,20);

glColor3f(0.52,0.537,0.52);
circle(420,100,10);

glColor3f(0.52,0.537,0.52);
circle(360,80,40);

glColor3f(0.52,0.537,0.52);
circle(400,110,40);

}


void cloud2()
{
glColor3f(0.52,0.537,0.52);
circle(40,280,20);

glColor3f(0.52,0.537,0.52);
circle(-80,290,20);

glColor3f(0.52,0.537,0.52);
circle(20,300,10);

glColor3f(0.52,0.537,0.52);
circle(-40,280,40);

glColor3f(0.52,0.537,0.52);
circle(0,310,40);

}

void myKey(unsigned char key,int x,int y)
{
 switch(key)
 {
 case 'd':
           glPushMatrix();
           glTranslatef(cx,0,0);
           nakkur();
            cx+=10;
            glutPostRedisplay();
            glPopMatrix();
            break;
  case 'q':exit(0);
           break;
 }


}


void nakkur()//my charecter to be moved
{
  glBegin(GL_QUADS);
  glColor3f(1.00,0.973,0.863);
  glVertex2f(-800,-500);
  glVertex2f(-770,-500);
  glVertex2f(-770,-630);
  glVertex2f(-800,-630);
  glEnd();
}

This isn’t a debugging service. Please read the Forum Posting Guidelines.

What have you done to try and debug the problem yourself? Do you have any specific OpenGL-related questions you’d like to ask?

Sir,i am trying to move an object through x-axis how doi can achive it??
Using which function i can implement the move function,please suggest me!!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.