0

I have knew that there is some problem in this code as if I run it nothing is drawn .

portion of program where wrong is located in this code

void display(void)
{
  glClear (GL_COLOR_BUFFER_BIT);
  glColor3f (1.0, 1.0, 1.0);

  glLoadIdentity ();         

  glPushMatrix();
  glRotated((GLdouble) Vangle,1.0,0.0,0.0);
  gluLookAt (0.0, 0.0, 5.0,   0.0, 0.0, 0.0,    0.0, 1.0, 0.0);
  glPopMatrix();

  glutWireCube (1.0);

  glFlush ();
}

can you tell what is wrong ?

I think in matrix stack methods (push and pop) , I do not know how do I use it

Note : value of Vangle is zero .

genpfault
  • 51,148
  • 11
  • 85
  • 139
user1841718
  • 187
  • 1
  • 4
  • 15
  • 1
    Is the cube displayed *without* the matrix ops? Remember that the "pop" will undo everything done to the "pushed" matrix. –  Feb 19 '13 at 21:25
  • Why do you glRotated() just before gluLookAt? Do you need to rotate as well since gluLookAt essentially commits some rotations and translations to the matrix stack? – FreelanceConsultant Feb 19 '13 at 21:45
  • Another point which i have thought of is that you should call glMatrixMode(GL_PROJECTION) before calling gluLookAt, and then call glMatrixMode(GL_MODELVIEW) after to prevent confusion. See this thread: http://stackoverflow.com/questions/13053334/gluperspective-glviewport-glulookat-and-the-gl-projection-and-gl-modelview-mat Which should sort out any confusion on that matter. (I hope!) – FreelanceConsultant Feb 19 '13 at 21:47
  • yes , it is displayed without matrix ops . – user1841718 Feb 19 '13 at 22:16
  • Edward Bird , I want to rotate coordinates system then put the postion of viewpoint , this will make the position of viewpoint changes ,I want to write program that sees all sides of scene by changing camera aim aroung scene – user1841718 Feb 19 '13 at 22:21

1 Answers1

1

As pst pointed out: Move the glutWireCube() call inside the glPush/PopMatrix() pair.

Give this a shot:

#include <GL/glut.h>

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

    // projection
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    double w = glutGet( GLUT_WINDOW_WIDTH );
    double h = glutGet( GLUT_WINDOW_HEIGHT );
    double ar = w / h;
    gluPerspective( 60, ar, 0.1, 100 );

    // "camera" transform
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    gluLookAt (0.0, 0.0, 5.0,   0.0, 0.0, 0.0,    0.0, 1.0, 0.0);

    // draw cube
    glPushMatrix();
    float Vangle = 0.0f;
    glRotated((GLdouble) Vangle,1.0,0.0,0.0);
    glutWireCube (1.0);    
    glPopMatrix();

    glutSwapBuffers();
}

int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
    glutInitWindowSize( 640, 480 );
    glutCreateWindow( "GLUT" );
    glutDisplayFunc( display );
    glutMainLoop();
    return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139