Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / How to create an image without image
- - By Andrek Date 2012-02-27 16:53
Hello, you need to know how to create an image without using a picture, to understand:

width = 100
height = 100
@image =, [width, height], false)

If not possible with Gosu, also use TexPlay. Thank you very much.
Parent - - By lol_o2 Date 2012-02-27 19:00
TexPlay.create_image(window, width, height)
If you want a specified color add :color => color at the end.
Parent - By Andrek Date 2012-02-28 10:48
Thank you very much, is exactly what I wanted :D.
Parent - - By jlnr (dev) Date 2012-02-28 03:04
You can fake the interface for RMagick images:

class EmptyImageSource < Struct(:columns, :rows)
  def to_blob; "\0" * columns * rows * 4; end;

empty_image =,, height), ...)

Untested. Maybe it is cols instead of columns.
Parent - - By Andrek Date 2012-02-28 11:00
This method does not help me, gives me an error:

TestGosuTexPlay.rb:4:in <main>': undefined method Struct' for main:Object (NoMethodError)

But thank you very much lol_o2 helped me. I have not the RMagick gem.
Parent - - By RavensKrag Date 2012-02-28 15:53
It should probably be, :rows) I believe.  I haven't tested it either though.

But this code should not require the RMagick gem to work.  It merely creates a binary blob which gosu will interpret as being a blank RMagic image object.
Parent - - By Andrek Date 2012-02-28 17:12 Edited 2012-02-28 17:20
It worked!, This approach is better because you can use the rect, exactly at this time had that error. Thank you very much: D.

@image =,, 100), tileable, rect_x, rect_y, rect_width, rect_height)

Is there any way to edit the rect? so:

@image.rect_x = x
@image.rect_y = y
@image.rect_width = width
@image.rect_height = height


@image.set_rect(x, y, width, height)
Parent - - By jlnr (dev) Date 2012-03-01 08:33
What would you like to happen when you change x/y? From Gosu's PoV, an Image has no position. You can move an image in itself without Texplay by calling @image.insert(@image, offset_x, offset_y). Gosu does not allow you to resize an image though, and Texplay cannot do this without creating a new image either.
Parent - By Andrek Date 2012-03-01 12:03
Thanks but does not solve everything I need. This method is best: Thank you very much :D.
Parent - - By RavensKrag Date 2012-03-01 15:51
I suspect that you're looking at this from a too low-level perspective.  Are you perhaps coming from pygame/rubygame? Your methodology seems similar to those frameworks, from what little I know of them.

With it's OpenGL backend, I don't see any reason to resize images in this way, if you are indeed resizing images.  If you need to somehow resize and then add to a single texture, you should probably drop to OpenGL and then use render to texture instead.  However, this should only be necessary if you're going to apply a shader or something to the whole resultant texture.  Even in that case, there might be a better way to do that. 

If you wanted to render to texture it seems that texplay has a means for doing this, you don't want to use raw OpenGL.

For resizing, it would be better to just use Image#draw() and take advantage of the factor_x and factor_y to rescale.  If you're trying to avoid the fuzzyness which comes from that, I believe there is something having to do with a "undocumented retrofication" method you can use.  Though, Julian would know more about than I do, as the method is, of course, undocumented.

Not trying to tell you how to write your code, but I wouldn't want you to become a victim of premature optimization or some related problem.  I know I've done that far too many times myself.
Parent - - By Andrek Date 2012-03-01 18:18
I do not speak much English but I think I understood what I said and never used pygame/rubygame. I am creating a library with Gosu/TexPlay.

In order not to talk too much I'm going to put a code showing what I want to do:

class Window_Command < Window_Base
  def initialize(width, commands)
    self.width = width
    self.height = 64 # Window height
    @index = 0
    @commads = commands
    @cursor =
    @cursor.bitmap ='cursor.png') # Bitmap is equal Gosu::Image but Bitmap is created by my.
    self.contents =, commands.length * 32) # width = 192; height = 96
    self.contents.src_rect =, 0, self.width, self.height) # Not show beyond the window height.
  def refresh
    for c in 0...@commands.length # 0, 1, 2
      draw_item(@commands[c], c)
  def draw_item(text, index)
    self.contents.draw_text(0, index * 32, text) # (x, y, string) I need to create this method.
  def update
    if Keyboard.trigger?(:Down)
      @index += 1
    elsif Keyboard.trigger?(:Up)
      @index -= 1
    @cursor.y = @index * 32
  def update_src_rect
    case @index
    when 0..1 then self.contents.src_rect.y = 0
    when 3 then self.contents.src_rect.y = 32

window_commands = Window_Command(192, ['New Game', 'Continue', 'Exit'])

if Keyboard.trigger?(:Enter)
  case window_commands.index
  when 0 # New Game
  when 1 # Continue
  when 2 # Exit

This code creates a window in the game like Final Fantasy, to select options at the beginning of the game, but are only visible two squares the third is created but not visible (src_rect). I hope you find me understand.

My methodology is the RPG Maker XP.
Parent - - By jlnr (dev) Date 2012-03-02 04:52
Ah, I see! It is not efficient to create new Images with Gosu; what you want to do is just draw all the items all the time, but use clip_to(rect) { your_rendering_code_here }. clip_to works with screen coordinates, not texture coordinates, but will do what you want - cut off what should be invisible.
Parent - - By Andrek Date 2012-03-02 15:00
I can not understand how to use clip_to, if I can help I'd appreciate.
Parent - - By lol_o2 Date 2012-03-02 16:01
When you have draw inside Window class:
clip_to(x,y,width,height) do

Outside Window class, pass it for Window object variable (like: $window.clip to(...) do ...)
Parent - By Andrek Date 2012-03-02 16:15
Ahhhh!!! ok i understand :D.
Parent - By Spooner Date 2012-02-28 23:59
Yeah, pretty much the way Texplay does it. There is no magic involved.
Up Topic Gosu / Gosu Exchange / How to create an image without image

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill