【发布时间】:2015-07-01 15:25:38
【问题描述】:
我正在使用 java 和 LWJGL/openGL 创建一些图形。对于渲染,我使用以下内容:
RawModel 的构造函数:
public RawModel(int vaoID, int vertexCount, String name){
this.vaoID = vaoID;
this.vertexCount = vertexCount;
this.name = name;
}
渲染器:
public void render(Entity entity, StaticShader shader){
RawModel rawModel = entity.getRaw(active);
GL30.glBindVertexArray(rawModel.getVaoID());
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(3);
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(),
entity.getRotX(), entity.getRotY(), entity.getRotZ(), entity.getScale());
shader.loadTransformationMatrix(transformationMatrix);
GL11.glDrawElements(GL11.GL_TRIANGLES, rawModel.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(3);
GL30.glBindVertexArray(0);
}
我正在使用 GL11.GL_TRIANGLES 因为这就是我可以显示模型的线条而不是面孔的方法。但是当我为顶点设置颜色时,它只是将周围的线条着色为颜色集,在某些情况下,所有线条都采用周围顶点的颜色。我怎样才能使它根据每个顶点的距离和颜色结合这两种颜色?
片段着色器:
#version 400 core
in vec3 colour;
in vec2 pass_textureCoords;
out vec4 out_Color;
uniform sampler2D textureSampler;
void main(void){
vec4 textureColour = texture(textureSampler, pass_textureCoords);
//out_Color = texture(textureSampler, pass_textureCoords);
out_Color = vec4(colour, 1.0);
}
顶点着色器:
#version 400 core
in vec3 position;
in vec2 textureCoords;
in int selected;
out vec3 colour;
out vec2 pass_textureCoords;
uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
void main(void){
gl_Position = projectionMatrix * viewMatrix * transformationMatrix * vec4(position, 1.0);
pass_textureCoords = textureCoords;
if(selected == 1){
colour = vec3(200, 200, 200);
}
else{
colour = vec3(0, 0, 0);
}
gl_BackColor = vec4(colour, 1.0);
}
【问题讨论】:
标签: java opengl 3d rendering lwjgl