2017-02-15 5 views
1

OpenGL ES 3.0を使用してイメージを描画するアプリケーションを作成しようとしています。私はこれをNDK、JNIでAndroid Studioを使用しています。私が実行すると、Logcatでこのエラーが発生しました。何が間違っていますか?あなたの注意と助けは非常に感謝しています。GLSL ES 3.0、頂点シェーダのコンパイルに失敗しました: 'position':正式なレイアウトではありません。修飾子id

エラー:ロードするために

GLfloat recVertices[] = { 
     // Positions   // Colors   // Texture Coords 
     0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // Top Right 
     0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // Bottom Right 
     -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // Bottom Left 
     -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // Top Left 
}; 

GLuint indices[] = { // Note that we start from 0! 
     0, 1, 3, // First Triangle 
     1, 2, 3 // Second Triangle 
}; 
GLunint VAO; 
    void initBuffers() 
{ 

    GLuint VBOs[2], EBO; // Initialize an buffer to store all the verticles and transfer them to the GPU 
    glGenVertexArrays (1,&VAO); 

    glGenBuffers(1, VBOs); 


    glGenBuffers(1, &EBO); 
    glBindVertexArray (VAO); 

    // Bind the Vertex Array 
    glBindBuffer(GL_ARRAY_BUFFER, VBOs[0]);//0. Copy verticles array for OpenGL to use 
    glBufferData(GL_ARRAY_BUFFER, sizeof(recVertices), recVertices, GL_STATIC_DRAW); 

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); 
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 

    // 1. set the vertex attributes pointers 
    // Position Attribute 
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0); 
    glEnableVertexAttribArray(0); 
    // Color Attribute 
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat))); 
    glEnableVertexAttribArray(1); 
    //Texture Coordinate Attribute 
    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat))); 
    glEnableVertexAttribArray(2); 

    glBindVertexArray(0); 
} 

マイgenerateTexture()関数:

Could not compile shader 35633: 
       Vertex shader compilation failed. 
       ERROR: 0:2: 'position' : not a legal layout qualifier id 
       ERROR: 0:2: '' : the location is not within attribute range [0, MAX_ATTRIBUTES-1] 
       ERROR: 0:3: 'position' : not a legal layout qualifier id 
       ERROR: 0:3: '' : the location is not within attribute range [0, MAX_ATTRIBUTES-1] 
       ERROR: 0:4: 'position' : not a legal layout qualifier id 
       ERROR: 0:4: '' : the location is not within attribute range [0, MAX_ATTRIBUTES-1] 
       ERROR: 6 compilation errors. No code generated. 

マイバーテックスシェーダ:すべてのバッファを設定するには

"#version 300 es\n" 
"layout (position=0) in vec3 position;\n" 
"layout (position=1) in vec3 color;\n" 
"layout (position=2) in vec2 texCoord;\n" 

"out vec3 ourColor;\n" 
"out vec2 TexCoord;\n" 

"void main()\n" 
"{\n" 
    "gl_Position = vec4(position,1.0f); // Add the xOffset to the x position of the vertex position\n" 
    "ourColor = color;\n" 
    "TexCoord= vec2(texCoord.x,1.0f-texCoord.y);\n" 
"}"; 

マイinitBuffer()関数画像:

void generateTexture() 
{ 

    glGenTextures(1 , &mTexture); 
    glBindTexture(GL_TEXTURE_2D, mTexture);// Bind our 2D texture so that following set up will be applied 

    //Set texture wrapping parameter 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_MIRRORED_REPEAT); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_MIRRORED_REPEAT); 

    //Set texture Filtering parameter 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); 
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); 

    //Load the image 
    int picWidth,picHeight,n; 
    unsigned char* image = stbi_load("D:\Lighthouse.jpg",&picWidth,&picHeight,0,0); 

    //Generate the image 
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB , picWidth , picHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, image); 
    glGenerateMipmap(GL_TEXTURE_2D); 

    stbi_image_free(image);// Free the reference to the image 
    glBindTexture(GL_TEXTURE_2D,0); //Unbind 2D textures 

} 

、最終的には機能レンダリングマイ:GLSL ES 3程度

void renderFrame() { 
    static float grey; 
    grey += 0.01f; 
    if (grey > 1.0f) { 
     grey = 0.0f; 
    } 

    generateTexture(); 
    glClearColor(grey+0.05f, grey-0.03f, grey+0.02f, grey-0.04f); 
    checkGlError("glClearColor"); 
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 
    checkGlError("glClear"); 

    glUseProgram(gProgram); 
    checkGlError("glUseProgram"); 

    glActiveTexture(GL_TEXTURE0); 
    checkGlError("glActiveTexture"); 
    glBindTexture(GL_TEXTURE_2D,mTexture); 
    checkGlError("glBindTexture"); 
    GLint mlocation = glGetUniformLocation(gProgram,"ourTexture"); 
    checkGlError("glGetUniformLocation"); 
    glUniform1i(mlocation,0); 
    checkGlError("glUniform1i"); 
    initBuffers(); 
    glBindVertexArray(VAO); 
    checkGlError("glBindVertexArray"); 
    glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_INT,0); 

} 

答えて

2

わからないのが、 "標準" GLSLでは、これはlayout (location = n)、ないlayout (position = n)でなければなりません。

at the wikiという表記を使用すると、さまざまなレイアウト修飾子を使用できます。

+0

これで編集して正常にコンパイルできました。そんな愚かな間違いを私は作った。あなたの答えをありがとう:D –

関連する問題