当我在Windows 8计算机上使用lwjgl渲染网格时,我会发现奇怪的闪烁。
使用完全相同的代码(lwjgl natives除外),图像在旧MacBook上正确呈现。
那么为什么这只会发生在Windows 8中。
片段着色器
#version 400core
in vec2 texCords;
in vec3 surfaceNormal;
in vec3 toLight;
in vec3 toCamera;
in vec3 position_out;
in float distanceToCamera_out;
uniform vec3 diffuseLightColor;
uniform vec3 specularLightColor;
out vec4 out_Color;
void main(void){
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitToLight = normalize(toLight);
//temporary
vec4 color = vec4(1,1,1,1);
//diffuse light
float diffuseFactor = max(dot(unitNormal, unitToLight),0);
vec3 diffuse = diffuseLightColor * diffuseFactor;
//specular light
vec3 reflected = reflect(-unitToLight,unitNormal);
float specularFactor = max(dot(reflected,normalize(toCamera)),0);
specularFactor = pow(specularFactor,50); //dampening
vec3 specular = specularLightColor * specularFactor;
//final light
vec3 finalLight = diffuse + specular;
//final color
out_Color = color * vec4(finalLight,1);
}
渲染功能
public void render(Entity entity) {
TexturedModel texModel=entity.getModel();
RawModel model=texModel.getModel();
ModelTexture texture = texModel.getTexture();
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getBaseId());
GL30.glBindVertexArray(model.getVaoId());
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, model.getVboiId());
shader.loadTransformation(Maths.createTransformationMatrix(entity.getPosition(), entity.getRx(), entity.getRy(), entity.getRz(), entity.getScale()));
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL30.glBindVertexArray(0);
}
GPU:gtx 970
答案 0 :(得分:0)
在您的视频中,我看不到闪烁。但是你可能会遇到屏幕撕裂...?如果是这种情况,请添加Display.setVSyncEnabled(true)
。你也可能有碎片,这就是硬件问题,你的编码没有任何问题。