Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Turning off interpolation?
- - By darkhog Date 2014-01-06 22:39
As we know, Gosu uses hardware acceleration and does mipmapping (interpolation) for all textures. That's cool and dandy, but I plan to make one of these retro, pixel games that are popular nowadays and I want to upscale bitmaps in-engine without interpolation. How can I turn it off?

Also you should consider changing library name, because first thing that is showing when googling is gosu language, not gosu engine ;).
Parent - - By nicklink483 Date 2014-01-06 23:00
I can't remember the link to the forum post, but here's how you do that:

First, make sure you have the ruby-opengl gem.
Then, require 'opengl' in your game file right under require 'gosu'
Then, for each image object you instantiate, add this code right after:

    @image = Gosu::Image.new("cool_retro_scaled_image.bmp", false)

    glBindTexture(GL_TEXTURE_2D, self.gl_tex_info.tex_name)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

I extracted this into a method by opening up the Gosu::Image class in my main game file

class Gosu:Image

  def retro!
   
    glBindTexture(GL_TEXTURE_2D, self.gl_tex_info.tex_name)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
   
    self
 
  end

end

so now when I have an image, I can just do this:

    @image = Gosu::Image.new("cool_retro_scaled_image.bmp", false).retro!

Try it out!  Whenever you @image.draw_rot and you have the scale to something bigger than 1, it will do nearest-neighbor approximation scaling (which is what you're looking for).

Quick edit: here's that other forum post on it: http://www.libgosu.org/cgi-bin/mwf/topic_show.pl?tid=227
Parent - By darkhog Date 2014-01-06 23:05
Thanks!
Parent - - By jlnr (dev) Date 2014-01-07 07:44
The OpenGL snippet has since been turned into the Gosu::enable_undocumented_retrofication method. Just call it once during startup. And please wrap it in a rescue block because I want to deprecate it as soon as I have found a better interface for it %)
Parent - By darkhog Date 2014-01-07 11:02
How about adding optional boolean parameter to image loader function that if true would execute the snippet?

Or, in case change is global, how about Window.interpolation=false?
Up Topic Gosu / Gosu Exchange / Turning off interpolation?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill