2017-02-15 19 views
1

OpenGL ES 3.0을 사용하여 이미지를 그리는 앱을 만들려고합니다. 나는 NDK, JNI와 함께 Android Studio를 사용합니다. Logcat에서이 오류가 발생했습니다. 무엇을 잘못하고 있습니까? 귀하의 관심과 도움은 대단히 감사하겠습니다.GLSL ES 3.0, 버텍스 쉐이더 컴파일 실패 : 'position': 합법적 인 레이아웃이 아닙니다. 한정자 ID

오류 :

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() 모든 버퍼 설정하는 기능 :로드

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 

} 

그리고 마지막으로 기능 렌더링의 나 : 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 조 –