2011-08-19 83 views
0

我想在OpenGL中編程。Fedora 15上的OpenGL

所以寫了一個測試程序調用t_gl1.cpp

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

沒有任何錯誤建的成功。

但是,如果我嘗試運行它,我得到了

freeglut(./t_gl1):錯誤:在功能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 
} 
+0

你真正應該使用'過剩*()'函數;他們更便攜。這可能是你的問題。 – Bojangles

+0

我做到了。我從來沒有稱這個「fgOpenWindow」,它必須被過度稱爲(freeglut) –

+1

哦。我的錯。你可以發佈這個問題的代碼(或其中的一部分,如果它很長)? – Bojangles

回答

0

運行,因爲您標記這個問題cuda我會假設你正在運行NVIDIA的顯卡。

嘗試installing some drivers

+0

是的,我正在運行CUDA開發驅動程序。 sudo less/proc/driver/nvidia/version,顯示「NVRM版本:NVIDIA®(英偉達™)UNIX x86內核模塊280.13 Wed Jul 27 16:55:43 PDT 2011」 –

1

代碼沒有問題。我可以成功地編譯並在一個配置了NVIDIA®(英偉達™)280.13版驅動程序的64位Linux系統上運行它。您有一個驅動程序或X11驅動程序安裝或配置問題。這個問題不需要編程幫助。

2

我同意talonmies。這是因爲Nvidia的問題。我找不到在Fedora 15上安裝Nvidia開發者驅動程序的正式方法。所以我使用了rpmfusion。驅動程序運行,我可以運行CUDA。只有GLX相關的東西搞砸了。但是,它也搞砸了侏儒3.

所以我切換到Arch Linux。隨着一個乾淨的開始,安裝Nvida並根據ArchWiki安裝Xorg。然後安裝Gnome。令人驚訝的是,OpenGL的作品。我猜Arch購物中心的司機不是開發者的驅動程序。也許只是顯示驅動程序。但是,CUDA的作品。

我很高興。希望這對於那些想在Linux上運行CUDA和OpenGL的人有所幫助。

感謝, 阿爾弗雷德

+1

請務必接受此答案,以便此問題不再顯示作爲「未答覆」。 –