Skip to content

Commit 4b0cf7b

Browse files
authored
chore: set all needed glPixelStore states for ImGuiImplGl3 (#298)
Fixes a crash when trying to upload the texture if the application changed one of the 3 added states before ImGui was initialized
1 parent e8f9b01 commit 4b0cf7b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

imgui-lwjgl3/src/main/java/imgui/gl3/ImGuiImplGl3.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
import static org.lwjgl.opengl.GL32.GL_TEXTURE_MIN_FILTER;
6666
import static org.lwjgl.opengl.GL32.GL_TRIANGLES;
6767
import static org.lwjgl.opengl.GL32.GL_TRUE;
68+
import static org.lwjgl.opengl.GL32.GL_UNPACK_ALIGNMENT;
69+
import static org.lwjgl.opengl.GL32.GL_UNPACK_SKIP_PIXELS;
70+
import static org.lwjgl.opengl.GL32.GL_UNPACK_SKIP_ROWS;
6871
import static org.lwjgl.opengl.GL32.GL_UNPACK_ROW_LENGTH;
6972
import static org.lwjgl.opengl.GL32.GL_UNSIGNED_BYTE;
7073
import static org.lwjgl.opengl.GL32.GL_UNSIGNED_INT;
@@ -545,6 +548,9 @@ public boolean createFontsTexture() {
545548
glBindTexture(GL_TEXTURE_2D, data.fontTexture);
546549
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
547550
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
551+
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // Not on WebGL/ES
552+
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); // Not on WebGL/ES
553+
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); // Not on WebGL/ES
548554
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); // Not on WebGL/ES
549555
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width.get(), height.get(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
550556

0 commit comments

Comments
 (0)