首页 > 解决方案 > OpenGL项目崩溃

问题描述

屏幕截图 此代码编译时没有错误或警告,但无法运行,应用程序立即崩溃。

#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,当我在调试模式下运行时出现分段错误

标签: c++openglglutopengl-compat

解决方案


推荐阅读