Xcode 函数的隐式声明';glBindVertexArrayOES';在c99中无效

Xcode 函数的隐式声明';glBindVertexArrayOES';在c99中无效,xcode,Xcode,因此,我正在为iPhone和iPad构建一个系统监控应用程序。每当我试图编译应用程序时,我都会收到一个错误,上面说“函数'glBindVertexArrayOES'的隐式声明在c99中无效” 这就是代码的其余部分 GLKVector3 position = GLKVector3Make(x, y, 0.0); GLKVector3 rotation = GLKVector3Make(0.0, 0.0, 0.0); GLKMatrix4 scale

因此,我正在为iPhone和iPad构建一个系统监控应用程序。每当我试图编译应用程序时,我都会收到一个错误,上面说“函数'glBindVertexArrayOES'的隐式声明在c99中无效”

这就是代码的其余部分

        GLKVector3 position = GLKVector3Make(x, y, 0.0);
        GLKVector3 rotation = GLKVector3Make(0.0, 0.0, 0.0);
        GLKMatrix4 scale = GLKMatrix4MakeScale(xScale, yScale, 1.0);
        GLKMatrix4 modelMatrix = [GLCommon modelMatrixWithPosition:position rotation:rotation scale:scale];

        self.graph.effect.transform.modelviewMatrix = modelMatrix;
        self.graph.effect.texture2d0.enabled = GL_TRUE;
        self.graph.effect.texture2d0.target = GLKTextureTarget2D;
        self.graph.effect.texture2d0.name = self.lineLegendIconTexture.name;
        self.graph.effect.texture2d0.envMode = GLKTextureEnvModeReplace;
        [self.graph.effect prepareToDraw];

        glDrawArrays(GL_TRIANGLE_STRIP, 0, sizeof(lineLegendData) / sizeof(VertexData_t));
    }

    /*
     * Text
     */
    if (self.lineLegendTextTexture)
    {
        GLfloat x = self.graph.graphRight - 5.0 - (lineIndex * 9.0);
        GLfloat y = self.graph.graphBottom - 1.0;
        GLfloat xScale = self.lineLegendTextTexture.width * kFontScaleMultiplierW;
        GLfloat yScale = self.lineLegendTextTexture.height * kFontScaleMultiplierH;

        glBindVertexArrayOES(self.glVertexArrayLineLegend);

        GLKVector3 position = GLKVector3Make(x, y, 0.0);
        GLKVector3 rotation = GLKVector3Make(0.0, 0.0, 0.0);
        GLKMatrix4 scale = GLKMatrix4MakeScale(xScale, yScale, 1.0);
        GLKMatrix4 modelMatrix = [GLCommon modelMatrixWithPosition:position rotation:rotation scale:scale];

        self.graph.effect.transform.modelviewMatrix = modelMatrix;
        self.graph.effect.texture2d0.enabled = GL_TRUE;
        self.graph.effect.texture2d0.target = GLKTextureTarget2D;
        self.graph.effect.texture2d0.name = self.lineLegendTextTexture.name;
        self.graph.effect.texture2d0.envMode = GLKTextureEnvModeReplace;
        [self.graph.effect prepareToDraw];

        glDrawArrays(GL_TRIANGLE_STRIP, 0, sizeof(lineLegendData) / sizeof(VertexData_t));
    }
}

- (NSUInteger)maxDataLineElements
{
    return self.dataLineDataSize;
}

- (void)setDataLineZoom:(GLfloat)aZoom
{
    self.zoom = aZoom;
}

#pragma mark - private

- (void)setupVBO
{
    /*
     * Data line.
     */
    {
下一行还会抛出相同的c99错误

        glGenVertexArraysOES(1, &_glVertexArrayDataLine);
另一个代码如下:

        glBindVertexArrayOES(self.glVertexArrayDataLine);

        glGenBuffers(1, &_glBufferDataLine);
        glBindBuffer(GL_ARRAY_BUFFER, self.glBufferDataLine);
        glBufferData(GL_ARRAY_BUFFER, self.dataLineDataValidSize * sizeof(VertexData_t), _dataLineData, GL_DYNAMIC_DRAW);

        glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData_t),
                              NULL + offsetof(VertexData_t, positionCoords));
        glEnableVertexAttribArray(GLKVertexAttribPosition);

        GL_CHECK_ERROR();
    }

    /*
     * Line legend.
     */
    {
        glGenVertexArraysOES(1, &_glVertexArrayLineLegend);
        glBindVertexArrayOES(self.glVertexArrayLineLegend);

        glGenBuffers(1, &_glBufferLineLegend);
        glBindBuffer(GL_ARRAY_BUFFER, self.glBufferLineLegend);
        glBufferData(GL_ARRAY_BUFFER, sizeof(lineLegendData), lineLegendData, GL_STATIC_DRAW);

        glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData_t),
                              NULL + offsetof(VertexData_t, positionCoords));
        glEnableVertexAttribArray(GLKVertexAttribPosition);

        glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData_t),
                              NULL + offsetof(VertexData_t, textureCoords));
        glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
    }
}

