2014-01-30 3 views
0

VBO에서 마지막으로 작업 한 이후로 얼마 지나지 않아 다시 작동하도록 노력하고 있습니다. 그러나, 내가 무엇을하든 glClearColor와 함께 렌더링 할 수있는 것은 없습니다.OpenGL VBO가 무언가를 그려 내지 못함

초기화 GL

... 

vmml::vec3f eye = vmml::vec3f(0.0, 0.0, 0.0); 
vmml::vec3f tar = vmml::vec3f(0.0, 0.0, 1.0); 
vmml::vec3f up = vmml::vec3f(0.0, 1.0, 0.0); 
viewMatrix = lookAt(eye, tar, up); 

상자

[code for shadows...] 

    glViewport(0, 0, width, height); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    shadeManager.bindShader(SHADOWSHADER); 

    vmml::vec4f b1(0.5, 0.0, 0.0, 0.5); 
    vmml::vec4f b2(0.0, 0.5, 0.0, 0.5); 
    vmml::vec4f b3(0.0, 0.0, 0.5, 0.5); 
    vmml::vec4f b4(0.0, 0.0, 0.0, 1.0); 

    vmml::mat4f bias = vmml::mat4f::ZERO; 
    bias.set_column(0, b1); 
    bias.set_column(1, b2); 
    bias.set_column(2, b3); 
    bias.set_column(3, b4); 

    vmml::mat4f depthBiasVP = bias * depthVP; 

    GLuint depthBiasID = glGetUniformLocation(shadowShaderID, "depthBiasVP"); 
    GLuint lightDirID = glGetUniformLocation(shadowShaderID, "lightInvDir"); 
    GLuint shadowMapID = glGetUniformLocation(shadowShaderID, "shadowMap"); 
    GLuint viewID  = glGetUniformLocation(shadowShaderID, "V"); 
    GLuint projectionID = glGetUniformLocation(shadowShaderID, "P"); 

    glUniformMatrix4fv(depthBiasID, 1, GL_FALSE, &depthBiasVP[0][0]); 
    glUniform3fv(lightDirID, 1, &lightPos[0]); 

    glActiveTexture(GL_TEXTURE1); 
    glBindTexture(GL_TEXTURE_2D, depthTextureID); 
    glUniform1i(shadowMapID, 1); 

    [calculate eye, target and up...] 
    viewMatrix = lookAt(eye, target, up); 

    glUniformMatrix4fv(viewID, 1, GL_FALSE, &viewMatrix[0][0]); 
    glUniformMatrix4fv(projectionID, 1, GL_FALSE, &projectionMatrix[0][0]); 

    currentFrustum->setActive(true); 
    currentFrustum->extractFrustum(projectionMatrix, viewMatrix); 
    scenegraph.render(false); 

PaintGL

상자

glGenBuffers(1, &vertexBuffer); 
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); 
glBufferData(GL_ARRAY_BUFFER, 72 * sizeof(GLfloat), &vertices[0], GL_STATIC_DRAW); 
glGenBuffers(1, &uvBuffer); 
glBindBuffer(GL_ARRAY_BUFFER, uvBuffer); 
glBufferData(GL_ARRAY_BUFFER, 48 * sizeof(GLfloat), &uvs[0], GL_STATIC_DRAW); 
glGenBuffers(1, &normalBuffer); 
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer); 
glBufferData(GL_ARRAY_BUFFER, 72 * sizeof(GLfloat), &normals[0], GL_STATIC_DRAW); 

[code for adding material and texture to box...] 

생성 및 렌더링 :

내 코드입니다 나는 쉐이더가 제대로로드되었는지 확인하지하고 모델/뷰/투영 행렬이 올바른지, 아직 아무 것도 한

#version 420 core 

layout(location = 0) in vec3 vertexPos; 
layout(location = 1) in vec2 vertexUV; 
layout(location = 2) in vec3 vertexNorm; 

out vec2 UV; 
out vec3 position; 
out vec3 normal; 
out vec3 viewDirection; 
out vec3 lightDirection; 
out vec4 shadow; 

uniform mat4 M; 
uniform mat4 V; 
uniform mat4 P; 
uniform vec3 lightInvDir; 
uniform mat4 depthBiasVP; 

void main() { 
    gl_Position = P * V * M * vec4(vertexPos, 1); 

    UV = vertexUV; 
    position = (M * vec4(vertexPos, 1)).xyz; 
    normal = (V * M * vec4(vertexNorm, 0)).xyz; 
    viewDirection = vec3(0,0,0) - (V * M * vec4(vertexPos, 1)).xyz; 

    lightDirection = (V * vec4(lightInvDir, 0)).xyz; 
    shadow = depthBiasVP * M * vec4(vertexPos, 1); 
} 

#version 420 core 

in vec2 UV; 
in vec3 position; 
in vec3 normal; 
in vec3 viewDirection; 
in vec3 lightDirection; 
in vec4 shadow; 

layout(location = 0) out vec3 color; 

uniform sampler2D tex; 
uniform sampler2D shadowMap; 

uniform vec3 diffLight; 
uniform vec3 ambiLight; 
uniform vec3 specLight; 

uniform vec3 diffMaterial; 
uniform vec3 ambiMaterial; 
uniform vec3 specMaterial; 
uniform float shininess; 

vec2 disk[16] = vec2[] (
    vec2(-0.94201624, -0.39906216), 
    vec2(0.94558609, -0.76890725), 
    vec2(-0.094184101, -0.92938870), 
    vec2(0.34495938, 0.29387760), 
    vec2(-0.91588581, 0.45771432), 
    vec2(-0.81544232, -0.87912464), 
    vec2(-0.38277543, 0.27676845), 
    vec2(0.97484398, 0.75648379), 
    vec2(0.44323325, -0.97511554), 
    vec2(0.53742981, -0.47373420), 
    vec2(-0.26496911, -0.41893023), 
    vec2(0.79197514, 0.19090188), 
    vec2(-0.24188840, 0.99706507), 
    vec2(-0.81409955, 0.91437590), 
    vec2(0.19984126, 0.78641367), 
    vec2(0.14383161, -0.14100790) 
); 

float random(vec3 seed, int i) { 
    vec4 s = vec4(seed, i); 
    float dotProduct = dot(s, vec4(12.9898, 78.233, 45.164, 94.673)); 
    return fract(sin(dotProduct) * 43758.5453); 
} 

void main() { 
    vec3 materialDiffuseColor = diffMaterial * texture2D(tex, UV).rgb; 
    vec3 materialAmbientColor = ambiMaterial * materialDiffuseColor; 
    vec3 materialSpecularColor = specMaterial; 

    vec3 l = normalize(lightDirection); 
    vec3 n = normalize(normal); 
    vec3 v = normalize(viewDirection); 
    vec3 ref = reflect(-l, n); 

    float diff = clamp(dot(n, l), 0,1); 
    float spec = clamp(dot(l, ref), 0,1); 

    float visibility = 1.0; 
    float bias = 0.005*tan(acos(diff)); 
    bias = clamp(bias, 0.0, 0.01); 

    vec4 shadowCoordDivide = shadow/shadow.w; 

    if (texture2D(shadowMap, shadowCoordDivide.xy).z < shadowCoordDivide.z-bias) { 
     //visibility = 0.5; 
     diff = 0; 
     spec = 0; 
    } 

    color = 2 * ambiLight * materialAmbientColor; 

    if (diff != 0) { 
     color += visibility * diffLight * materialDiffuseColor * diff; 

     float iSpec = pow(spec, shininess); 
     color += visibility * specLight * materialSpecularColor * iSpec; 
    } 
} 

16,

GLuint id = ShaderManager::getInstance().getShader(SHADOWSHADER); 
    if (depthPass) 
     id = ShaderManager::getInstance().getShader(DEPTHSHADER); 

    GLuint mID = glGetUniformLocation(id, "M"); 
    GLuint texID = glGetUniformLocation(id, "tex"); 
    GLuint diffID = glGetUniformLocation(id, "diffMaterial"); 
    GLuint ambiID = glGetUniformLocation(id, "ambiMaterial"); 
    GLuint specID = glGetUniformLocation(id, "specMaterial"); 
    GLuint shinID = glGetUniformLocation(id, "shininess"); 

    glUniformMatrix4fv(mID, 1, GL_FALSE, &mod[0][0]); 

    glActiveTexture(GL_TEXTURE0); 
    glBindTexture(GL_TEXTURE_2D, texture); 
    glUniform1i(texID, 0); 

    glUniform3fv(diffID, 1, &values.diffuseMaterial[0]); 
    glUniform3fv(ambiID, 1, &values.ambientMaterial[0]); 
    glUniform3fv(specID, 1, &values.specularMaterial[0]); 
    glUniform1f(shinID, values.shinyMaterial[0]); 

    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); 
    glVertexAttribPointer(
       0, 
       3, 
       GL_FLOAT, 
       GL_FALSE, 
       0, 
       (void*)0 
       ); 
    glEnableVertexAttribArray(0); 

    glBindBuffer(GL_ARRAY_BUFFER, uvBuffer); 
    glVertexAttribPointer(
       1, 
       2, 
       GL_FLOAT, 
       GL_FALSE, 
       0, 
       (void*)0 
       ); 
    glEnableVertexAttribArray(1); 

    glBindBuffer(GL_ARRAY_BUFFER, normalBuffer); 
    glVertexAttribPointer(
       2, 
       3, 
       GL_FLOAT, 
       GL_FALSE, 
       0, 
       (void*)0 
       ); 
    glEnableVertexAttribArray(2); 

    glDrawArrays(GL_QUADS, 0, 6 * 4); 

    glDisableVertexAttribArray(0); 
    glDisableVertexAttribArray(1); 
    glDisableVertexAttribArray(2); 

쉐이더 .... 나를 올바른 방향으로 안내 할 수있는 사람은 누구입니까?

EDIT1 : 나는 잊고 일부 중요하지 않은 코드를 제거 추가 코드 섹션 .. Edit2가 : 다운 가능한 오류 영역

을 박탈 코드
+0

모든 코드를 덤프하지 말고 문제가 발생한 곳으로 좁히십시오. – Vallentin

+0

그래, 내가 덤프하지 않은 코드가 더 많다. 나는 관련 영역만을 게시했다. – Raccomunk

+0

FBO가 더 이상 필요 없으면 바인딩 해제 하시겠습니까? 그림자지도를 그릴 때 다시 바인딩할까요? –

답변

0

그냥 렌더링 코드보고에서, 당신은을 전달하는 것처럼 보이지 않는다 뷰 및 투시 매트릭스를 정점 셰이더에 연결합니다. 전달되지 않은 유니폼을 참조하면 GPU 드라이버가 얼마나 좋은지에 따라 달라집니다. 어떤 것은 충돌 할 것이고, 어떤 것은 shader를 실행시키기 위해 기꺼이 기본 폴백 (fallback) 행렬을 피드 할 것입니다. 셰이더가이 기본 행렬을보고 상자를 올바르게 변형하지 않을 수 있습니다.

코드에서 올바르게 행렬을 전달하는 경우이 답을 무시하십시오. 붙여 넣은 코드를 기반으로합니다.

+0

오, 그래, 그 부분을 잊어 버렸어. 행렬을 셰이더에 전달하고 있습니다. – Raccomunk

+0

그래, 나는 너를 알았지 만 확인 하는게 아프지 않아. :) – redsoxfantom

관련 문제