SFML community forums
Help => Graphics => Topic started by: deps on May 09, 2008, 12:21:48 am
-
Hello, found out about SFML not long ago and is trying it out.
I love the ruby language and was happy I found a promising graphics library for it.
Using the prebuilt windows Ruby package, and I have a couple of questions.
First, How can I set up the projection matrix, or whatever it is called, to make the resolution 160x120, and still keep the window size as 640x480.
I tried something like this, but is having some problems.
# The graphics mode we want to use
mode = VideoMode.new( 640,480, 32)
# Open up a window
win = RenderWindow.new( mode, "My test", 0 )
# Set up a view
view = View.new( FloatRect.new(0,0,160,120) )
For some reason sprites isn't getting scaled.
I draw them using win.draw( my_sprite ) and its drawn at the top left, and in its original size.
It also looks a bit blury. (Most likely because of subpixel accuracy or mipmapping or something. I'm not so good at this hardware accelerated thingys :) )
Would really appreciate some help.
If needed, here's what I have at the moment. It's not much but I have only been working on it for an hour or so.
require 'RubySFML'
include SFML
# The graphics mode we want to use
mode = VideoMode.new( 640,480, 32)
# Open up a window
win = RenderWindow.new( mode, "My test", 0 )
# Set up a view
view = View.new( FloatRect.new(0,0,160,120) )
# Misc settings
win.showMouseCursor( false )
win.useVerticalSync( true )
# Load images
tiles_gfx = Image.new("tiles.png")
tiles = Sprite.new( tiles_gfx )
# Main loop
done = false
while !done
while e = win.getEvent()
done = true if e.type == Event::Closed or
(e.type == Event::KeyReleased and e.code == Key::Escape)
end
# GFX
win.draw( tiles )
win.display()
sleep(0.01)
end
Thank you
-
Looks like you missed the main call :
win.setView(view)
;)
-
Uhm... Never mind that. Was just checking if you guys were awake. :oops:
How about the blurriness of the sprites? Can I some how turn off the mipmapping/texturefilter/whateveritis that is causing it? I'm going to try to get some retro feel to it so I want nice crisp pixels. :)
-
Try that :
tiles_gfx.setSmooth( false )
-
Excellent! Will try this out as soon as I get off from work!
Thanks a lot! :D
-
Works just great. :)
Got a new little problem...
I have a lot of tiles in one texture and only wants to draw one at a time instead of the whole image. After some digging around in the docs I came up with this. But the result is a bit wrong.
(http://image.bayimg.com/pajmoaabj.jpg)
The left one is the one produced by SFML, the right one is what I was expecting.
As you can see, the left one only got half of the edge pixels drawn.
The relevant code used:
tiles_gfx = Image.new("tiles.png")
tiles_gfx.setSmooth( false )
tiles = Sprite.new( tiles_gfx )
# ... later in the source
tiles.setSubRect( IntRect.new(0,0,8,8) )
win.draw( tiles )
-
Works just great. :)
Got a new little problem...
I have a lot of tiles in one texture and only wants to draw one at a time instead of the whole image. After some digging around in the docs I came up with this. But the result is a bit wrong.
(http://image.bayimg.com/pajmoaabj.jpg)
The left one is the one produced by SFML, the right one is what I was expecting.
As you can see, the left one only got half of the edge pixels drawn.
The relevant code used:
tiles_gfx = Image.new("tiles.png")
tiles_gfx.setSmooth( false )
tiles = Sprite.new( tiles_gfx )
# ... later in the source
tiles.setSubRect( IntRect.new(0,0,8,8) )
win.draw( tiles )
Assuming that you're trying to set a rectangle of 8 x 8 pixels should your rectangle be 0,0,7,7? I'm doing the same in one of my projects and this seems to work fine (for a 32x32 image):
Tile.SetSubRect(sf::IntRect(tileX, tileY , (tileX+32), (tileY+32)));
-
Well. Yes.
How stupid of me. :P
Thanks. :)