- (void)renderDataLine
{
    GLfloat yScale = 1.0 / self.zoom;

    /*
     * Render the first batch starting from 0 to self.dataLineDataCurrIdx.
     */
    {
        GLfloat yScale = 1.0 / self.zoom;

        glBindVertexArrayOES(self.glVertexArrayDataLine);

        GLKVector3 position = self.dataLinePosition1;
        GLKVector3 rotation = GLKVector3Make(0.0, 0.0, 0.0);
        GLKMatrix4 scale = GLKMatrix4MakeScale(kDataLineShiftSize, yScale, 1.0);
        GLKMatrix4 modelMatrix = [GLCommon modelMatrixWithPosition:position rotation:rotation scale:scale];

        self.graph.effect.transform.modelviewMatrix = modelMatrix;
        self.graph.effect.useConstantColor = YES;
        self.graph.effect.texture2d0.enabled = NO;

        const CGFloat *components = CGColorGetComponents(self.color.CGColor);
        self.graph.effect.constantColor = GLKVector4Make(components[0], components[1], components[2], CGColorGetAlpha(self.color.CGColor));
        [self.graph.effect prepareToDraw];

        DeviceSpecificUI *ui = [AppDelegate sharedDelegate].deviceSpecificUI;
        glLineWidth(ui.GLdataLineWidth);
        glDrawArrays(GL_LINE_STRIP, 0, self.dataLineDataCurrIdx);

        GL_CHECK_ERROR();
    }

    /*
     * Render the second batch starting from self.dataLineDataCurrIdx+1 to the end.
     */
    if (self.dataLineDataValidSize > self.dataLineDataCurrIdx)
    {
        glBindVertexArrayOES(self.glVertexArrayDataLine);

        GLKVector3 position = self.dataLinePosition2;
        GLKVector3 rotation = GLKVector3Make(0.0, 0.0, 0.0);
        GLKMatrix4 scale = GLKMatrix4MakeScale(kDataLineShiftSize, yScale, 1.0);
        GLKMatrix4 modelMatrix = [GLCommon modelMatrixWithPosition:position rotation:rotation scale:scale];

        self.graph.effect.transform.modelviewMatrix = modelMatrix;
        self.graph.effect.useConstantColor = YES;
        const CGFloat *components = CGColorGetComponents(self.color.CGColor);
        self.graph.effect.constantColor = GLKVector4Make(components[0], components[1], components[2], CGColorGetAlpha(self.color.CGColor));
        self.graph.effect.texture2d0.enabled = NO;
        [self.graph.effect prepareToDraw];

        DeviceSpecificUI *ui = [AppDelegate sharedDelegate].deviceSpecificUI;
        glLineWidth(ui.GLdataLineWidth);
        glDrawArrays(GL_LINE_STRIP, self.dataLineDataCurrIdx, self.dataLineDataValidSize - self.dataLineDataCurrIdx);

        GL_CHECK_ERROR();
    }
}

- (void)tearDownGL
{
    // Apparently GLKTextureInfo leaks memory if you don't delete textures explicitly.
    if (self.lineLegendIconTexture)
    {
        GLuint texture = self.lineLegendIconTexture.name;
        glDeleteTextures(1, &texture);
    }
    if (self.lineLegendTextTexture)
    {
        GLuint texture = self.lineLegendTextTexture.name;
        glDeleteTextures(1, &texture);
    }

    if (self.glBufferDataLine)
    {
        glDeleteBuffers(1, &_glBufferDataLine);
    }
    if (self.glBufferLineLegend)
    {
        glDeleteBuffers(1, &_glBufferLineLegend);
    }

    if (self.glVertexArrayDataLine)
    {
最后一个c99错误出现在下一行:

        glDeleteVertexArraysOES(1, &_glVertexArrayDataLine);
这是之后的最后一段代码:

    }
    if (self.glVertexArrayLineLegend)
    {
        glDeleteVertexArraysOES(1, &_glVertexArrayLineLegend);
    }

    GL_CHECK_ERROR();
}

@end

所以你可以猜到,我不知道这个问题将如何解决。我希望这里有人能帮忙?非常感谢

这通常通过导入适当的
OpenGLES
标题来解决,即:

#import <OpenGLES/ES2/glext.h>
#导入

#导入

取决于您使用的OpenGL版本。

我也遇到了同样的问题


解决此问题的最简单方法是在.pch文件中添加#import行。

当我们尝试在XCode6上构建包含一些OpenGL内容的应用程序时,我们遇到了这种情况。Gwynne的修正是简单而出色的。@AdamBlock我不认为包含正确的标题有什么了不起的:)
    }
    if (self.glVertexArrayLineLegend)
    {
        glDeleteVertexArraysOES(1, &_glVertexArrayLineLegend);
    }

    GL_CHECK_ERROR();
}

@end
#import <OpenGLES/ES2/glext.h>
#import <OpenGLES/ES1/glext.h>