输入glBegin()后OpenGL分割错误
OpenGL Segmentation Fault after typing glBegin()
我对OpenGL编程非常陌生,一切都很好,直到我收到了无处不在的分割错误,现在无法摆脱它。谁能发现这个分割错误并解释给我听?
注:虽然这是一项作业,但我不是来这里寻找答案的。事实上,我甚至不会提及分配的细节,甚至不会发送完整的代码(尽管,下面的代码也会导致段错误):
# include <stdio.h>
# include <stdlib.h>
# ifdef __APPLE__
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
# include <GLUT/glut.h>
# else
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/freeglut.h>
# endif
# include <iostream>
# include <ctime>
# include <cmath>
using namespace std;
#define GRID 50
/* Eye location */
float eye[]={5,5,5};
void initDefaults(void){
glClearColor(0, 0, 0, 0);
glColor3f(1, 1, 1);
glMatrixMode(GL_PROJECTION);
glFrustum(-10,10,-10,10,0,100);
gluPerspective(45,1,1,100);
}
/* TEMPORARY */
void createGrid(){
//After checking, I narrowed down the segmentation fault to here.
glColor3f(0, 0, 0);
printf("help");
glBegin(GL_POINTS);
glVertex3f(25,25,25);
glEnd();
}
/* displays UI to user */
void display(void){
//Clears the board upon (re)display
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
//Enables backface culling
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//Sets up the perspective matrix (viewing/camera)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye[0], eye[1], eye[2], GRID/2, GRID/2, 0, 0, 1, 0);
//I believe the segmentation fault occurs in here.
//************************************
createGrid();
//************************************
//Used for double-buffering
glutSwapBuffers();
}
/* main function - program entry point */
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitWindowSize(600, 600);
glutInitWindowPosition(200,200);
glutCreateWindow("Terrain");
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
glutDisplayFunc(display);
gluOrtho2D(-1, GRID + 1, -1, GRID + 1);
initDefaults();
glutMainLoop();
return(0);
}
再次检查您的开发环境。您的代码(到目前为止)非常好,您遇到的问题可能是由于库不匹配造成的。例如,如果您在Linux上开发,libGL.so
必须完全匹配GPU驱动程序和版本(或使用纯粹间接的GLX上下文,这通常只发生在远程X11上)。
相关文章:
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 如何在C++中从字符串中分割字符
- C++映射分割错误(核心转储)
- 了解 GLM- openGL 中的相机转换
- 如何在全屏模式下(在OpenGL中)使背景透明
- 为什么我不能使用 EGL 创建无头 OpenGl 上下文?
- OpenGL大的3D纹理(>2GB)非常慢
- OpenGl glm rotate
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- C++为线程工作动态地分割例程
- OpenGL在启用深度测试时不会丢弃我的碎片
- OpenGL相机和相机空间转型的困惑
- OpenGL将纹理四边形渲染为(0,0)
- OpenGL 和 GLM 矩阵无法正确扩展,总是按比例缩小
- 发布旋转矩阵(openGL/glm)
- 由cin中的字符串中未捕获空白引起的分割错误
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 输入glBegin()后OpenGL分割错误
- OpenGL分割故障
- 为什么这个OpenGL Shader分割错误调用glCreateShader