How do can I generate angle rotations around axes given a view direction and up vector (not perpendicular)?

So basically I want to do glRotates myself.

Thanks.

Below is the code I’ve written but I can’t seem to find what’s wrong with it:

```
kVec3D cameraPos = kInitVec3D(0, 0, 100);
kVec3D cameraLkt = kInitVec3D( 0, 0, 0 );
kVec3D cameraDir = kSubVec3D( &cameraLkt, &cameraPos );
kVec3D cameraUp = kInitVec3D(0, 1, 0);
kNormalize( &cameraDir );
kVec3D xAxis = kInitVec3D(1, 0, 0);
kVec3D yAxis = kInitVec3D(0, 1, 0);
kVec3D zAxis = kInitVec3D(0, 0, 1);
kVec3D xPerp = kCrossVec3D( &xAxis, &cameraDir );
kVec3D yPerp = kCrossVec3D( &yAxis, &cameraDir );
kVec3D zPerp = kCrossVec3D( &zAxis, &cameraDir );
float fromX = acosf( kDotVec3D( &cameraDir, &xAxis ) );
float fromY = acosf( kDotVec3D( &cameraDir, &yAxis ) );
float fromZ = acosf( kDotVec3D( &cameraDir, &zAxis ) );
if( kLength( &xPerp ) < 0.0001f ) fromX = 0; else kNormalize( &xPerp );
if( kLength( &yPerp ) < 0.0001f ) fromY = 0; else kNormalize( &yPerp );
if( kLength( &zPerp ) < 0.0001f ) fromZ = 0; else kNormalize( &zPerp );'
glLoadIdentity();
glRotatef( kINDEG( fromX ), xPerp.x, xPerp.y, xPerp.z );
glRotatef( kINDEG( fromY ), yPerp.x, yPerp.y, yPerp.z );
glRotatef( kINDEG( fromZ ), zPerp.x, zPerp.y, zPerp.z );
glTranslatef( -cameraPos.x, -cameraPos.y, -cameraPos.z );
```