def init(gl_version_major, gl_version_minor):
    global _use_opengl2
    global _elapsed_time
    global _last_time
    global _winW
    global _winH

    _winW, _winH = gh_window.getsize(0)

    set_version(0, 1, 0)

    if (gl_version_major >= 3):
        _use_opengl2 = 0
    else:
        _use_opengl2 = 1

    graphics.init0(_use_opengl2)
    init_font()
    init_camera_perspective()
    init_camera_ortho()
    init_bkg_quad()

    _elapsed_time = gh_window.timer_get_seconds(0)
    _last_time = _elapsed_time

    gh_renderer.clear_color_depth_buffers(0.2, 0.2, 0.2, 1.0, 1.0)
    gh_renderer.set_vsync(0)
    gh_renderer.set_scissor_state(0)
    gh_renderer.set_depth_test_state(1)
    def end_frame(self, show_info):
        if (show_info == 1):
            self.display_info(30)

        if (self._show_mouse == 1):
            winW, winH = gh_window.getsize(0)
            screen_mx, screen_my = self.get_mouse_position()
            self.draw_mouse(screen_mx - winW / 2, winH / 2 - screen_my,
                            self._mouse_color[0], self._mouse_color[1],
                            self._mouse_color[2], self._mouse_color[3], 0)
Example #3
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 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)
    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 get_mouse_position(self):
     mx, my = gh_input.mouse_getpos()
     if (gh_utils.get_platform() == 4):
         w, h = gh_window.getsize(0)
         return (mx + w / 2), -(my - h / 2)
     return mx, my
 def getsize(self):
     return gh_window.getsize(0)
 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)
 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