Fedora 15 上的 OpenGL

发布于 2024-11-30 06:50:23 字数 4367 浏览 3 评论 0原文

我正在尝试使用 OpenGL 进行编程。

所以编写了一个测试程序调用 t_gl1.cpp

我用

$ g++ t_gl1.cpp -lglut -lGL -lGLU -o t_gl1

成功构建了它,没有任何错误。

但是,如果我尝试运行它,我会得到

freeglut (./t_gl1): ERROR: Internal error in function fgOpenWindow X 请求失败错误:BadWindow(窗口参数无效) 失败请求的主要操作码:4 (X_DestroyWindow) 失败请求中的资源 ID:0x0 失败请求的序列号:26 输出流中的当前序列号:29

有谁知道发生了什么事吗?

这是代码,在Windows和Mac上测试过,没有问题。但无法在 Fedora 和 Ubuntu 上运行

#include <iostream>
#include <stdlib.h> 

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, //The key that was pressed
                int x, int y) {    //The current mouse coordinates
    switch (key) {
        case 27: //Escape key
            exit(0); //Exit the program
    }
}

//Initializes 3D rendering
void initRendering() {
    //Makes 3D drawing work when something is in front of something else
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_COLOR_MATERIAL); //NEW OF THIS
    glClearColor(0.7f,0.9f,1.0f,1.0f); //background, last number to be 1.0f
}

//Called when the window is resized
void handleResize(int w, int h) {
    //Tell OpenGL how to convert from coordinates to pixel values
    glViewport(0, 0, w, h);

    glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective

    //Set the camera perspective
    glLoadIdentity(); //Reset the camera
    gluPerspective(45.0,                  //The camera angle
                   (double)w / (double)h, //The width-to-height ratio
                   1.0,                   //The near z clipping coordinate
                   200.0);                //The far z clipping coordinate
}

float _angle=30.0f; //kinda global variable


//Draws the 3D scene
void drawScene() {
    //Clear information from last draw
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
    glLoadIdentity(); //Reset the drawing perspective

    glTranslatef(0.0f,0.0f,-5.0f);


    glPushMatrix();

    glRotatef(_angle, 0.0f, 1.0f , 0.0f);

    glColor3f(0.5f,0.0f,0.8f);
    glBegin(GL_QUADS); //Begin quadrilateral coordinates

    //Trapezoid

    glVertex3f(-0.7f, -1.5f, 0.0f);
    glVertex3f(0.7f, -1.5f, 0.0f);
    glVertex3f(0.4f, -0.5f, 0.0f);
    glVertex3f(-0.4f, -0.5f, 0.0f);

    glEnd(); //End quadrilateral coordinates
    glPopMatrix();



    glPushMatrix(); //push
    glRotatef(_angle, 1.0f, 0.0f, 0.0f);

    glBegin(GL_TRIANGLES); //Begin triangle coordinates Begin Pentagon
    glColor3f(1.0f,0.0f,0.0f);
    //Pentagon
    glVertex3f(0.5f, 0.5f, -0.0f);
    glVertex3f(1.5f, 0.5f, -0.0f);
    glVertex3f(0.5f, 1.0f, -0.0f);

    glVertex3f(0.5f, 1.0f, -0.0f);
    glVertex3f(1.5f, 0.5f, -0.0f);
    glVertex3f(1.5f, 1.0f, -0.0f);

    glVertex3f(0.5f, 1.0f, -0.0f);
    glVertex3f(1.5f, 1.0f, -0.0f);
    glVertex3f(1.0f, 1.5f, -0.0f);

    glEnd(); //end Pentagon
    glPopMatrix(); //pop

    glPushMatrix();

    glRotatef(_angle, -1.0f, 1.0f, 0.0f);

    glBegin(GL_TRIANGLES);

    //Triangle
    glVertex3f(-0.5f, 0.5f, 0.0f);
    glColor3f(0.0f, 1.0f, 0.0f);
    glVertex3f(-1.0f, 1.5f, -0.0f);
    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex3f(-1.5f, 0.5f, -0.0f);

    glEnd(); //End triangle coordinates
    glPopMatrix();

    glutSwapBuffers(); //Send the 3D scene to the screen
}

