def init_camera_ortho():
    global _camera_ortho
    global _winW
    global _winH
    _camera_ortho = gh_camera.create_ortho(-_winW / 2, _winW / 2, -_winH / 2,
                                           _winH / 2, 1.0, -1.0)
    gh_camera.set_viewport(_camera_ortho, 0, 0, _winW, _winH)
    gh_camera.set_position(_camera_ortho, 0, 0, 1)
    _old_camera_ortho = _camera_ortho
Exemplo n.º 2
0
def ftgl_init():
    global _ftgl_initialized, _ftgl_camera_ortho
    if (_ftgl_initialized == 0):
        ftgl_init_font_gpu_program()
        winW, winH = gh_window.getsize(0)
        _ftgl_camera_ortho = gh_camera.create_ortho(-winW / 2, winW / 2,
                                                    -winH / 2, winH / 2, 1.0,
                                                    10.0)
        gh_camera.set_viewport(_ftgl_camera_ortho, 0, 0, winW, winH)
        gh_camera.set_position(_ftgl_camera_ortho, 0, 0, 4)
        gh_camera.set_lookat(_ftgl_camera_ortho, 0, 0, 0, 1)
        _ftgl_initialized = 1
def init_camera_perspective():
    global _camera_persp
    global _winW
    global _winH
    global _camera_persp_fov
    global _old_camera_persp
    aspect = _winW / _winH
    _camera_persp = gh_camera.create_persp(_camera_persp_fov, aspect, 0.1,
                                           1000.0)
    gh_camera.set_viewport(_camera_persp, 0, 0, _winW, _winH)
    gh_camera.set_position(_camera_persp, 0, 10, 50)
    gh_camera.set_lookat(_camera_persp, 0, 0, 0, 1)
    gh_camera.setupvec(_camera_persp, 0, 1, 0, 0)
    _old_camera_persp = _camera_persp
 def update_perspective(self, camera, fov, is_vertical_fov, viewport_x,
                        viewport_y, viewport_width, viewport_height, znear,
                        zfar):
     camera._viewport.x = viewport_x
     camera._viewport.y = viewport_y
     camera._viewport.width = viewport_width
     camera._viewport.height = viewport_height
     camera._fov = fov
     camera._znear = znear
     camera._zfar = zfar
     aspect = float(viewport_width) / float(viewport_height)
     #gh_camera.update_persp_v2(camera._id, fov, is_vertical_fov, aspect, znear, zfar)
     gh_camera.update_persp(camera._id, fov, aspect, znear, zfar)
     gh_camera.set_viewport(camera._id, viewport_x, viewport_y,
                            viewport_width, viewport_height)
 def create_perspective(self, fov, is_vertical_fov, viewport_x, viewport_y,
                        viewport_width, viewport_height, znear, zfar):
     camera = self._create()
     camera._viewport.x = viewport_x
     camera._viewport.y = viewport_y
     camera._viewport.width = viewport_width
     camera._viewport.height = viewport_height
     camera._fov = fov
     camera._znear = znear
     camera._zfar = zfar
     aspect = float(viewport_width) / float(viewport_height)
     #camera._id = gh_camera.create_persp_v2(fov, is_vertical_fov, aspect, znear, zfar)
     camera._id = gh_camera.create_persp(fov, aspect, znear, zfar)
     gh_camera.set_viewport(camera._id, viewport_x, viewport_y,
                            viewport_width, viewport_height)
     gh_camera.set_position(camera._id, 0, 0, 20)
     gh_camera.set_lookat(camera._id, 0, 0, 0, 1)
     gh_camera.setupvec(camera._id, 0, 1, 0, 0)
     return camera
 def resize(self):
     global _font
     global _winW
     global _winH
     global _camera_persp
     global _camera_persp_fov
     global _camera_ortho
     global _bkg_quad
     _winW, _winH = gh_window.getsize(0)
     aspect = 1.333
     if (_winH > 0):
         aspect = _winW / _winH
     gh_camera.update_persp(_camera_persp, _camera_persp_fov, aspect, 0.1,
                            1000.0)
     gh_camera.set_viewport(_camera_persp, 0, 0, _winW, _winH)
     gh_camera.update_ortho(_camera_ortho, -_winW / 2, _winW / 2,
                            -_winH / 2, _winH / 2, 1.0, -1.0)
     gh_camera.set_viewport(_camera_ortho, 0, 0, -_winW, _winH)
     gh_mesh.update_quad_size(_bkg_quad, _winW, _winH)
     gh_utils.font_set_viewport_info(_font, 0, 0, _winW, _winH)
