Wenn ich versuche, projectionMatrix das gerenderte Bild verschwinden zu lassen, sehe ich nur schwarzen Bildschirm. Die Konsole gibt keinen Fehler zurück.lwjgl 3 mit projektionMatrix: nichts rendern
Wo ist das Problem?
Renderer
package ms.renderer;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
import org.joml.Matrix4f;
import ms.Display;
import ms.renderer.VertexArrayObject.Vertex;
import ms.shaders.ShaderProgram;
import ms.utils.FileLoader;
import ms.utils.TextureLoader;
public class Renderer {
VertexArrayObject vertices;
ShaderProgram shaders;
Display display;
Matrix4f projectionMatrix;
private float FOV = (float) Math.toRadians(60.0f);
private float Z_NEAR = 0.01f;
private float Z_FAR = 1000.0f;
public Renderer() {
display = new Display();
vertices = new VertexArrayObject();
}
public void init() throws Exception {
shaders = new ShaderProgram();
shaders.createVertexShader(FileLoader.loadResources("/ms/resources/shaders/vertexShader.vs"));
shaders.createFragmentShader(FileLoader.loadResources("/ms/resources/shaders/fragmentShader.fs"));
shaders.link();
float aspectRation = (float) display.getWidth()/display.getHeight();
projectionMatrix = new Matrix4f().perspective(FOV, aspectRation, Z_NEAR, Z_FAR);
shaders.createUniforms("projectionMatrix");
shaders.createUniforms("textureSampler");
}
public void render(Vertex vertex, TextureLoader texture) {
clear();
shaders.bindPorgram();
shaders.setUniform("projectionMatrix", projectionMatrix);
shaders.setUniform("textureSampler", 0);
glBindVertexArray(vertex.getVaoID());
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture.getId());
glDrawElements(GL_TRIANGLES, vertex.getVertexCount(), GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glBindVertexArray(0);
shaders.unbindProgram();
}
public void clear() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
public void clenaUp() {
vertices.cleanVAO();
shaders.cleanUp();
}
}
Vertexshader
#version 400 core
in vec3 position;
in vec2 textureCoords;
out vec2 outTextureCoords;
uniform mat4 projectionMatrix;
void main()
{
gl_Position = projectionMatrix * vec4(position, 1.0);
outTextureCoords = textureCoords;
}
Mainclass - gameLoop() Methode
public void gameLoop() throws Exception {
isRunning = true;
display.libVersion();
renderer.init();
float[] vertices = {
-0.5f, 0.5f, -5.0f,
-0.5f, -0.5f, -5.0f,
0.5f, -0.5f, -5.0f,
0.5f, 0.5f, -5.0f
};
int[] indices = {
0,1,3,
3,1,2
};
float[] textCoords = {
0, 0,
0, 1,
1, 1,
1, 0
};
Vertex model = loader.loadVAO(vertices, textCoords, indices);
TextureLoader texture = new TextureLoader("image");
while (isRunning && !display.windowShouldClose()) {
update();
renderer.render(model, texture);
if(display.windowShouldClose()) {
renderer.clenaUp();
isRunning = false;
}
}
}
Wenn i remove projectionMatrix das Bild rendern normal. Die projectMatrix Uniform lädt durch Konvertieren des Wertes in Floatbuffer.
ShaderProgram - setUniform() -Methode
public void setUniform(String uniformName, Matrix4f value) {
FloatBuffer buffers = BufferUtils.createFloatBuffer(16);
value.get(buffers);
glUniformMatrix4fv(uniforms.get(uniformName), false, buffers);
}
dadurch gelöst Modify Breite und Höhe int Variablen int in statischen Variablen. – Trese