void update(int value)
{
    _angle+=2.0f;
    if(_angle>360)
        _angle-=360;
    glutPostRedisplay();
    glutTimerFunc(25,update,0);
}

int main(int argc, char** argv) {
    //Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(400, 400); //Set the window size

    //Create the window
    glutCreateWindow("window");
    initRendering(); //Initialize rendering

    //Set handler functions for drawing, keypresses, and window resizes
    glutDisplayFunc(drawScene); //display the "drwwScene" most important part, others are settings
    glutKeyboardFunc(handleKeypress);
    glutReshapeFunc(handleResize);

    glutTimerFunc(25,update,0); //add the timer function to make animation

    glutMainLoop(); //Start the main loop.  glutMainLoop doesn't return.
    return 0; //This line is never reached
}

I am trying to program in OpenGL.

so wrote a test program call t_gl1.cpp

I built it successfully with

$ g++ t_gl1.cpp -lglut -lGL -lGLU -o t_gl1

No any error.

However, if I try to run it, I got

freeglut (./t_gl1): ERROR: Internal error in function fgOpenWindow
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 4 (X_DestroyWindow)
Resource id in failed request: 0x0
Serial number of failed request: 26
Current serial number in output stream: 29

Does any one know what is going on?

Here is the code, tested on Windows and Mac, no problem. But can't get it run on Fedora nor Ubuntu

#include <iostream>
#include <stdlib.h> 

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, //The key that was pressed
                int x, int y) {    //The current mouse coordinates
    switch (key) {
        case 27: //Escape key
            exit(0); //Exit the program
    }
}

//Initializes 3D rendering
void initRendering() {
    //Makes 3D drawing work when something is in front of something else
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_COLOR_MATERIAL); //NEW OF THIS
    glClearColor(0.7f,0.9f,1.0f,1.0f); //background, last number to be 1.0f
}

//Called when the window is resized
void handleResize(int w, int h) {
    //Tell OpenGL how to convert from coordinates to pixel values
    glViewport(0, 0, w, h);

    glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective

    //Set the camera perspective
    glLoadIdentity(); //Reset the camera
    gluPerspective(45.0,                  //The camera angle
                   (double)w / (double)h, //The width-to-height ratio
                   1.0,                   //The near z clipping coordinate
                   200.0);                //The far z clipping coordinate
}

float _angle=30.0f; //kinda global variable


//Draws the 3D scene
void drawScene() {
    //Clear information from last draw
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
    glLoadIdentity(); //Reset the drawing perspective

    glTranslatef(0.0f,0.0f,-5.0f);


    glPushMatrix();

    glRotatef(_angle, 0.0f, 1.0f , 0.0f);

    glColor3f(0.5f,0.0f,0.8f);
    glBegin(GL_QUADS); //Begin quadrilateral coordinates

    //Trapezoid

    glVertex3f(-0.7f, -1.5f, 0.0f);
    glVertex3f(0.7f, -1.5f, 0.0f);
    glVertex3f(0.4f, -0.5f, 0.0f);
    glVertex3f(-0.4f, -0.5f, 0.0f);

    glEnd(); //End quadrilateral coordinates
    glPopMatrix();



    glPushMatrix(); //push
    glRotatef(_angle, 1.0f, 0.0f, 0.0f);

    glBegin(GL_TRIANGLES); //Begin triangle coordinates Begin Pentagon
    glColor3f(1.0f,0.0f,0.0f);
    //Pentagon
    glVertex3f(0.5f, 0.5f, -0.0f);
    glVertex3f(1.5f, 0.5f, -0.0f);
    glVertex3f(0.5f, 1.0f, -0.0f);

    glVertex3f(0.5f, 1.0f, -0.0f);
    glVertex3f(1.5f, 0.5f, -0.0f);
    glVertex3f(1.5f, 1.0f, -0.0f);

    glVertex3f(0.5f, 1.0f, -0.0f);
    glVertex3f(1.5f, 1.0f, -0.0f);
    glVertex3f(1.0f, 1.5f, -0.0f);

    glEnd(); //end Pentagon
    glPopMatrix(); //pop

    glPushMatrix();

    glRotatef(_angle, -1.0f, 1.0f, 0.0f);

    glBegin(GL_TRIANGLES);

    //Triangle
    glVertex3f(-0.5f, 0.5f, 0.0f);
    glColor3f(0.0f, 1.0f, 0.0f);
    glVertex3f(-1.0f, 1.5f, -0.0f);
    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex3f(-1.5f, 0.5f, -0.0f);

    glEnd(); //End triangle coordinates
    glPopMatrix();

    glutSwapBuffers(); //Send the 3D scene to the screen
}