Exemplo n.º 7
0
def ftgl_resize(w, h):
    global _ftgl_camera_ortho
    gh_camera.update_ortho(_ftgl_camera_ortho, -w / 2, w / 2, -h / 2, h / 2,
                           1.0, 10.0)
    gh_camera.set_viewport(_ftgl_camera_ortho, 0, 0, w, h)
    def initialize(self):
        self._last_time = gh_utils.get_elapsed_time()
        lib_dir = gh_utils.get_scripting_libs_dir()
        #self._font_title_default = ftgl_load_font_v2(lib_dir + "common/Vampire Raves.otf", 30, 0, 0)
        self._font_title_default = ftgl_load_font_v2(
            lib_dir + "common/coolvetica rg.ttf", 30, 0, 0)
        self._font_default = ftgl_load_font_v2(
            lib_dir + "common/BebasNeue.otf", 20, 0, 0)
        self._font_default_user = ftgl_load_font_v2(
            lib_dir + "common/coolvetica rg.ttf", 20, 0, 0)
        self._gl_version = gh_renderer.get_api_version()
        self._gl_renderer = gh_renderer.get_renderer_model()
        self._GL_SAMPLES, y, z, w = gh_renderer.get_capability_4i("GL_SAMPLES")
        self._client_width, self._client_height = gh_window.getsize(0)
        if (gh_utils.get_platform() == 1):
            self._main_title = "GLSL Hacker (Windows 64-bit)"
        elif (gh_utils.get_platform() == 2):
            self._main_title = "GLSL Hacker (Mac OS X 64-bit)"
        elif (gh_utils.get_platform() == 3):
            self._main_title = "GLSL Hacker (Linux 64-bit)"
        elif (gh_utils.get_platform() == 4):
            self._main_title = "GLSL Hacker (Raspberry Pi x32)"

        PF_U8_RGBA = 3
        self._tex_mouse = gh_texture.create_from_file(
            lib_dir + "common/mouse-pointer-md.png", PF_U8_RGBA, 1)

        color_program_vs_gl3 = " \
    #version 150\
    in vec4 gxl3d_Position;\
    uniform mat4 gxl3d_ModelViewProjectionMatrix; \
    void main() \
    { \
      gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;\
    }"

        color_program_ps_gl3 = " \
    #version 150\
    uniform vec4 color;\
    out vec4 gl_FragColor;\
    void main() \
    { \
      gl_FragColor = color;  \
    }"

        color_program_vs_gles2 = " \
    attribute vec4 gxl3d_Position;\
    uniform mat4 gxl3d_ModelViewProjectionMatrix; \
    void main() \
    { \
      gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;\
    }"

        color_program_ps_gles2 = " \
    uniform vec4 color;\
    void main() \
    { \
      gl_FragColor = color;  \
    }"

        if (gh_utils.get_platform() == 4):
            self._color_program = gh_gpu_program.create_v2(
                "gfx_color_program", color_program_vs_gles2,
                color_program_ps_gles2)
        else:
            self._color_program = gh_gpu_program.create(
                "gfx_color_program", color_program_vs_gl3,
                color_program_ps_gl3)

        texture_program_vs_gl3 = " \
    #version 150\
    in vec4 gxl3d_Position;\
    in vec4 gxl3d_TexCoord0;\
    uniform mat4 gxl3d_ModelViewProjectionMatrix; \
    out vec4 Vertex_UV;\
    void main() \
    { \
      gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;\
      Vertex_UV = gxl3d_TexCoord0;\
    }"

        texture_program_ps_gl3 = " \
    #version 150\
    uniform sampler2D tex0;\
    uniform vec4 color;\
    varying vec4 Vertex_UV;\
    out vec4 gl_FragColor;\
    void main() \
    { \
      vec2 uv = Vertex_UV.xy;\
      uv.y *= -1.0;\
      vec4 t = texture(tex0,uv);\
      if ((t.r == 1.0) && (t.g < 1.0) && (t.g < 1.0))\
        gl_FragColor = color;  \
      else \
       discard;\
    }"

        texture_program_vs_gles2 = " \
    attribute vec4 gxl3d_Position;\
    attribute vec4 gxl3d_TexCoord0;\
    uniform mat4 gxl3d_ModelViewProjectionMatrix; \
    varying vec4 Vertex_UV;\
    void main() \
    { \
      gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;\
      Vertex_UV = gxl3d_TexCoord0;\
    }"

        texture_program_ps_gles2 = " \
    uniform sampler2D tex0;\
    uniform vec4 color;\
    varying vec4 Vertex_UV;\
    void main() \
    { \
      vec2 uv = Vertex_UV.xy;\
      uv.y *= -1.0;\
      vec4 t = texture2D(tex0,uv);\
      if ((t.r == 1.0) && (t.g < 1.0) && (t.b < 1.0))\
        gl_FragColor = color;  \
      else \
       discard;\
    }"

        if (gh_utils.get_platform() == 4):
            self.texture_program = gh_gpu_program.create_v2(
                "gfx_texture_program", texture_program_vs_gles2,
                texture_program_ps_gles2)
        else:
            self.texture_program = gh_gpu_program.create(
                "gfx_texture_program", texture_program_vs_gl3,
                texture_program_ps_gl3)

        gh_gpu_program.uniform1i(self.texture_program, "tex0", 0)

        winW, winH = gh_window.getsize(0)
        self._camera_ortho = gh_camera.create_ortho(-winW / 2.0, winW / 2.0,
                                                    -winH / 2.0, winH / 2.0,
                                                    1.0, 10.0)
        gh_camera.set_viewport(self._camera_ortho, 0, 0, winW, winH)
        gh_camera.set_position(self._camera_ortho, 0, 0, 4)

        self._mouse_quad = gh_mesh.create_quad(self._mouse_quad_width,
                                               self._mouse_quad_height)
 def updatePerspective(self, camera, fov, aspect, znear, zfar):
     gh_camera.update_persp(camera, fov, aspect, znear, zfar)
     viewport_width, viewport_height = gh_window.getsize(0)
     gh_camera.set_viewport(camera, 0, 0, viewport_width, viewport_height)
Exemplo n.º 10
0
 def newPersp(self, fov, aspect, znear, zfar):
     viewport_width, viewport_height = gh_window.getsize(0)
     c = gh_camera.create_persp(fov, aspect, znear, zfar)
     gh_camera.set_viewport(c, 0, 0, viewport_width, viewport_height)
     return c