20220728158 の変更点

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){キーワード: 描画ライブラリ, アプリ開発, アプリケーション, 描画処理, グラフィック};

検索

 

プロフィール

Pitan
pitan_prof.png
プログラミングや音MADやらが趣味

最新のページ

最新の5件
2025-03-28 2025-03-20 2025-03-18 2025-03-13

[もっと見る]

タグ

[もっと見る]

人気のページ

人気の5件

カウンター

合計: 113
今日: 1
昨日: 0
オンライン: 3
  編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS