#author("2024-01-06T11:51:57+09:00","default:pitablog","pitablog") #include(include/oldblog,notitle) CENTER:&ref(https://blog.pitan76.net/wp-content/uploads/2022/07/LWJGL34.png); ---- * 【LWJGL3】描画処理 – その1(背景色) #4 [#title] #splitbody{{ LEFT: &tag(情報技術,プログラミング,Java,LWJGL,LWJGL3); #split RIGHT:&size(13){投稿日: 2022-07-28 (木)}; }} #bcontents * Color4fクラス [#n35d9396] 色を保存するためのクラスをつくっておきます。 なくてもいいんですが、私はつくる派です。 package ml.pkom.lwjgl.tutorial; public class Color4f { public float r; public float g; public float b; public float a; public Color4f(float r, float g, float b) { this(r, g, b, 1.0f); } public Color4f(float r, float g, float b, float a) { this.r = r; this.g = g; this.b = b; this.a = a; } } * Windowクラス [#pfd41965] 先ほどつくったColor4fクラスを使います。 つくってない場合は一つ一つr, g, bのfloat型変数を用意する必要がありますね。 // 背景色 public Color4f bgColor new Color4f(0f, 0f, 0f); public void init() { (省略) // リサイズをできるように設定 GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE); GLFW.glfwMakeContextCurrent(window); GL.createCapabilities(); // ビデオモードの取得 GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); (省略) } // 背景色をセット public void setBgColor(float r, float g, float b) { this.bgColor = new Color4f(r, g, b); } update関数に以下の処理を追加します。 // 背景色を描画 GL11.glClearColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); &ref(https://blog.pitan76.net/wp-content/uploads/2022/07/Pasted-21.png,); どこかに以下のコードを埋め込むと黄色になると思います。 window.setBgColor(1.0f, 1.0f, 0.0f); ** コメント [#comment] #pctrlcmt &size(10){キーワード: 描画ライブラリ, アプリ開発, アプリケーション, 描画処理, グラフィック};
Pitan |
![]() |
プログラミングや音MADやらが趣味 |
[もっと見る]
[もっと見る]