imgui #10
@@ -10,7 +10,7 @@ public class Camera {
|
||||
public static final float zNear = 0.01f;
|
||||
public static final float zFar = 1000.0f;
|
||||
|
||||
private static final Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
|
||||
private static final Vector3f up = new Vector3f(0.0f, -1.0f, 0.0f);
|
||||
private static final Vector3f center = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
|
||||
private final float distance = 1.5f;
|
||||
|
||||
@@ -232,12 +232,10 @@ public class DDDView extends GameAdaptator implements GameListener {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
/*
|
||||
this.window.addRegularTask((delta) -> {
|
||||
final float angle = 1f;
|
||||
this.camera.setRotateAngle(this.camera.getRotateAngle() + angle * delta);
|
||||
});
|
||||
*/
|
||||
this.window.run();
|
||||
|
||||
// free OpenGL resources
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
package chess.view.DDDrender;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_COMPONENT;
|
||||
import static org.lwjgl.opengl.GL11.GL_RGB;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
||||
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
|
||||
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_INT;
|
||||
import static org.lwjgl.opengl.GL11.glBindTexture;
|
||||
import static org.lwjgl.opengl.GL11.glTexImage2D;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
@@ -14,7 +21,7 @@ import chess.view.DDDrender.shader.BoardShader;
|
||||
import chess.view.DDDrender.shader.PieceShader;
|
||||
import chess.view.DDDrender.shader.ShaderProgram;
|
||||
|
||||
public class Renderer implements Closeable{
|
||||
public class Renderer implements Closeable {
|
||||
private BoardShader boardShader;
|
||||
private PieceShader pieceShader;
|
||||
|
||||
@@ -26,6 +33,34 @@ public class Renderer implements Closeable{
|
||||
public void Init() {
|
||||
boardShader.LoadShader();
|
||||
pieceShader.LoadShader();
|
||||
|
||||
// The frame buffer
|
||||
int fbo = GL30.glGenFramebuffers();
|
||||
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
|
||||
|
||||
// The texture
|
||||
int renderTexture = GL30.glGenTextures();
|
||||
glBindTexture(GL_TEXTURE_2D, renderTexture);
|
||||
|
||||
System.out.println(renderTexture);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 800, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
GL30.glTexParameteri(GL_TEXTURE_2D, GL30.GL_TEXTURE_MAG_FILTER, GL30.GL_NEAREST);
|
||||
GL30.glTexParameteri(GL_TEXTURE_2D, GL30.GL_TEXTURE_MIN_FILTER, GL30.GL_NEAREST);
|
||||
|
||||
// The depth buffer
|
||||
int depthBuffer = GL30.glGenRenderbuffers();
|
||||
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBuffer);
|
||||
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 800, 800);
|
||||
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
|
||||
depthBuffer);
|
||||
|
||||
// Set "renderedTexture" as our colour attachement #0
|
||||
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderTexture, 0);
|
||||
// Set the list of draw buffers.
|
||||
int[] drawBuffers = { GL30.GL_COLOR_ATTACHMENT0 };
|
||||
GL30.glDrawBuffers(drawBuffers);
|
||||
}
|
||||
|
||||
public void Update(Camera cam) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import chess.view.DDDrender.world.World;
|
||||
import common.Signal1;
|
||||
import imgui.ImFontConfig;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
import imgui.gl3.ImGuiImplGl3;
|
||||
import imgui.glfw.ImGuiImplGlfw;
|
||||
|
||||
@@ -176,9 +177,13 @@ public class Window implements Closeable {
|
||||
}
|
||||
|
||||
private void render(float delta, float aspectRatio) {
|
||||
cam.setAspectRatio(aspectRatio);
|
||||
cam.setAspectRatio(1.0f);
|
||||
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 1);
|
||||
glViewport(0, 0, 800, 800);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
|
||||
renderer.Update(cam);
|
||||
renderWorld();
|
||||
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
private void renderWorld() {
|
||||
@@ -226,6 +231,15 @@ public class Window implements Closeable {
|
||||
ImGui.newFrame();
|
||||
}
|
||||
|
||||
private void renderWindow() {
|
||||
// ImGui.showDemoWindow();
|
||||
|
||||
ImGui.begin("Hello");
|
||||
ImGui.button("test");
|
||||
ImGui.image(1, new ImVec2(800, 800));
|
||||
ImGui.end();
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
|
||||
// Set the clear color
|
||||
@@ -255,7 +269,7 @@ public class Window implements Closeable {
|
||||
float deltaTime = (float) (currentTime - lastTime);
|
||||
render(deltaTime, (float) width[0] / (float) height[0]);
|
||||
|
||||
// ImGui.showDemoWindow();
|
||||
renderWindow();
|
||||
ImGui.render();
|
||||
implGl3.renderDrawData(ImGui.getDrawData());
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BoardShader extends ShaderProgram {
|
||||
in vec3 toCameraVector;
|
||||
in vec3 surfaceNormal;
|
||||
|
||||
out vec4 out_color;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
const float shineDamper = 10.0;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class PieceShader extends ShaderProgram {
|
||||
|
||||
uniform vec3 modelColor;
|
||||
|
||||
out vec4 out_color;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
|
||||
void main(void){
|
||||
const float shineDamper = 10.0;
|
||||
|
||||
Reference in New Issue
Block a user