Skip to content

Commit

Permalink
display image drawn using SimpleDraw (#5)
Browse files Browse the repository at this point in the history
* change internal format, format, and type for color of texture

* replace width_texture, height_texture with width_image, height_image

* add SimpleDraw

* display image rendered using SimpleDraw

* move glClearColor and glClear out of render loop

* fix image orientation using appropriate transforms
  • Loading branch information
Sid-Bhatia-0 authored Mar 27, 2022
1 parent 5968393 commit 30567d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[deps.SimpleDraw]]
git-tree-sha1 = "c010f60b702e5852f0e7d3071fb647e0955d3262"
uuid = "d1acf6f4-8553-480e-80ae-3c883f0a995a"
version = "0.3.0"

[[deps.Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[deps]
GLFW = "f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98"
ModernGL = "66fc600b-dfda-50eb-8b99-91cfa97b1301"
SimpleDraw = "d1acf6f4-8553-480e-80ae-3c883f0a995a"
31 changes: 17 additions & 14 deletions example.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ModernGL as MGL
import GLFW
import SimpleDraw as SD

function process_input(window)
if GLFW.GetKey(window, GLFW.KEY_Q)
Expand Down Expand Up @@ -81,10 +82,10 @@ MGL.glDeleteShader(vertex_shader)
MGL.glDeleteShader(fragment_shader)

vertices = MGL.GLfloat[
1.0f0, 1.0f0, 0.0f0, 1.0f0, 1.0f0, # top right
1.0f0, -1.0f0, 0.0f0, 1.0f0, 0.0f0, # bottom right
-1.0f0, -1.0f0, 0.0f0, 0.0f0, 0.0f0, # bottom left
-1.0f0, 1.0f0, 0.0f0, 0.0f0, 1.0f0, # top left
1.0f0, 1.0f0, 0.0f0, 0.0f0, 1.0f0, # top right
1.0f0, -1.0f0, 0.0f0, 1.0f0, 1.0f0, # bottom right
-1.0f0, -1.0f0, 0.0f0, 1.0f0, 0.0f0, # bottom left
-1.0f0, 1.0f0, 0.0f0, 0.0f0, 0.0f0, # top left
]
indices = MGL.GLuint[
0, 1, 3, # first Triangle
Expand Down Expand Up @@ -133,22 +134,24 @@ MGL.glTexParameteri(MGL.GL_TEXTURE_2D, MGL.GL_TEXTURE_WRAP_T, MGL.GL_REPEAT)
MGL.glTexParameteri(MGL.GL_TEXTURE_2D, MGL.GL_TEXTURE_MIN_FILTER, MGL.GL_NEAREST)
MGL.glTexParameteri(MGL.GL_TEXTURE_2D, MGL.GL_TEXTURE_MAG_FILTER, MGL.GL_NEAREST)

width_texture = 10
height_texture = 10
channels_texture = 3
data = rand(MGL.GLchar, width_texture * height_texture * channels_texture)
MGL.glTexImage2D(MGL.GL_TEXTURE_2D, 0, MGL.GL_RGB, width_texture, height_texture, 0, MGL.GL_RGB, MGL.GL_UNSIGNED_BYTE, data)
image = zeros(MGL.GLuint, height_image, width_image)
background_color = 0x00c0c0c0
text_color = 0x00000000
SD.draw!(image, SD.Background(), background_color)
SD.draw!(image, SD.TextLine(SD.Point(1, 1), "Hello world!", SD.TERMINUS_32_16), text_color)
MGL.glTexImage2D(MGL.GL_TEXTURE_2D, 0, MGL.GL_RGBA, height_image, width_image, 0, MGL.GL_BGRA, MGL.GL_UNSIGNED_INT_8_8_8_8_REV, image)

MGL.glClearColor(0.0f0, 0.0f0, 0.0f0, 1.0f0)
MGL.glClear(MGL.GL_COLOR_BUFFER_BIT)

while !GLFW.WindowShouldClose(window)
process_input(window)

MGL.glClearColor(0.5f0, 0.5f0, 0.5f0, 1.0f0)
MGL.glClear(MGL.GL_COLOR_BUFFER_BIT)

SD.draw!(image, SD.Background(), background_color)
SD.draw!(image, SD.TextLine(SD.Point(1, 1), "Hello world!", SD.TERMINUS_32_16), text_color)
MGL.glActiveTexture(MGL.GL_TEXTURE0)
MGL.glBindTexture(MGL.GL_TEXTURE_2D, texture_ref[])
data = rand(MGL.GLchar, width_texture * height_texture * channels_texture)
MGL.glTexSubImage2D(MGL.GL_TEXTURE_2D, 0, MGL.GLint(0), MGL.GLint(0), MGL.GLsizei(width_texture), MGL.GLsizei(height_texture), MGL.GL_RGB, MGL.GL_UNSIGNED_BYTE, data)
MGL.glTexSubImage2D(MGL.GL_TEXTURE_2D, 0, MGL.GLint(0), MGL.GLint(0), MGL.GLsizei(height_image), MGL.GLsizei(width_image), MGL.GL_BGRA, MGL.GL_UNSIGNED_INT_8_8_8_8_REV, image)

MGL.glUseProgram(shader_program)

Expand Down

0 comments on commit 30567d6

Please sign in to comment.