2017-02-15 21 views
1

Я пытаюсь создать приложение, использующее OpenGL ES 3.0 для рисования изображения. Для этого я использую Android Studio с NDK, JNI. Когда я бегу, я получил эту ошибку в Logcat, что я делаю неправильно? Ваше внимание и помощь очень ценятся.GLSL ES 3.0, не удалось скомпилировать вершину Shader: 'position': не является идентификатором идентификатора юридического макета

Ошибка:

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. 

Моего Vertex Shader:

"#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() для настройки все буфера:

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() функции для загрузки изображение:

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 

} 

И наконец моя Рендер функции:

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 ES 3, но в "стандартном" GLSL это должно быть layout (location = n), не layout (position = n).

Вы можете посмотреть at the wiki, чтобы получить различные квалификаторы макета.

+0

Я отредактировал и успешно скомпилировал его. Такая глупая ошибка, которую я совершил. Спасибо за ваш ответ: D –