Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Make stuff big. Really big.  (Read 4461 times)

0 Members and 1 Guest are viewing this topic.

deps

  • Newbie
  • *
  • Posts: 14
    • View Profile
Make stuff big. Really big.
« 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.
Code: [Select]
# 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.

Code: [Select]
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Make stuff big. Really big.
« Reply #1 on: May 09, 2008, 03:20:14 am »
Looks like you missed the main call :
Code: [Select]
win.setView(view)
;)
Laurent Gomila - SFML developer

deps

  • Newbie
  • *
  • Posts: 14
    • View Profile
Make stuff big. Really big.
« Reply #2 on: May 09, 2008, 09:52:56 am »
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. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Make stuff big. Really big.
« Reply #3 on: May 09, 2008, 10:41:27 am »
Try that :
Code: [Select]
tiles_gfx.setSmooth( false )
Laurent Gomila - SFML developer

deps

  • Newbie
  • *
  • Posts: 14
    • View Profile
Make stuff big. Really big.
« Reply #4 on: May 09, 2008, 10:49:34 am »
Excellent! Will try this out as soon as I get off from work!

Thanks a lot!  :D

deps

  • Newbie
  • *
  • Posts: 14
    • View Profile
Make stuff big. Really big.
« Reply #5 on: May 10, 2008, 12:00:42 pm »
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.

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:
Code: [Select]

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 )

acrin1

  • Newbie
  • *
  • Posts: 45
    • View Profile
    • http://www.crpgdev.com
Make stuff big. Really big.
« Reply #6 on: May 12, 2008, 01:50:40 pm »
Quote from: "deps"
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.

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:
Code: [Select]

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)));

deps

  • Newbie
  • *
  • Posts: 14
    • View Profile
Make stuff big. Really big.
« Reply #7 on: May 14, 2008, 07:25:11 am »
Well. Yes.
How stupid of me. :P
Thanks. :)