2013-08-29 4 views
0

인터리브 VBO와 GLSL에 아무것도, 그립니다 없으며, 드디어 쿼드 생성이 코드에 도달 이유 : 다음은 OpenGL은 :이 코드는 내가 많은 논문과 블로그를 검토 한

vert shader:--------------------- 
    #version 330 
    layout(location = 0) in vec3 attrib_position; 
    layout(location = 6) in vec2 attrib_texcoord; 
    out Varing 
    { 
     vec4 pos; 
     vec2 texcoord; 
    } VS_StateOutput; 

    uniform mat4 gtransform; 
    void main(void) 
    { 
     VS_StateOutput.pos = gtransform * vec4(attrib_position,1.0f); 
     VS_StateOutput.texcoord = attrib_texcoord; 
    } 

    frag shader:-------------------- 
    #version 330 
    uniform sampler2D texUnit; 

    in Varing 
    { 
     vec4 pos; 
     vec2 texcoord; 
    } PS_StateInput; 
    layout(location = 0) out vec4 color0; 
    void main(void) 
    { 
     color0 = texture(texUnit, PS_StateInput.texcoord); 
    } 

gProgram

에서 프로그램 저장 내 정점 데이터 : gVertexVBO에 저장

float data[] = 
    { 
     -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 
     1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 
     1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 
     -1.0f, -1.0f, 0.0f, 0.0f, 1.0f 
    }; 

및 인덱스 데이터 : gIndexVBO에 저장

unsigned short idata[] = 
    { 
     0, 3, 2, 0, 2, 1 
    }; 
도면 섹션에서

, 나는 다음과 같이 수행

추신 : gtransform가 행렬

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   
    glUseProgram(gProgram);   
    glProgramUniformMatrix4fv(gProgram, gtLoc, 1, GL_FALSE, matrix); 
    glProgramUniform1uiv(gProgram, texLoc, 1, &colorTex); 

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gIndexVBO); 

    glBindBuffer(GL_ARRAY_BUFFER, gVertexVBO); 
    char* offset = NULL; 
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float)*5, offset); 
    glEnableVertexAttribArray(0); 

    glVertexAttribPointer(6, 2, GL_FLOAT, GL_FALSE, sizeof(float)*5, offset+sizeof(float)*3); 
    glEnableVertexAttribArray(6); 

    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL); 

    glDisableVertexAttribArray(0); 
    glDisableVertexAttribArray(6); 
    glBindBuffer(GL_ARRAY_BUFFER, 0); 
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 

나는 다시 클리어 색상만을 얻을로 설정되어, 나는이 코드 내에있는 오류를 생각한다 그러나 나는 그것이 어디에 있는지 알 수 없다, 나는 어떤 도움을 주셔서 감사합니다.

초기화 섹션에서 코드를 확인해야하는 경우 답장에 게시 해 드리겠습니다. 감사합니다!

답변

2

버텍스 쉐이더에 gl_Position이 내장되어 있지 않습니다.

uniform mat4 gtransform; 
void main(void) 
{ 
    vec4 outPosition = gtransform * vec4(attrib_position,1.0f); 
    gl_Position = outPosition; 
    // if you need the position in the fragment shader 
    VS_StateOutput.pos = outPosition; 
    VS_StateOutput.texcoord = attrib_texcoord; 
} 

OpenGL은 늘 당신의 VS_StateOutput 구조체에 대해 알고 어디에서 새로운 정점을 넣어하는 어떤 생각을 가지고 있지 않습니다. 빠른 참조를 위해 See here. (페이지 7)

This link은 내장 구조에 대해 더 자세히 설명합니다.

편집 :

void main(void) 
{ 
    color0 = vec4(1.0); //texture(texUnit, PS_StateInput.texcoord); 
} 

어떤 텍스처 문제를 배제하기 :

다음으로는 단편 쉐이더 주에를 변경합니다. 때로는 질감 문제로 인해 빈 검은 색 질감이 생깁니다. 만약 당신이 하얀 색을 얻으면, 당신은 그 텍스쳐 문제를 알고 대신 그곳을 볼 수 있습니다.

+0

고마워요! 그것은 실제로 오류였습니다. 그러나 그 문제를 해결 한 후에도 여전히 쿼드를 얻을 수 없습니다. –

+0

프래그먼트 쉐이더에 관해서는, 아무 것도 시도하지 않았습니다. –

+0

다른 장소에서'glGetError'를 호출하려고합니다. 더 많은 정보를 제공하는 오류 코드를 반환해야합니다. 미안하지만 나는 그다지 시간이 없다. 버퍼를 설정할 위치에 코드를 게시해야합니다. [glGetError Link here] (http://www.opengl.org/sdk/docs/man/xhtml/glGetError.xml) – finlaybob