2015-01-14 158 views
-2

嘗試在OSX Yosemite上使用xCode運行示例OpenGL C++程序。Mac上的OpenGL C++構建失敗未找到'GL/glut.h'文件

運行程序時,我得到 'GL/glut.h' 找不到文件截圖:

'GL/glut.h' file not found

不過,我確實有該項目的glut.h頭:

glut.h header in the project

在一個單獨的論壇上,我看,它應該是「GLUT/glut.h」所以我做了,但得到了以下信息:

GLUT/glut.h

我需要做什麼才能讓OpenGL與C++配置?

這是我試圖運行的代碼。如果我可以運行它,那麼我應該把一切都準備去:

#include <GLUT/glut.h> 
#include <math.h> 
//#include <stdlib.h> 

const double TWO_PI = 6.2831853; 

/* Initial display-window size. */ 
GLsizei winWidth = 400, winHeight = 400; 
GLuint regHex; 

class screenPt 
{ 
private: 
    GLint x, y; 

public: 
    /* Default Constructor: initializes coordinate position to (0, 0). */ 
    screenPt () { 
     x = y = 0; 
    } 

    void setCoords (GLint xCoord, GLint yCoord) { 
     x = xCoord; 
     y = yCoord; 
    } 

    GLint getx () const { 
     return x; 
    } 

    GLint gety () const { 
     return y; 
    } 
}; 

static void init (void) 
{ 
    screenPt hexVertex, circCtr; 
    GLdouble theta; 
    GLint k; 

    /* Set circle center coordinates. */ 
    circCtr.setCoords (winWidth/2, winHeight/2); 

    glClearColor (1.0, 1.0, 1.0, 0.0); // Display-window color = white. 

    /* Set up a display list for a red regular hexagon. 
    * Vertices for the hexagon are six equally spaced 
    * points around the circumference of a circle. 
    */ 
    regHex = glGenLists (1); // Get an identifier for the display list. 
    glNewList (regHex, GL_COMPILE); 
    glColor3f (1.0, 0.0, 0.0); // Set fill color for hexagon to red. 
    glBegin (GL_POLYGON); 
    for (k = 0; k < 6; k++) { 
     theta = TWO_PI * k/6.0; 
     hexVertex.setCoords (circCtr.getx () + 150 * cos (theta), 
          circCtr.gety () + 150 * sin (theta)); 
     glVertex2i (hexVertex.getx (), hexVertex.gety ()); 
    } 
    glEnd (); 
    glEndList (); 
} 

void regHexagon (void) 
{ 
    glClear (GL_COLOR_BUFFER_BIT); 

    glCallList (regHex); 

    glFlush (); 
} 

void winReshapeFcn (int newWidth, int newHeight) 
{ 
    glMatrixMode (GL_PROJECTION); 
    glLoadIdentity (); 
    gluOrtho2D (0.0, (GLdouble) newWidth, 0.0, (GLdouble) newHeight); 

    glClear (GL_COLOR_BUFFER_BIT); 
} 

void main (int argc, char** argv) 
{ 
    glutInit (&argc, argv); 
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowPosition (100, 100); 
    glutInitWindowSize (winWidth, winHeight); 
    glutCreateWindow ("Reshape-Function & Display-List Example"); 

    init (); 
    glutDisplayFunc (regHexagon); 
    glutReshapeFunc (winReshapeFcn); 

    glutMainLoop (); 
} 

回答

1

當你把它改爲「GLUT/glut.h`它找到正確的頭。不幸的是,現在您可以獲得有關棄用函數的所有警告消息。

對於已過時的功能的消息的修復看到xcode 5 deprecation warning about glut functionsGlut deprecation in Mac OSX 10.9, IDE: QT Creator

您也有一個錯誤信息說你的主函數需要返回一個int。這會阻止您的代碼編譯,而不是警告。

編輯 你應該改變你的主函數有一個返回類型的int。

int main(int argc, char *argv[]) 
{ 
    /* code */ 
    return 0; 
} 

有些編譯器會接受void作爲main的返回類型,但這是一個非標準的擴展。

+0

所以這是一個OSX的問題?另外,如果我返回0它說它不應該返回一個值。 –

+0

是的,在OSX 10.9中,他們已經棄用了這些功能。意思是他們會在某個時候刪除它們,並不真正希望你使用它們。我不確定你的主要功能有什麼問題,你可以發佈代碼嗎? –

+0

更新的問題。 –

相關問題