|
投稿日: 2022-07-28 (木)
|
適当に初期クラスのMainクラスとウィンドウの処理を書くためのWindowクラスをつくっておきます。
package ml.pkom.lwjgl.tutorial;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;
import static org.lwjgl.system.MemoryUtil.*;
public class Window {
public long window;
// ウィンドウの横幅
public int width = 640;
// ウィンドウの縦幅
public int height = 360;
// ウィンドウのタイトル名
public String title = "HogeHoge";
public void init() {
// GLFWの初期化
GLFW.glfwInit();
// ウィンドウを作成
window = GLFW.glfwCreateWindow(width, height, title, NULL, NULL);
// ウィンドウが見えるように設定
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
// リサイズをできるように設定
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
// ビデオモードの取得
GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
// 画面のサイズを取得
int screenWidth = videoMode.width();
int screenHeight = videoMode.height();
// ウィンドウの位置を中央へセットする
GLFW.glfwSetWindowPos(window, (screenWidth - width) / 2, (screenHeight - height) / 2);
// ウィンドウを表示
GLFW.glfwShowWindow(window);
}
// 閉じるボタンが押されるとtrueを返す
public boolean isClosed() {
return GLFW.glfwWindowShouldClose(window);
}
public void update() {
// マウスなど入力されたイベントを記録する
GLFW.glfwPollEvents();
}
public void swapBuffers() {
// カラーバッファ(色表示)を入れ替える
GLFW.glfwSwapBuffers(window);
}
}
package ml.pkom.lwjgl.tutorial;
public class Main {
public static void main(String[] args) {
Window window = new Window();
// ウィンドウの初期化
window.init();
// 閉じるまでループ
while (!window.isClosed()) {
// イベントの更新
window.update();
// バッファの更新
window.swapBuffers();
}
}
}
実行してみるとウィンドウが表示されました。
コメントはありません。 Comments/20220728158
キーワード: 描画ライブラリ, アプリ開発, アプリケーション, 描画処理, グラフィック
| Pitan |
![]() |
| プログラミングや音MADやらが趣味 |
| Table of Contents |
[もっと見る]
[もっと見る]