def orbit_v2(self, camera, lookat_x, lookat_y, lookat_z, mouse_button):
        is_down = gh_input.mouse_get_button_state(mouse_button)
        if ((is_down == 1) and (camera._do_rotate == 0)):
            mx, my = gh_input.mouse_getpos()

            if (gh_utils.get_platform() == 2):  # OSX
                self._init_camera_orbit(camera, mx, -my)
            else:  # Windows and Linux
                self._init_camera_orbit(camera, mx, my)

            camera._do_rotate = 1

        if (is_down == 0):
            camera._do_rotate = 0

        if (camera._do_rotate == 1):
            mx, my = gh_input.mouse_getpos()

            if ((mx != camera._old_mouse_x) or (my != camera._old_mouse_y)):
                if (gh_utils.get_platform() == 2):  # OSX
                    self._rotate_camera_orbit(camera, mx, -my, lookat_x,
                                              lookat_y, lookat_z)
                else:  # Windows and Linux
                    self._rotate_camera_orbit(camera, mx, my, lookat_x,
                                              lookat_y, lookat_z)
    def update(self, camera, dt):
        # Windows platform.
        if (gh_utils.get_platform() == 1):
            gh_window.keyboard_update_buffer(0)

        camera._is_moving = 0
        self.pan(camera, camera._pan_speed_factor)

        if (camera._do_pan == 0):
            if (camera._mode == self._MODE_ORBIT):
                self.update_orbit(camera, dt, camera._lookat_x,
                                  camera._lookat_y, camera._lookat_z)

            elif (camera._mode == self._MODE_FLY):
                self.update_fly(camera, dt)

            elif (camera._mode == self._MODE_FPS):
                self.update_walk(camera, dt)
    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)
Exemplo n.º 4
0
def ftgl_init_font_gpu_program():
    global _ftgl_font_program

    if (_ftgl_font_program > 0):
        return

    ftgl_font_program_vs_gl3 = " \
  #version 150 \
  in vec4 gxl3d_Position; \
  in vec4 gxl3d_TexCoord0; \
  in vec4 gxl3d_Color; \
  uniform mat4 gxl3d_ModelViewProjectionMatrix; \
  uniform vec4 gxl3d_Viewport; \
  out vec4 Vertex_UV; \
  out vec4 Vertex_Color; \
  void main() \
  { \
    vec4 V = vec4(gxl3d_Position.xyz, 1); \
    V.x = V.x - gxl3d_Viewport.z / 2.0; \
    V.y = V.y + gxl3d_Viewport.w / 2.0; \
    gl_Position = gxl3d_ModelViewProjectionMatrix * V; \
    Vertex_UV = gxl3d_TexCoord0; \
    Vertex_Color = gxl3d_Color; \
  }"

    ftgl_font_program_ps_gl3 = " \
  #version 150 \
  uniform sampler2D tex0; \
  in vec4 Vertex_UV; \
  in vec4 Vertex_Color; \
  out vec4 FragColor; \
  void main (void) \
  { \
    vec2 uv = Vertex_UV.xy; \
    vec3 t = texture(tex0,uv).rgb; \
    FragColor = vec4(t.r*Vertex_Color.rgb, Vertex_Color.a * t.r); \
  }"

    ftgl_font_program_vs_gl2 = " \
  #version 120 \
  uniform mat4 gxl3d_ModelViewProjectionMatrix; \
  uniform vec4 gxl3d_Viewport; \
  varying vec4 Vertex_UV; \
  varying vec4 Vertex_Color; \
  void main() \
  { \
    vec4 V = vec4(gl_Vertex.xyz, 1); \
    V.x = V.x - gxl3d_Viewport.z / 2.0; \
    V.y = V.y + gxl3d_Viewport.w / 2.0; \
    gl_Position = gl_ModelViewProjectionMatrix * V;		 \
    Vertex_UV = gl_MultiTexCoord0; \
    Vertex_Color = gl_Color; \
  }"

    ftgl_font_program_ps_gl2 = " \
  #version 120 \
  uniform sampler2D tex0; \
  varying vec4 Vertex_UV; \
  varying vec4 Vertex_Color; \
  void main (void) \
  { \
    vec2 uv = Vertex_UV.xy; \
    vec3 t = texture2D(tex0,uv).rgb; \
    gl_FragColor = vec4(t.r*Vertex_Color.rgb, Vertex_Color.a * t.r); \
  }"

    ftgl_font_program_vs_gles2 = """
  attribute vec4 gxl3d_Position;
  attribute vec4 gxl3d_TexCoord0;
  attribute vec4 gxl3d_Color; 
  uniform mat4 gxl3d_ModelViewProjectionMatrix; 
  uniform vec4 gxl3d_Viewport; 
  varying vec4 Vertex_UV; 
  varying vec4 Vertex_Color; 
  void main() 
  { 
    vec4 V = vec4(gxl3d_Position.xyz, 1.0); 
    V.x = V.x - gxl3d_Viewport.z / 2.0; 
    V.y = V.y + gxl3d_Viewport.w / 2.0; 
    gl_Position = gxl3d_ModelViewProjectionMatrix * V;
    Vertex_UV = gxl3d_TexCoord0;
    Vertex_Color = gxl3d_Color;
  }"""

    ftgl_font_program_ps_gles2 = """
  uniform sampler2D tex0; 
  varying vec4 Vertex_UV; 
  varying vec4 Vertex_Color;
  void main () 
  { 
    vec2 uv = Vertex_UV.xy; 
    vec3 t = texture2D(tex0,uv).rgb; 
    gl_FragColor = vec4(t.r*Vertex_Color.rgb, Vertex_Color.a * t.r); 
    //gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); 
  } """

    if (gh_utils.get_platform() == 4):
        # Raspberry Pi
        _ftgl_font_program = gh_gpu_program.create_v2(
            "ftgl_font_program", ftgl_font_program_vs_gles2,
            ftgl_font_program_ps_gles2)
    else:
        if (gh_renderer.get_api_version_major() >= 3):
            _ftgl_font_program = gh_gpu_program.create_v2(
                "ftgl_font_program", ftgl_font_program_vs_gl3,
                ftgl_font_program_ps_gl3)
        else:
            _ftgl_font_program = gh_gpu_program.create_v2(
                "ftgl_font_program", ftgl_font_program_vs_gl2,
                ftgl_font_program_ps_gl2)
 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 is_rpi(self):
     if (gh_utils.get_platform() == 4):
         return 1
     return 0
 def is_linux(self):
     if (gh_utils.get_platform() == 3):
         return 1
     return 0
 def is_oSX(self):
     if (gh_utils.get_platform() == 2):
         return 1
     return 0
 def is_windows(self):
     if (gh_utils.get_platform() == 1):
         return 1
     return 0