20220728158 の変更点
#author("2024-01-06T11:45:56+09:00","default:pitablog","pitablog")
#include(include/oldblog,notitle)
&ref(https://blog.pitan76.net/wp-content/uploads/2022/07/LWJGL31.png);
* 【LWJGL3】ウィンドウの作成 #1 [#title]
#splitbody{{
LEFT:
&tag(情報技術,プログラミング,Java,LWJGL,LWJGL3);
#split
RIGHT:&size(13){投稿日: 2022-07-28 (木)};
}}
#bcontents
適当に初期クラスのMainクラスとウィンドウの処理を書くためのWindowクラスをつくっておきます。
- 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);
}
}
- Mainクラス
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();
}
}
}
&ref(https://blog.pitan76.net/wp-content/uploads/2022/07/Pasted-17.png,);
実行してみるとウィンドウが表示されました。
** コメント [#comment]
#pctrlcmt
&size(10){キーワード: 描画ライブラリ, アプリ開発, アプリケーション, 描画処理, グラフィック};