Esempio n. 1
0
import gc

import nanogui
from nanogui import Screen, Window, Widget, GridLayout, VScrollPanel, Button
from nanogui import entypo

if __name__ == "__main__":
    nanogui.init()

    width = 1000
    half_width = width // 2
    height = 800

    # create a fixed size screen with one window
    screen = Screen((width, height), "NanoGUI Icons", False)
    window = Window(screen, "All Icons")
    window.setPosition((0, 0))
    window.setFixedSize((width, height))

    # attach a vertical scroll panel
    vscroll = VScrollPanel(window)
    vscroll.setFixedSize((width, height))

    # vscroll should only have *ONE* child. this is what `wrapper` is for
    wrapper = Widget(vscroll)
    wrapper.setFixedSize((width, height))
    wrapper.setLayout(GridLayout())  # defaults: 2 columns

    # NOTE: don't __dict__ crawl in real code!
    # this is just because it's more convenient to do this for enumerating all
Esempio n. 2
0
        globals()[name] = value

    def getter():
        return globals()[name]

    return setter, getter


nanogui.init()

use_gl_4_1 = False  # Set to True to create an OpenGL 4.1 context.
if use_gl_4_1:
    # NanoGUI presents many options for you to utilize at your discretion.
    # See include/nanogui/screen.h for what all of the options are.
    screen = Screen(Vector2i(500, 700),
                    "NanoGUI test [GL 4.1]",
                    glMajor=4,
                    glMinor=1)
else:
    screen = Screen(Vector2i(500, 700), "NanoGUI test")

gui = FormHelper(screen)
window = gui.addWindow(Vector2i(10, 10), "Form helper example")

gui.addGroup("Basic types")
gui.addBoolVariable("bool", *make_accessors("bvar"))
gui.addStringVariable("string", *make_accessors("strvar"))

gui.addGroup("Validating fields")
gui.addIntVariable("int", *make_accessors("ivar"))
gui.addDoubleVariable("double", *make_accessors("dvar")).setSpinnable(True)
Esempio n. 3
0
    def __init__(self):
        Screen.__init__(self, size=[512, 512], caption="Unnamed")

        if nanogui.api == 'opengl':
            vertex_program = '''
                #version 330
                in vec3 position;
                in vec2 uv;
                out vec2 uv_frag;
                uniform mat4 mvp;

                void main() {
                    gl_Position = mvp * vec4(position, 1.0);
                    uv_frag = uv;
                }
            '''

            fragment_program = '''
                #version 330
                in vec2 uv_frag;
                out vec4 fragColor;
                uniform sampler2D albedo_texture;

                void main() {
                    fragColor = texture(albedo_texture, uv_frag);
                }
            '''
        elif nanogui.api == 'metal':
            vertex_program = '''
                using namespace metal;

                struct VertexOut {
                    float4 position [[position]];
                    float2 uv;
                };

                vertex VertexOut vertex_main(const device packed_float3 *position,
                                             const device float2 *uv,
                                             constant float4x4 &mvp,
                                             uint id [[vertex_id]]) {
                    VertexOut vert;
                    vert.position = mvp * float4(position[id], 1.f);
                    vert.uv = uv[id];
                    return vert;
                }
            '''

            fragment_program = '''
                using namespace metal;

                struct VertexOut {
                    float4 position [[position]];
                    float2 uv;
                };

                fragment float4 fragment_main(VertexOut vert [[stage_in]],
                             texture2d<float, access::sample> albedo_texture,
                             sampler albedo_sampler) {
                    return albedo_texture.sample(albedo_sampler, vert.uv);
                }
            '''

        base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        image_fname = os.path.join(base_dir, "resources/icons/icon1.png")
        image = np.array(Image.open(image_fname))

        self.albedo_texture = Texture(
            pixel_format=Texture.PixelFormat.RGBA,
            component_format=Texture.ComponentFormat.UInt8,
            size=image.shape[:2])
        self.albedo_texture.upload(image)

        self.render_pass = RenderPass(color_targets=[self])

        self.shader = Shader(self.render_pass, "test_shader", vertex_program,
                             fragment_program)

        p = np.array([[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 0]],
                     dtype=np.float32)

        uv = np.array([[1, 1], [0, 1], [0, 0], [1, 0]], dtype=np.float32)

        indices = np.array([0, 2, 1, 3, 2, 0], dtype=np.uint32)

        self.shader.set_buffer("position", p)
        self.shader.set_buffer("uv", uv)
        self.shader.set_buffer("indices", indices)
        self.shader.set_texture("albedo_texture", self.albedo_texture)
Esempio n. 4
0
# OpenGL/Metal rendering test: render a red triangle to a texture
# and save it to a PNG file

import sys
sys.path.append('python')
import nanogui
from nanogui import Shader, Texture, RenderPass, Screen
import numpy as np
from PIL import Image

nanogui.init()

