Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display image drawn using SimpleDraw #5

Merged
merged 6 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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