void update(int value)
{
    _angle+=2.0f;
    if(_angle>360)
        _angle-=360;
    glutPostRedisplay();
    glutTimerFunc(25,update,0);
}

int main(int argc, char** argv) {
    //Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(400, 400); //Set the window size

    //Create the window
    glutCreateWindow("window");
    initRendering(); //Initialize rendering

    //Set handler functions for drawing, keypresses, and window resizes
    glutDisplayFunc(drawScene); //display the "drwwScene" most important part, others are settings
    glutKeyboardFunc(handleKeypress);
    glutReshapeFunc(handleResize);

    glutTimerFunc(25,update,0); //add the timer function to make animation

    glutMainLoop(); //Start the main loop.  glutMainLoop doesn't return.
    return 0; //This line is never reached
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

几度春秋 2024-12-07 06:50:23

我同意塔隆米斯的观点。
这是因为 Nvidia 的问题。我找不到在 Fedora 15 上安装 Nvidia 开发人员驱动程序的官方方法。所以我使用了 rpmfusion。驱动程序运行了,我就可以运行CUDA了。只有 GLX 相关的东西才被搞乱。然而,它也搞乱了 Gnome 3。

所以我转而使用 Arch Linux。有了一个干净的开始,安装 Nvida 并根据 ArchWiki 安装 Xorg。然后安装 Gnome。令人惊奇的是,OpenGL 竟然可以工作。我猜Arch repo 中的驱动程序不是开发人员的驱动程序。也许只是用于显示驱动程序。然而,CUDA 可以工作。

我对此很高兴。希望这对那些想要在 Linux 上运行 CUDA 和 OpenGL 的人有所帮助。

谢谢,
阿尔弗雷德

I aggreed with talonmies.
It was because of the Nvidia problem. I could't find a official way to install Nvidia's developer's driver on Fedora 15. So I used rpmfusion. The driver runs and I can run CUDA. Only GLX related stuff are messed up. However, it also messed up Gnome 3.

So I switched to Arch Linux. With a much clean start, install Nvida and install Xorg according to the ArchWiki. And then install Gnome. Amazingly, OpenGL works. I guess the driver in Arch repo is not the developer's driver. Maybe just for display driver. However, CUDA works.

I am glad with that. And hopefully this will be helpful to some one else who want to run CUDA and OpenGL on Linux.

Thanks,
Alfred

吐个泡泡 2024-12-07 06:50:23

代码没有任何问题。我可以在正确配置的 64 位 Linux 系统上使用 NVIDIA 版本 280.13 驱动程序成功编译并运行它。您有驱动程序或 X11 驱动程序安装或配置问题。此问题不需要编程帮助。

There is nothing wrong with the code. I can successfully compile and run it on a properly configured 64 bit linux system with NVIDIA release 280.13 drivers. You have a driver or X11 driver installation or configuration problem. There is no programming help required for this question.

失退 2024-12-07 06:50:23

既然您标记了这个问题 cuda,我将假设您正在运行 NVidia 硬件。

尝试安装一些驱动程序

Since you tagged this question cuda I'm going to assume you're running NVidia hardware.

Try installing some drivers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文