if nanogui.api == 'opengl':
    s = Screen([16, 16], "Unnamed")

    vertex_program = '''
        #version 330
        in vec3 position;

        void main() {
            gl_Position = vec4(position, 1.0);
        }
    '''

    fragment_program = '''
        #version 330
        uniform vec4 color;
        out vec4 fragColor;

        void main() {
            fragColor = color;
Esempio n. 5
0
enumvar = 1
colvar = nanogui.Color(.5, .5, .7, 1)


def make_accessors(name):
    def setter(value):
        globals()[name] = value

    def getter():
        return globals()[name]
    return setter, getter


nanogui.init()

screen = Screen(Vector2i(500, 700), "NanoGUI test")
gui = FormHelper(screen)
window = gui.addWindow(Vector2i(10, 10), "Form helper example")

gui.addGroup("Basic types")
gui.addBoolVariable("bool", *make_accessors("bvar"))
gui.addStringVariable("string", *make_accessors("strvar"))

gui.addGroup("Validating fields")
gui.addIntVariable("int", *make_accessors("ivar"))
gui.addDoubleVariable("double", *make_accessors("dvar"))

gui.addGroup("Complex types")
gui.addEnumVariable("Enumeration", *make_accessors("enumvar")) \
   .setItems(["Item 1", "Item 2", "Item 3"])
gui.addColorVariable("Color", *make_accessors("colvar"))
Esempio n. 6
0
        globals()[name] = value

    def getter():
        return globals()[name]

    return setter, getter


nanogui.init()

use_gl_4_1 = False  # Set to True to create an OpenGL 4.1 context.
if use_gl_4_1:
    # NanoGUI presents many options for you to utilize at your discretion.
    # See include/nanogui/screen.h for what all of the options are.
    screen = Screen((500, 700),
                    'NanoGUI test [GL 4.1]',
                    gl_major=4,
                    gl_minor=1)
else:
    screen = Screen((500, 700), 'NanoGUI test')

gui = FormHelper(screen)
window = gui.add_window((10, 10), 'Form helper example')

gui.add_group('Basic types')
gui.add_bool_variable('bool', *make_accessors('bvar'))
gui.add_string_variable('string', *make_accessors('strvar'))
gui.add_string_variable(
    'placeholder', *make_accessors('strvar2')).set_placeholder('placeholder')

gui.add_group('Validating fields')
gui.add_int_variable('int', *make_accessors('ivar'))
Esempio n. 7
0
import gc

import nanogui
from nanogui import Screen, Window, Widget, GridLayout, VScrollPanel, Button
from nanogui import entypo

if __name__ == "__main__":
    nanogui.init()

    width = 1000
    half_width = width // 2
    height = 800

    # create a fixed size screen with one window
    screen = Screen((width, height), "NanoGUI Icons", False)
    window = Window(screen, "All Icons")
    window.set_position((0, 0))
    window.set_fixed_size((width, height))

    # attach a vertical scroll panel
    vscroll = VScrollPanel(window)
    vscroll.set_fixed_size((width, height))

    # vscroll should only have *ONE* child. this is what `wrapper` is for
    wrapper = Widget(vscroll)
    wrapper.set_fixed_size((width, height))
    wrapper.set_layout(GridLayout())  # defaults: 2 columns

    # NOTE: don't __dict__ crawl in real code!
    # this is just because it's more convenient to do this for enumerating all
Esempio n. 8
0
    def __init__(self):
        Screen.__init__(self,
            size=[512, 512],
            caption="Unnamed",
            depth_buffer=True
        )

        if nanogui.api == 'opengl':
            vertex_program = '''
                #version 330
                in vec3 position;
                in vec4 color;
                out vec4 color_frag;
                uniform mat4 mvp;

                void main() {
                    gl_Position = mvp * vec4(position, 1.0);
                    color_frag = color;
                }
            '''

            fragment_program = '''
                #version 330
                in vec4 color_frag;
                out vec4 fragColor;

                void main() {
                    fragColor = color_frag;
                }
            '''
        elif nanogui.api == 'metal':
            vertex_program = '''
                using namespace metal;

                struct VertexOut {
                    float4 position [[position]];
                    float4 color;
                };

                vertex VertexOut vertex_main(const device packed_float3 *position,
                                             const device float4 *color,
                                             constant float4x4 &mvp,
                                             uint id [[vertex_id]]) {
                    VertexOut vert;
                    vert.position = mvp * float4(position[id], 1.f);
                    vert.color = color[id];
                    return vert;
                }
            '''

            fragment_program = '''
                using namespace metal;

                struct VertexOut {
                    float4 position [[position]];
                    float4 color;
                };

                fragment float4 fragment_main(VertexOut vert [[stage_in]]) {
                    return vert.color;
                }
            '''

        self.render_pass = RenderPass(
            color_targets=[self],
            depth_target=self
        )

        self.shader = Shader(
            self.render_pass,
            "test_shader",
            vertex_program,
            fragment_program
        )

        p = np.array([
            [-1, 1, 1], [-1, -1, 1],
            [1, -1, 1], [1, 1, 1],
            [-1, 1, -1], [-1, -1, -1],
            [1, -1, -1], [1, 1, -1]],
            dtype=np.float32
        )

        color = np.array([
            [0, 1, 1, 1], [0, 0, 1, 1],
            [1, 0, 1, 1], [1, 1, 1, 1],
            [0, 1, 0, 1], [0, 0, 0, 1],
            [1, 0, 0, 1], [1, 1, 0, 1]],
            dtype=np.float32
        )

        indices = np.array([
            3, 2, 6, 6, 7, 3,
            4, 5, 1, 1, 0, 4,
            4, 0, 3, 3, 7, 4,
            1, 5, 6, 6, 2, 1,
            0, 1, 2, 2, 3, 0,
            7, 6, 5, 5, 4, 7],
            dtype=np.uint32
        )

        self.shader.set_buffer("position", p)
        self.shader.set_buffer("color", color)
        self.shader.set_buffer("indices", indices)
Esempio n. 9
0
colvar = nanogui.Color(.5, .5, .7, 1)


def make_accessors(name):
    def setter(value):
        globals()[name] = value

    def getter():
        return globals()[name]

    return setter, getter


nanogui.init()

screen = Screen(Vector2i(500, 700), "NanoGUI test")

gui = FormHelper(screen)
window = gui.addWindow(Vector2i(10, 10), "Form helper example")

gui.addGroup("Basic types")
gui.addBoolVariable("bool", *make_accessors("bvar"))
gui.addStringVariable("string", *make_accessors("strvar"))

gui.addGroup("Validating fields")
gui.addIntVariable("int", *make_accessors("ivar"))
gui.addDoubleVariable("double", *make_accessors("dvar"))

gui.addGroup("Complex types")
gui.addEnumVariable("Enumeration", *make_accessors("enumvar")) \
   .setItems(["Item 1", "Item 2", "Item 3"])
Esempio n. 10
0
def make_accessors(name):
    def setter(value):
        globals()[name] = value

    def getter():
        return globals()[name]
    return setter, getter

nanogui.init()

use_gl_4_1 = False # Set to True to create an OpenGL 4.1 context.
if use_gl_4_1:
    # NanoGUI presents many options for you to utilize at your discretion.
    # See include/nanogui/screen.h for what all of the options are.
    screen = Screen((500, 700), 'NanoGUI test [GL 4.1]', gl_major=4, gl_minor=1)
else:
    screen = Screen((500, 700), 'NanoGUI test')

gui = FormHelper(screen)
window = gui.add_window((10, 10), 'Form helper example')

gui.add_group('Basic types')
gui.add_bool_variable('bool', *make_accessors('bvar'))
gui.add_string_variable('string', *make_accessors('strvar'))
gui.add_string_variable('placeholder', *make_accessors('strvar2')).set_placeholder('placeholder')

gui.add_group('Validating fields')
gui.add_int_variable('int', *make_accessors('ivar'))
gui.add_double_variable('double', *make_accessors('dvar'))
Esempio n. 11
0
    def __init__(self):
        Screen.__init__(self, [512, 512], "Unnamed")

        if nanogui.api == 'opengl':
            vertex_program = '''
                #version 330
                in vec3 position;

                void main() {
                    gl_Position = vec4(position, 1);
                }
            '''

            fragment_program = '''
                #version 330
                uniform vec4 color;
                out vec4 fragColor;

                void main() {
                    fragColor = color;
                }
            '''
        elif nanogui.api == 'metal':
            vertex_program = '''
                using namespace metal;

                struct VertexOut {
                    float4 position [[position]];
                };

                vertex VertexOut vertex_main(const device packed_float3 *position,
                                             uint id [[vertex_id]]) {
                    VertexOut vert;
                    vert.position = float4(position[id], 1.f);
                    return vert;
                }
            '''

            fragment_program = '''
                using namespace metal;

                struct VertexOut {
                    float4 position [[position]];
                };

                fragment float4 fragment_main(VertexOut vert [[stage_in]],
                                              const constant float4 &color) {
                    return color;
                }
            '''

        self.render_pass = RenderPass([self])
        self.render_pass.set_viewport([10, 10],
                                      self.framebuffer_size() - [10, 20])

        self.shader = Shader(self.render_pass, "test_shader", vertex_program,
                             fragment_program)

        p = np.array([[0.0, 0.5, 0], [-0.5, -0.5, 0], [0.5, -0.5, 0]],
                     dtype=np.float32)

        self.shader.set_buffer("position", p)
        self.shader.set_buffer("color", np.array([0, 1, 0, 1],
                                                 dtype=np.float32))
        self.shader.set_buffer("indices", np.array([0, 1, 2], dtype=np.uint32))