glewInit()在macOS上失败 [英] glewInit() fails on macOS

查看:115
本文介绍了glewInit()在macOS上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一段代码可以在ubuntu机器上很好地运行,但是不能在xcode或终端上执行.我正在尝试在xcode上运行它,但是在main上却失败了,

So I have a piece of code that runs fine on ubuntu machine, but fails to do so on xcode or via terminal. I'm trying to run it on xcode, but it fails on main with:

使用未声明的标识符glewInit;您的意思是glutInit吗?" 函数调用的参数太少,预期为2,为0"

"Use of undeclared identifier glewInit; did you mean glutInit?" "Too few argument to function call, expected 2, have 0"

该代码很长,是由我的教授编写的,可以在ubuntus上运行.但是由于有错误,我认为原因是...好吧,声明不足的标识符,include丢失了.因此,在谷歌搜索之后,我发现glewInit是glew库的一部分->因此,我下载了代码并将其安装在我的机器上,如下所示:

The code is lengthy is been written by my professor and it runs on ubuntus. But with the errors, I'm thinking that the reasons is...well, underclared identifier, include is missing. So, after googling I figured out that glewInit is part of the glew library -> so I downloaded the code and installed it on my machine with following:

制作 须藤-s 进行安装

make sudo -s make install

已成功安装到我的/usr/include/GL中.现在,当我输入xcode #include或只是#include时,编译器将抛出glew.h找不到(尽管我自己可以在usr/include/GL中看到该文件).

which were successfully installed into my /usr/include/GL. Now, when i type into xcode #include or just #include , the compiler throws that glew.h is not found (though i can i see the file myself in the usr/include/GL).

这是代码:

#include "include/Angel.h"

// The rotation  around z axis
GLfloat  Theta = 0.0; // Angle (in degrees)
GLfloat  step = 0.01; // Incremental
GLuint  locTheta;  
enum { CW = 0, CCW = 1};
int direction = CW;  // Direction

//Scale along x and y axes
GLfloat ScaleFactor[2] = {1.0, 1.0};
GLuint locScale;

const int NumPoints = 4;
void init();
void display( void );
void reshape( GLsizei w, GLsizei h );
void keyboard( unsigned char key, int x, int y );
void mouse( int button, int state, int x, int y );
void idle( void );
//----------------------------------------------------------------------------

// OpenGL initialization
void init()
{
    // Vertices of a unit square centered at origin, sides aligned with axes
    vec4 points[] = {
        vec4( -0.5, -0.5,  0, 1.0 ), //v1
        vec4(  0.5, -0.5,  0, 1.0 ), //v2
        vec4( -0.5,  0.5,  0, 1.0 ), //v3
        vec4(  0.5,  0.5,  0, 1.0 )  //v4
    };

    // RGBA colors
    vec4 colors[] = {
        vec4( 1.0, 0.0, 0.0, 1.0 ),  // red
        vec4( 0.0, 1.0, 0.0, 1.0 ),  // green
        vec4( 0.0, 1.0, 0.0, 1.0 ),  // green
        vec4( 0.0, 0.0, 1.0, 1.0 ),  // blue
    };

    // Create and initialize a buffer object
    GLuint buffer;
    glGenBuffers( 1, &buffer );
    glBindBuffer( GL_ARRAY_BUFFER, buffer );
    glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors), NULL, GL_STATIC_DRAW );
    glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points );
    glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors );

    // Load shaders and use the resulting shader program
    GLuint program = InitShader( "vshader_rot.glsl", "fshader_rot.glsl" );
    glUseProgram( program );

    // set up vertex arrays
    GLuint vPosition = glGetAttribLocation( program, "vPosition" );
    glEnableVertexAttribArray( vPosition );
    glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
               BUFFER_OFFSET(0) );

    GLuint vColor = glGetAttribLocation( program, "vColor" ); 
    glEnableVertexAttribArray( vColor );
    glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0,
               BUFFER_OFFSET(sizeof(points)) );

    // The location of shader uniform variables
    locTheta = glGetUniformLocation( program, "theta" );
    locScale = glGetUniformLocation( program, "scale" );

    glClearColor( 1.0, 1.0, 1.0, 1.0 );
}

//----------------------------------------------------------------------------

void display( void )
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glUniform1f( locTheta, Theta );
    glUniform2fv( locScale, 1, ScaleFactor );

    glDrawArrays( GL_TRIANGLE_STRIP, 0, NumPoints);

    glutSwapBuffers();
}

//----------------------------------------------------------------------------
void reshape( GLsizei w, GLsizei h )
{
    glViewport(0, 0, w, h);

    // Scale the square to avoid stretching
    if (w > h) ScaleFactor[0] = (float)h/w;
    if (w < h) ScaleFactor[1] = (float)w/h;
}

//----------------------------------------------------------------------------

void keyboard( unsigned char key, int x, int y )
{
    switch( key ) {
    case 033: // Escape Key
    case 'q': case 'Q':
        exit( EXIT_SUCCESS );
        break;
    }
}

//----------------------------------------------------------------------------

void mouse( int button, int state, int x, int y )
{
    if ( state == GLUT_DOWN ) {
        switch( button ) 
        {
        case GLUT_LEFT_BUTTON:    
            direction = CCW;  
            break;
        case GLUT_RIGHT_BUTTON:   
            direction = CW;  
            break;
        }
    }
}

//----------------------------------------------------------------------------

void idle( void )
{
    // Animate the rotation
    if (direction == CW)    
        Theta += step;
    else
        Theta -= step;

    if ( Theta > 360.0 ) {
        Theta -= 360.0;
    }

    glutPostRedisplay();
}

//----------------------------------------------------------------------------

int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
    glutInitWindowSize( 512, 512 );
    glutCreateWindow( "Rotating Color Square" );

    glewInit();
    init();

    glutDisplayFunc( display );
    glutReshapeFunc( reshape );
    glutKeyboardFunc( keyboard );
    glutMouseFunc( mouse );
    glutIdleFunc( idle );

    glutMainLoop();
    return 0;
}

我有Lion 10.7.4和xCode 4.2.1

I have Lion 10.7.4 and xCode 4.2.1

推荐答案

glewInit()调用(当然包括),因此您可以通过以下方式将其排除:

glewInit() call (and the includes, of course) is not necessary on MacOS, so you might just exclude it this way:

#ifndef __APPLE__
glewInit();
#endif

与包含相同.

现在带有未解决的符号.您必须包括MacOSX的本机GL标头:

Now with the unresolved symbols. You have to include MacOSX's native GL headers:

#ifdef __APPLE__
#  include <OpenGL/gl.h>
#  include <OpenGL/glext.h>
#else /// your stuff for linux
#  include "GL/GL.h"
.... whatever
#endif

OpenGL是OSX的核心技术,而不是Linux/X Window中的扩展".因此,只需将OpenGL和GLUT框架包括到您的XCode项目中,并希望它可以构建并运行.

OpenGL is a core technology for OSX, not an "extension", as in Linux/X Window. So just include the OpenGL and GLUT framework to your XCode project and hopefully it should build and work.

这篇关于glewInit()在macOS上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