import entities.config.GLConfigVariable;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.NULL;
//---------------------------------------------------------------
// ウィンドウ
public class GLWindow {
private long window; // ウィンドウハンドル
//---------------------------------------------------------------
//---------------------------------------------------------------
// getter
public long getWindow() {
return this.window;
}
//---------------------------------------------------------------
//---------------------------------------------------------------
//
public void init() {
initWindow();
initRender();
}
//---------------------------------------------------------------
// 画面のスワップ
public void swapWindow() {
glfwSwapBuffers(window); // バッファのスワップ
glfwPollEvents(); // 入力とかイベントの取得
}
//---------------------------------------------------------------
// ウィンドウの破棄
public void destroyWindow() {
glfwFreeCallbacks(window); // ウィンドウコールバックの解放
glfwDestroyWindow(window); // ウィンドウの破棄
glfwTerminate(); // GLFWの破棄
glfwSetErrorCallback(null).free(); // エラーコールバックの解放
}
//---------------------------------------------------------------
// ウィンドウが起動しているかどうか
public boolean windowShouldClose() {
return glfwWindowShouldClose(window);
}
//---------------------------------------------------------------
// ウィンドウの初期化
private void initWindow() {
GLFWErrorCallback.createPrint(System.err).set(); // エラーコールバックの設定
// GLFWの初期化
if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW");
// ウィンドウの設定
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
// ウィンドウの作成
window = glfwCreateWindow(GLConfigVariable.WIDTH, GLConfigVariable.HEIGHT, GLConfigVariable.TITLE_NAME, GLConfigVariable.IS_FULL_SCREEN ? glfwGetPrimaryMonitor() : NULL, NULL);
if (window == NULL)
throw new RuntimeException("Failed to create the window.");
glfwMakeContextCurrent(window); //起動したウィンドウをターゲットに
glfwSwapInterval(1); // v-syncの適応
glfwShowWindow(window); // ウィンドウの表示
}
//---------------------------------------------------------------
// 描画プロセス初期化
private void initRender() {
GL.createCapabilities();
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // 背景色設定
// OpenGLの初期化
glEnable(GL_TEXTURE_2D); // 二次元テクスチャの有効化
glEnable(GL_BLEND); // アルファブレンディングの有効化
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // ブレンドモードの設定
}
//---------------------------------------------------------------
}