Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C+中开始使用OpenGL+;_C++_Eclipse_Opengl - Fatal编程技术网

C++ 在C+中开始使用OpenGL+;

C++ 在C+中开始使用OpenGL+;,c++,eclipse,opengl,C++,Eclipse,Opengl,我已尝试使用OpenGl开始编程,目前为止,我已获得以下代码: #include <gl/glut.h> // Include the GLUT header file void display (void) { } int main(int argc, char **argv) { glutInit(&argc, argv); // Initialize GLUT // Set up a basic display buffer (only single

我已尝试使用OpenGl开始编程,目前为止,我已获得以下代码:

#include <gl/glut.h> // Include the GLUT header file

void display (void)
{
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv); // Initialize GLUT
    // Set up a basic display buffer (only single buffered for now)
    glutInitDisplayMode (GLUT_SINGLE);
    glutInitWindowSize (500, 500); // Set the width and height of the window
    glutInitWindowPosition (100, 100); // Set the position of the window
    // Set the title for the window
    glutCreateWindow("Your first OpenGL Window!");

    glutDisplayFunc(display);
    glutMainLoop();
    glClearColor(1.f, 0.f, 0.f, 1.f); // Clear the background of our window to red

    return 0;
}
#include//include GLUT头文件
作废显示(作废)
{
}
int main(int argc,字符**argv)
{
glutInit(&argc,argv);//初始化GLUT
//设置一个基本的显示缓冲区(目前只有一个缓冲区)
glutInitDisplayMode(GLUT_单个);
GLUTINITWindowsSize(500500);//设置窗口的宽度和高度
glutInitWindowPosition(100100);//设置窗口的位置
//设置窗口的标题
glutCreateWindow(“您的第一个OpenGL窗口!”);
glutDisplayFunc(显示器);
glutMainLoop();
glClearColor(1.f,0.f,0.f,1.f);//将窗口的背景清除为红色
返回0;
}
我在Eclipse中构建并运行该项目,它编译得很好,但什么也没发生(没有windows弹出窗口或任何东西)。谁能告诉我我做错了什么

glutInitDisplayMode (GLUT_SINGLE);
您还需要定义所需的帧缓冲区格式,即至少添加一个
GLUT\u RGBA
(您可能还需要一个深度缓冲区)。只有少数情况下不需要双缓冲区。所以:
glutInitDisplayMode(GLUT_RGBA | GLUT_深度| GLUT_双精度)

然后将不会调用显示函数,除非添加
glutDisplayFunc(显示)
createwindow
之后

glutMainLoop();
glClearColor(1.f, 0.f, 0.f, 1.f);
GLUTmain循环不会返回。即使有,glClearColor在程序中的那个位置也没有效果

您还需要定义所需的帧缓冲区格式,即至少添加一个
GLUT\u RGBA
(您可能还需要一个深度缓冲区)。只有少数情况下不需要双缓冲区。所以:
glutInitDisplayMode(GLUT_RGBA | GLUT_深度| GLUT_双精度)

然后将不会调用显示函数,除非添加
glutDisplayFunc(显示)
createwindow
之后

glutMainLoop();
glClearColor(1.f, 0.f, 0.f, 1.f);

GLUTmain循环不会返回。即使是这样,glClearColor在程序中的该位置也没有效果。

添加一条打印语句以确保代码实际运行。添加一条打印语句以确保代码实际运行。