OpenGL项目崩溃

时间:2019-07-15 16:30:23

标签: c++ opengl glut opengl-compat

Screenshot 该代码编译时没有错误或警告,但无法运行,应用程序立即崩溃。

#include <GL/glut.h>

int WinWidth  = 640,
 WinHeight = 480;
int WinFar   = 10;

void DrawPoint(float x, float y)
{
 glColor3f(1.0, 1.0, 1.0);
 glBegin(GL_POINTS);
  glVertex2f(x, y);
 glEnd();
}

void display()
{
 glClear(GL_COLOR_BUFFER_BIT);
 //Draws
 DrawPoint(0, 0);
 //
 glFlush();
}

int main(int argc, char** argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
 glutInitWindowSize(WinWidth, WinHeight);
 glutInitWindowPosition(150, 150);
 glutCreateWindow("Lesson 01");
 glClearColor(0, 0, 0, 1.0);

 glOrtho(-WinWidth/2, WinWidth/2, WinHeight/2, -WinHeight/2, -WinFar/2, WinFar/2);
 glutDisplayFunc(display);

 glutMainLoop();
 return 0;
}

它崩溃,返回值3221225477。我在做什么错了?

程序收到信号SIGEGV,分段错误 当我在调试模式下运行它时

0 个答案:

没有答案