class Gosu::Graphics

Constants

MAX_TEXTURE_SIZE

Attributes

fullscreen[R]
gl[R]
height[R]
width[R]

Public Class Methods

new(android_initializer) click to toggle source
# File lib/gosu_android/graphics/graphics.rb, line 20
def initialize(android_initializer)
  @android_initializer = android_initializer
end

Public Instance Methods

begin(clear_with_color = Color::BLACK) click to toggle source

Prepares the graphics object for drawing. Nothing must be drawn without calling begin.

# File lib/gosu_android/graphics/graphics.rb, line 43
def begin(clear_with_color = Color::BLACK)
  if @gl == nil
    raise "Surface must be created before calling begin"
  end
  @gl.glClearColor(clear_with_color.red / 255.0, clear_with_color.green / 255.0,
    clear_with_color.blue / 255.0, clear_with_color.alpha / 255.0)
  @gl.glClear(JavaImports::GL10::GL_COLOR_BUFFER_BIT | JavaImports::GL10::GL_DEPTH_BUFFER_BIT)

  true
end
beginGL() click to toggle source

Finishes all pending Gosu drawing operations and executes the following OpenGL code in a clean environment.

# File lib/gosu_android/graphics/graphics.rb, line 67
def beginGL; end
begin_clipping(x, y, width, height) click to toggle source

Enables clipping to a specified rectangle.

# File lib/gosu_android/graphics/graphics.rb, line 79
def begin_clipping(x,  y,  width,  height); end
begin_recording() click to toggle source

Starts recording a macro. Cannot be nested.

# File lib/gosu_android/graphics/graphics.rb, line 84
def begin_recording; end
create_image(src, src_x, src_y, src_width, src_height, border_flags) click to toggle source

TODO If @gl == nil Texture.new will fail, this has to be fixed Turns a portion of a bitmap o something that can be drawn on this graphics object.

# File lib/gosu_android/graphics/graphics.rb, line 137
def create_image(src, src_x,  src_y,  src_width,  src_height, border_flags)
  max_size = MAX_TEXTURE_SIZE
  #Special case: If the texture is supposed to have hard borders,
  #is quadratic, has a size that is at least 64 pixels but less than 256
  #pixels and a power of two, create a single texture just for this image.
  if ((border_flags & BF_TILEABLE) == BF_TILEABLE and src_width == src_height and
    (src_width & (src_width - 1)) == 0 and src_width >= 64)

    texture = Texture.new(src_width, @gl)
    #Use the source bitmap directly if the source area completely covers
    #it.
    if (src_x == 0 and src_width == src.width and src_y == 0 and src_height == src.height)
      data = texture.try_alloc(self, @queues, texture, src, 0)
    else
      trimmed_src = Bitmap.new
      trimmed_src.resize(src_width, src_height)
      trimmed_src.insert(src, 0, 0, src_x, src_y, src_width, src_height)
      data = texture.try_alloc(self, @queues, texture, trimmed_src, 0)
    end

    if data == nil
        raise "Internal texture block allocation error"
    end
    return data
  end

  #Too large to fit on a single texture.
  #TODO LargeImageData not implemented yet
  if (src_width > max_size - 2 || src_height > max_size - 2)
    bmp = Bitmap.new(src_width, src_height)
    bmp.insert(src, 0, 0, src_x, src_y, src_width, src_height)
    lidi = LargeImageData.new(self, bmp, max_size - 2, max_size - 2, border_flags)
    return lidi
  end

  bmp = Bitmap.new
  Gosu::apply_border_flags(bmp, src, src_x, src_y, src_width, src_height, border_flags)

  #Try to put the bitmap into one of the already allocated textures.
  @textures.each do |tex|
    data = tex.try_alloc(self, @queues, tex, bmp, 1)
      return data if data != nil
  end

  #All textures are full: Create a new one.
  texture = Texture.new(max_size, @gl)
  @textures.push texture

  data = texture.try_alloc(self, @queues, texture, bmp, 1)
  if data == nil
    raise "Internal texture block allocation error"
  end
  data
end
draw_line( x1, y1, c1, x2, y2, c2, z, mode) click to toggle source

Draws a line from one po to another (last pixel exclusive). Note: OpenGL lines are not reliable at all and may have a missing pixel at the start or end po. Please only use this for debugging purposes. Otherwise, use a quad or image to simulate lines, or contribute a better drawLine to Gosu.

# File lib/gosu_android/graphics/graphics.rb, line 101
def draw_line( x1,  y1,  c1, x2,  y2,  c2, z,  mode)
  op = @queues.op_pool.newDrawOp
  op.render_state.mode = mode
  op.vertices_or_block_index = 2
  op.vertices[0].set(x1, y1, c1)
  op.vertices[1].set(x2, y2, c2)
  op.z = z
  @queues.schedule_draw_op op
end
draw_quad( x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode) click to toggle source
# File lib/gosu_android/graphics/graphics.rb, line 122
def draw_quad( x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode)
  op = @queues.op_pool.newDrawOp
  op.render_state.mode = mode
  op.vertices_or_block_index = 4
  op.vertices[0].set(x1, y1, c1)
  op.vertices[1].set(x2, y2, c2)
  op.vertices[2].set(x3, y3, c3)
  op.vertices[3].set(x4, y4, c4)
  op.z = z
  @queues.schedule_draw_op op
