matrices....

i’v got a code like this:

  GLfloat m[16];
  int i;

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  printf("
 before >> 
");

  glGetFloatv(GL_MODELVIEW_MATRIX, m);
  for(i=0;i<16;i++) {
    if(i % 4 == 0) printf("
");
    printf("%5.5f    ",m[i]);
  }
  glRotatef(90,1,0,0);
  printf("
 after >> 
");
  glGetFloatv(GL_MODELVIEW_MATRIX, m);
  for(i=0;i<16;i++) {
    if(i % 4 == 0) printf("
");
    printf("%5.5f    ",m[i]);
  }

as you probably see, it loads an identity matrix and then rotates it by 90deg around x-axis… a this is output of my lovely program

 before >>

1.00000    0.00000    0.00000    0.00000
0.00000    1.00000    0.00000    0.00000
0.00000    0.00000    1.00000    0.00000
0.00000    0.00000    0.00000    1.00000
 after >>

  nan      nan      nan      nan
0.00000    -0.00000    1.00000    0.00000
0.00000    -1.00000    -0.00000    0.00000
0.00000    0.00000    0.00000    1.00000

what the hell nans do there ? plz… if you have ANY suggestion let me know :wink:

nan is “not a number”, basically it’s a bogus value as a result of bogus math.

Try using floats in your rotatef call, instead of ints i.e. 1.0f instead of 1, 90.0f instead of 90, 0.0f instead of 0 etc. The only thing that looks suspicious is the potential for badness due to non explicit casts here especially in C.

that’s not a problem (i even tried glRotatef((float)90.0, (float)1.0, (float)0.0, (float)0.0) and similar crazy attempts). it’s larger program which suddenly stopped working… after 4 hours of useless printf()ing i found that. but i just noticed a strange thing. on first call it works well. on subsequent calsl it outputs ugly nans. i think it’s caused by some screwed gl state (but i don’t have a clue what kind of state could cause this)) and obviously it could be caused by unitialized pointer…

The code you gave should just work.
Stray pointers aside, if the error happens in a bigger program, make sure your matrices don’t degenerate due to floating point errors accumulating over matrix concatenations.

For example if you do something like this

for (hours)
{
glClear()
glRotatef(1.0f, 1.0f, 0.0f, 0.0f);
draw();
}

your modelview matrix will sum up rounding errors and you geometry will be skewed and/or moving off the screen.

Always recalculate your matrices from given parameters like angles.

yeah… another five hours wasted and pointers pointing to hell rulez! i thought i was related to gl because my code never segfaulted or did something like such pointers usually do. yeah, i’s working now and i’m jumping aroung and having fun!!! :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: