LWJGL对象未在ATI显卡上显示

时间:2014-09-26 22:48:20

标签: opengl shader lwjgl

我编写了一个使用.obj文件的LWJGL应用程序,读取它们并显示它们(使用显示列表)。

在我的nvidia显卡上,一切运行正常。但是在amd显卡上我看不到对象。

我如何向着色器提供数据:

glUseProgram(shaderEngine.obj);
glUniform1i(glGetUniformLocation(shaderEngine.obj, "inOrangeJuice"), inOrangeJuice ? 1 : 0);
shaderEngine.loadMatrix(glGetUniformLocation(shaderEngine.standard, "projectionMatrix"), camera.projectionMatrix);
shaderEngine.loadMatrix(glGetUniformLocation(shaderEngine.obj, "viewMatrix"), camera.viewMatrix);

加载了ModelMatrix:

shaderEngine.createModelMatrix(new Vector3f(x, y, z), new Vector3f(rx, ry, rz), new Vector3f(1, 1, 1));
shaderEngine.loadModelMatrix(shaderEngine.obj);

Fragment Shader:

#version 130

uniform sampler2D tex;
uniform vec2 texCoord[4];

float textureSize;
float texelSize;

uniform int inOrangeJuice;


bool pointInTriangle(vec3 P, vec3 A, vec3 B, vec3 C)
{
    vec3 u = B - A;
    vec3 v = C - A;
    vec3 w = P - A;

    vec3 vCrossW = cross(v, w);
    vec3 vCrossU = cross(v, u);

    if(dot(vCrossW, vCrossU) < 0)
    {
        return false;
    }


    vec3 uCrossW = cross(u, w);
    vec3 uCrossV = cross(u, v);

    if(dot(uCrossW, uCrossV) < 0)
    {
        return false;
    }

    float denom = length(uCrossV);
    float r = length(vCrossW);
    float t  = length(uCrossW);

    return (r + t <= 1);
}


vec4 texture2DBilinear(sampler2D textureSampler, vec2 uv)
{
    vec4 tl = texture2D(textureSampler, uv);
    vec4 tr = texture2D(textureSampler, uv + vec2(texelSize, 0));
    vec4 bl = texture2D(textureSampler, uv + vec2(0, texelSize));
    vec4 br = texture2D(textureSampler, uv + vec2(texelSize , texelSize));
    vec2 f = fract( uv.xy * textureSize );
    vec4 tA = mix( tl, tr, f.x );
    vec4 tB = mix( bl, br, f.x );
    return mix( tA, tB, f.y );
}


void main()
{
    ivec2 textureSize2d = textureSize(tex,0);
    textureSize = float(textureSize2d.x);
    texelSize = 1.0 / textureSize;

    //texture coordinate:
    vec2 texCoord = (gl_TexCoord[0].st);

    bool inOJ = false;

    if(inOrangeJuice == 1)
    {
        float depth = gl_FragCoord.z / gl_FragCoord.w;//works only with perspective projection
        depth = depth / 6;

        if(depth > 1)
        {
            depth = 1;
        }
        inOJ = true;
        gl_FragColor = texture2DBilinear(tex, texCoord) * gl_Color * (1.0 - depth) + vec4(1.0, 0.5, 0.0, 1.0) * depth;
    }
    if(inOJ == false)
    {
        gl_FragColor = texture2DBilinear(tex, texCoord) * gl_Color;
    }

    //Nothing is shown, inOrangeJuice should be 0
    //gl_FragColor = vec4(inOrangeJuice,0,0,1);

    //Always works:
    //gl_FragColor = texture2D(tex, texCoord) * gl_Color;
}

0 个答案:

没有答案