Skip to content

Instantly share code, notes, and snippets.

@jcorbin
Created November 25, 2019 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcorbin/cab8aa3f369dd08a373330f1617dd547 to your computer and use it in GitHub Desktop.
Save jcorbin/cab8aa3f369dd08a373330f1617dd547 to your computer and use it in GitHub Desktop.
import color
import texture
import imgui
import std
import vec
fatal(gl_window("Fail To Scale", 512, 512))
im_init(true)
check(im_add_font("data/fonts/Inconsolata/Inconsolata-Bold.ttf", 32), "cannot load imgui font")
check(gl_set_font_name("data/fonts/US101/US101.TTF"), "must font")
def nest(body): gl_translate(xy_1 / 10.0): gl_scale(4.0/5.0): body()
def test_pattern(size:xy_i):
gl_set_shader("color")
gl_color(color_red): gl_unit_square()
nest():
gl_color(color_green): gl_unit_square()
nest():
gl_color(color_yellow): gl_unit_square()
nest():
gl_color(color_blue): gl_unit_square()
nest():
gl_color(color_pink): gl_unit_square()
nest():
gl_color(color_cyan): gl_unit_square()
nest():
gl_color(color_white): gl_unit_square()
gl_set_font_name("data/fonts/US101/US101.TTF")
gl_set_font_size(size.y)
let box = float(gl_text_size("???"))
gl_translate(xy_h - box / max(box) / 2): gl_scale(1.0 / max(box)):
gl_color(color_black)
gl_text("???")
def with_framebuffer(size:xy_i, fmt:texture_format, body):
let tex = gl_create_blank_texture(size, color_clear, fmt)
assert gl_switch_to_framebuffer(tex, false, fmt, nil, nil)
body(size)
assert gl_switch_to_framebuffer(nil)
return tex
let win_size = gl_window_size()
let n = min(win_size)
var sc = floor(n)
let tex = with_framebuffer(
xy_1i * n,
texture_format_clamp // | texture_format_nomipmap // NOTE: this "fixes" it
) size:
gl_scale(float(size)): test_pattern(size)
while gl_frame(): im_frame():
if gl_button("escape") == 1: return
gl_clear(color_clear)
let size = xy_1i * floor(sc)
gl_translate(float(win_size - sc) / 2): gl_scale(float(size)):
gl_color(color_white):
gl_set_shader("color")
gl_unit_square()
gl_set_shader("textured")
gl_set_primitive_texture(0, tex)
gl_unit_square()
// test_pattern(size)
im_window("Control", im_window_always_autoresize):
sc = im_sliderint("scale", sc, 1, floor(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment