我正在尝试为fps项目实现一个摄像头,在调用glMatrixMode(GL_MODELVIEW)
时在main.cpp上使用我的Camera类时遇到问题。
以下是相关功能:
void Camera::init() {
m_yaw = 0.0;
m_pitch = 0.0;
set_pos(0,0,0);
}
void Camera::set_pos(float x, float y, float z) {
m_x = x;
m_y = y;
m_z = z;
refresh();
}
void Camera::refresh() {
m_lx = cos(m_yaw) * cos(m_pitch);
m_ly = sin(m_pitch);
m_lz = sin(m_yaw) * cos(m_pitch);
m_strafe_lx = cos(m_yaw - M_PI_2);
m_strafe_lz = sin(m_yaw - M_PI_2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
printf("the segmentation fault is above!\n");
gluLookAt(m_x, m_y, m_z, m_x + m_lx, m_y + m_ly, m_z + m_lz, 0.0, 1.0, 0.0);
//printf("Camera: %f %f %f Direction vector: %f %f %f\n", m_x, m_y, m_z, m_lx, m_ly, m_lz);
}
答案 0 :(得分:1)
如果你包含glew.h,你需要事先初始化,否则GL API调用被替换为空函数指针并导致段错误。