【问题标题】:OpenGL on Fedora 15Fedora 15 上的 OpenGL
【发布时间】:2011-08-19 20:37:09
【问题描述】:

我正在尝试在 OpenGL 中编程。

于是写了一个测试程序调用t_gl1.cpp

我成功构建了它

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

没有任何错误。

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

freeglut (./t_gl1): 错误: 函数 fgOpenWindow 中的内部错误 失败请求的 X 错误:BadWindow(无效的 Window 参数) 失败请求的主要操作码: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
}

【问题讨论】:

  • 你真的应该使用glut*()函数;它们更便携。这可能是你的问题。
  • 我做到了。我从来不把这个叫做“fgOpenWindow”,它一定是被过剩(freeglut)调用的
  • 哦,对了。我的错。您可以发布与此问题相关的代码(或部分代码,如果它很长)吗?
  • glxinfo 返回“错误:找不到 RGB GLX 视觉或 fbconfig”
  • @Alfred Zhong:这个错误信息基本上告诉你,你的驱动程序没有正确安装。 NVidia 驱动需要一对匹配的 Xorg/GLX 驱动模块和 Linux 内核模块。如果它们不匹配,则不会加载 OpenGL 驱动程序。

标签: opengl glut fedora freeglut


【解决方案1】:

我同意 talonmies。 这是因为 Nvidia 的问题。我找不到在 Fedora 15 上安装 Nvidia 开发者驱动程序的官方方法。所以我使用了 rpmfusion。驱动程序运行,我可以运行 CUDA。只有 GLX 相关的东西被搞砸了。但是,它也搞砸了 Gnome 3。

所以我切换到 Arch Linux。一个非常干净的开始,根据 ArchWiki 安装 Nvida 并安装 Xorg。然后安装 Gnome。令人惊讶的是,OpenGL 可以工作。我猜 Arch repo 中的驱动程序不是开发人员的驱动程序。也许只是为了显示驱动程序。但是,CUDA 可以工作。

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

谢谢, 阿尔弗雷德

【讨论】:

  • 一定要接受这个答案,这样这个问题就不会再显示为“未回答”。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    试试installing some drivers

    【讨论】:

    • 是的,我正在运行 CUDA 开发驱动程序。 sudo less /proc/driver/nvidia/version,显示“NVRM 版本:NVIDIA UNIX x86 内核模块 280.13 Wed Jul 27 16:55:43 PDT 2011”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多