Finally working

This commit is contained in:
2026-07-24 20:41:09 +02:00
parent d8cfb79c9a
commit bfa53c7849
8 changed files with 57 additions and 10 deletions
@@ -207,6 +207,7 @@ public class GLGraphicsDevice implements GraphicsDevice {
return false;
}
GL20.glAttachShader(T, id);
shaders.add(id);
}
for(BufferAttribute attribute : ObjectIterables.flatMap(pipeline.attributes(), VertexBinding::attributes)) {
GL20.glBindAttribLocation(T, attribute.index(), attribute.name());
@@ -237,6 +238,7 @@ public class GLGraphicsDevice implements GraphicsDevice {
//TODO Warn that location wasn't found
continue;
}
GL31.glUniformBlockBinding(program, location, binding.slot());
uniforms.add(binding.name(), binding.slot(), new UniformObject(binding.slot()));
}
ShaderInstance instance = new ShaderInstance(program, uniforms, samplers);
@@ -21,7 +21,7 @@ public class GLSurface implements GraphicsSurface {
@Override
public void beginFrame() {
GL11.glClearColor(0.2F, 0.55F, 0.66F, 1F);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
window.beginFrame();
GLFW.glfwPollEvents();
}
@@ -1,8 +1,10 @@
package speiger.src.coreengine;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;
import org.lwjgl.system.Configuration;
import org.lwjgl.util.freetype.FreeType;
@@ -82,6 +84,15 @@ public class NewRenderEngineTest {
VertexBuilder builder = new VertexBuilder(255);
builder.start(null, VertexTypes.TESTING);
// builder.pos(350F, 250F, 0).tex(0F, 1F).rgba(-1).endVertex(); // Unten Links
// builder.pos(450F, 350F, 0).tex(1F, 0F).rgba(-1).endVertex(); // Oben Rechts
// builder.pos(450F, 250F, 0).tex(1F, 1F).rgba(-1).endVertex(); // Unten Rechts
//
// builder.pos(450F, 350F, 0).tex(1F, 0F).rgba(-1).endVertex(); // Oben Rechts
// builder.pos(350F, 250F, 0).tex(0F, 1F).rgba(-1).endVertex(); // Unten Links
// builder.pos(350F, 350F, 0).tex(0F, 0F).rgba(-1).endVertex(); // Oben Links
builder.pos(-0.5F, -0.5F, 0).tex(0F, 1F).rgba(-1).endVertex();
builder.pos(0.5F, -0.5F, 0).tex(1F, 1F).rgba(-1).endVertex();
builder.pos(0.5F, 0.5F, 0).tex(1F, 0F).rgba(-1).endVertex();
@@ -104,15 +115,15 @@ public class NewRenderEngineTest {
Sampler sampler = device.createSampler(SamplerSettings.builder().sampler(SampleMode.NEAREST).wrap(BorderMode.CLAMP_TO_EDGE).build());
VertexBuffer buffer = device.createBuffer(BufferType.UNIFORM_BUFFER, BufferState.STATIC_DRAW);
ByteBuffer mat = ByteBuffer.allocate(64);
ByteBuffer mat = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
int scale = 0;
new Matrix4f().ortho(0, 0, window.width() >> scale, window.height() >> scale, 1000, -1000).store(mat);
buffer.bind().set(mat.flip().array()).unbind();
ShaderPipeline pipeline = ShaderPipeline.builder(ID.of("gui"))
.withStage(ShaderType.VERTEX, ID.of("shader/testGui/vertex.vs"))
.withStage(ShaderType.FRAGMENT, ID.of("shader/testGui/fragment.fs"))
.withStage(ShaderType.VERTEX, ID.of("shader/newTestGui/vertex.vs"))
.withStage(ShaderType.FRAGMENT, ID.of("shader/newTestGui/fragment.fs"))
.withTexture("texture", 0, 0, TextureType.TEXTURE_2D)
.withUniform("Camera", 0, 0, 64)
.withFormat()
@@ -123,11 +134,13 @@ public class NewRenderEngineTest {
.build();
window.visible(true);
GraphicsCommandBuffer queue = device.createCommandBuffer(ExecutionType.IMMEDIATE);
GL11.glViewport(0, 0, window.width(), window.height());
while(!window.shouldClose()) {
surface.beginFrame();
if(window.changed()) {
window.updateViewport();
GL11.glViewport(0, 0, window.width(), window.height());
new Matrix4f().ortho(0, 0, window.width() >> scale, window.height() >> scale, 1000, -1000).store(mat);
buffer.bind().set(mat.flip().array()).unbind();
}
@@ -14,6 +14,7 @@ import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.rendering.input.window.IWindowListener.Reason;
import speiger.src.coreengine.rendering.input.window.WindowCallback.ReloadFunction;
import speiger.src.coreengine.rendering.input.window.WindowManager.WindowBuilder;
import speiger.src.coreengine.rendering.utils.GLStateTracker;
import speiger.src.coreengine.utils.collections.FlagHolder;
public class Window {
@@ -0,0 +1,14 @@
#version 420
in vec4 pass_color;
in vec2 pass_tex;
out vec4 frag_color;
layout(binding = 0) uniform sampler2D texture;
void main()
{
vec4 color = texture2D(texture, pass_tex);
frag_color = pass_color * color;
}
@@ -0,0 +1,19 @@
#version 420
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec2 in_tex;
layout(location = 2) in vec4 in_color;
out vec4 pass_color;
out vec2 pass_tex;
layout(std140, column_major, binding = 0) uniform Camera {
mat4 proViewMatrix;
} camera;
void main()
{
gl_Position = vec4(in_position, 1.0);
pass_color = in_color;
pass_tex = in_tex;
}
@@ -5,7 +5,7 @@ in vec2 pass_tex;
out vec4 frag_color;
layout(binding = 0) uniform sampler2D texture;
uniform sampler2D texture;
void main()
{
@@ -7,13 +7,11 @@ layout(location = 2) in vec4 in_color;
out vec4 pass_color;
out vec2 pass_tex;
layout(binding = 0) uniform Camera {
mat4 proViewMatrix;
} camera;
uniform mat4 proViewMatrix;
void main()
{
gl_Position = camera.proViewMatrix * vec4(in_position, 1.0);
gl_Position = proViewMatrix * vec4(in_position, 1.0);
pass_color = in_color;
pass_tex = in_tex;
}