end
draw_triangle( x1, y1, c1, x2, y2, c2, x3, y3, c3, z, mode) click to toggle source
# File lib/gosu_android/graphics/graphics.rb, line 111
def draw_triangle( x1,  y1,  c1, x2,  y2,  c2, x3,  y3,  c3, z,  mode)
  op = @queues.op_pool.newDrawOp
  op.render_state.mode = mode
  op.vertices_or_block_index = 3
  op.vertices[0].set(x1, y1, c1)
  op.vertices[1].set(x2, y2, c2)
  op.vertices[2].set(x3, y3, c3)
  op.z = z
  @queues.schedule_draw_op op
end
end() click to toggle source

Every call to begin must have a matching call to end.

# File lib/gosu_android/graphics/graphics.rb, line 54
def end
  flush
  @gl.glFlush
end
endGL() click to toggle source

Resets Gosu o its default rendering state.

# File lib/gosu_android/graphics/graphics.rb, line 69
def endGL; end
end_clipping() click to toggle source

Disables clipping.

# File lib/gosu_android/graphics/graphics.rb, line 81
def end_clipping; end
end_recording(width, height) click to toggle source

Finishes building the macro and returns it as a drawable object. The width and height affect nothing about the recording process, the resulting macro will simply return these values when you ask it. Most usually, the return value is passed to Image::Image().

# File lib/gosu_android/graphics/graphics.rb, line 90
def end_recording(width,  height); end
flush() click to toggle source

Flushes the Z queue to the screen and starts a new one. Useful for games that are very composite in nature (splitscreen).

# File lib/gosu_android/graphics/graphics.rb, line 60
def flush
  @queues.perform_draw_ops_and_code
  @queues.clear_queue
end
initialize_window(physical_width, physical_height, fullscreen, window) click to toggle source
# File lib/gosu_android/graphics/graphics.rb, line 24
def initialize_window(physical_width, physical_height, fullscreen, window)
  @window = window
  @virt_width = physical_height
  @virt_height = physical_width

  @phys_width = physical_width
  @phys_height = physical_height

  @fullscreen = fullscreen
  #Gl stuff moved to render

  @queues = DrawOpQueue.new(@gl)
  @textures = []
end
onDrawFrame(gl) click to toggle source
# File lib/gosu_android/graphics/graphics.rb, line 192
def onDrawFrame(gl)
  #gl.glClear(JavaImports::GL10::GL_COLOR_BUFFER_BIT | JavaImports::GL10::GL_DEPTH_BUFFER_BIT)
  @window.do_show
  rescue Exception => e
    puts "#{ e } (#{ e.class } #{e.message} #{e.backtrace.inspect} )!"
end
onSurfaceChanged(gl, width, height) click to toggle source
# File lib/gosu_android/graphics/graphics.rb, line 199
def onSurfaceChanged(gl, width, height)
  @gl = gl
  @gl.glViewport(0, 0, width, height)
end
onSurfaceCreated(gl, config) click to toggle source
# File lib/gosu_android/graphics/graphics.rb, line 204
def onSurfaceCreated(gl, config)
  @gl = gl
  #@queues.gl = @gl
  @android_initializer.on_ready
  #Options to improve performance
  @gl.glDisable(JavaImports::GL10::GL_DITHER)
  @gl.glHint(JavaImports::GL10::GL_PERSPECTIVE_CORRECTION_HINT, JavaImports::GL10::GL_FASTEST)

  @gl.glMatrixMode(JavaImports::GL10::GL_PROJECTION)
  @gl.glLoadIdentity
  @gl.glViewport(0, 0, @window.width, @window.height)

  @gl.glOrthof(0, @window.width, @window.height, 0, -1, 1)


  @gl.glMatrixMode(JavaImports::GL10::GL_MODELVIEW)
  @gl.glLoadIdentity

  @gl.glEnable(JavaImports::GL10::GL_BLEND)
  rescue Exception => e
    puts "#{ e } (#{ e.class } #{e.message} #{e.backtrace.inspect} )!"
end
pop_transform() click to toggle source

Pops one transformation from the transformation stack.

# File lib/gosu_android/graphics/graphics.rb, line 95
def pop_transform; end
push_transform(transform) click to toggle source

Pushes one transformation onto the transformation stack.

# File lib/gosu_android/graphics/graphics.rb, line 93
def push_transform(transform); end
scheduleGL(functor, z) click to toggle source

(Experimental) Schedules a custom GL functor to be executed at a certain Z level. The functor is called in a clean GL context (as given by beginGL/endGL). Gosu’s rendering up to the Z level may not yet have been glFlush()ed. Note: You may not call any Gosu rendering functions from within the functor, and you must schedule it from within Window::draw’s call tree.

# File lib/gosu_android/graphics/graphics.rb, line 76
def scheduleGL(functor, z); end
set_resolution(virtualWidth, virtualHeight) click to toggle source
# File lib/gosu_android/graphics/graphics.rb, line 39
def set_resolution(virtualWidth, virtualHeight); end