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

Author Topic: Simple static 2d shadows  (Read 11822 times)

0 Members and 1 Guest are viewing this topic.

general sirhc

  • Newbie
  • *
  • Posts: 19
    • View Profile
Simple static 2d shadows
« on: August 10, 2010, 10:29:57 am »
I am currently converting my game from GML (Game Maker Language) to C++ and I am using the SFML library for all graphics however I am having a lot of trouble replicating how surfaces in GM work.

A surface in GM is basically a render target which you can draw onto.

My actual problem is that I have static shadows that I want to draw with say an alpha of 0.6 (these are loaded from file) but the shadows overlap when they're drawn and the overlap areas are darker because of it, so I was wondering how do I draw them all say to say another image or something and then draw that image as a sprite with 0.6 alpha

Apologies if I didn't make myself clear enough, its a bit confusing to explain.

I'm using SFML 1.6.

Thanks to anyone that can help

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Simple static 2d shadows
« Reply #1 on: August 10, 2010, 10:33:39 am »
If all you need is a pixel copy, you can use Image::Copy.

If you really need to draw to an image like you would do to a window, SFML 2 has the RenderImage class.
Laurent Gomila - SFML developer

general sirhc

  • Newbie
  • *
  • Posts: 19
    • View Profile
Simple static 2d shadows
« Reply #2 on: August 10, 2010, 10:40:09 am »
Thank you for the very quick reply.

I don't think copy will work in this situation because the in game world is a giant map (not like a simple level based game where everything is on the screen at once) and that the map is built by the player so although the shadows are static they image that has all the shadows needs to be updated fairly often. I decided against using copy because "This function does a slow pixel copy and should only be used at initialization time"

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Simple static 2d shadows
« Reply #3 on: August 10, 2010, 10:46:28 am »
Ok I see, you really need the RenderImage class. But you'll have to switch to SFML 2.0, which has not been released yet (but is stable enough to be used).

And don't forget that images have a maximum size, you probably won't be able to render your giant map in a single sf::Image.
Laurent Gomila - SFML developer

general sirhc

  • Newbie
  • *
  • Posts: 19
    • View Profile
Simple static 2d shadows
« Reply #4 on: August 10, 2010, 10:58:42 am »
Sadly that what I was thinking would be the end result.

Don't worry although I am new to SFML and not as much C++ I still have got my fair share of programming experience and I have learned my lesson from having very large amounts of useless data.

I only plan on rendering shadows that you can see, not to mention that the map can reach 2621400px X 2621400px at the moment and I plan on increasing it, so attempting to render every shadow would probably cause some problems :P

EDIT:
I don't suppose there is a chance of a private or beta release of SFML 2, I am not worried if you change it later on and I need to do some minor fixes. I would just like to get this working sooner rather than later.

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Simple static 2d shadows
« Reply #5 on: August 10, 2010, 08:27:49 pm »
Quote from: "general sirhc"

I don't suppose there is a chance of a private or beta release of SFML 2, I am not worried if you change it later on and I need to do some minor fixes. I would just like to get this working sooner rather than later.


You can grab the latest version from the SVN repository.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Simple static 2d shadows
« Reply #6 on: August 10, 2010, 09:36:45 pm »
If you don't like SVN, there are even snapshots archives directly available on the download page.
Laurent Gomila - SFML developer

general sirhc

  • Newbie
  • *
  • Posts: 19
    • View Profile
Simple static 2d shadows
« Reply #7 on: August 11, 2010, 01:55:19 pm »
Okay so now that I have SFML 2, I'm not really sure of the syntax of the new commands, is there is documentation yet or do I just look at the arguments for the functions?

After trying to run my project on SFML 2 I am getting compile errors saying that "no matching function for call to 'sf::RenderWindow::Draw(sf::String&)', it might be something really stupid I've done because I'm tired but help would be nice none the less (Apologies if its something stupid cause i'm tired)


Also on the tutorial page for mingw saying how to set up SFML I noticed this minor typo

"Go to SFML-x.y\build\codeblocks, and open the file SFML.workspace. Choose the configuration you want to build (Debug or Release, Static or DLL), and ---->clic<---- "build workspace". This should create the corresponding SFML library files in the lib directory, as well as the sample executables."

Just thought you might be interested

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Simple static 2d shadows
« Reply #8 on: August 11, 2010, 02:06:19 pm »
Documentation is here:
http://www.sfml-dev.org/documentation/2.0/

There's no porting guide yet, but you look at the General forum for major changes, I usually open a new discussion for all of them.

Regarding your error, sf::String is now sf::Text ;)
Laurent Gomila - SFML developer

general sirhc

  • Newbie
  • *
  • Posts: 19
    • View Profile
Simple static 2d shadows
« Reply #9 on: August 11, 2010, 02:33:47 pm »
Wow you're so helpful =) Definitely the best forum admin I have ever seen =)

Thanks so much and I don't know if it is helpful but here is my current list of things that I needed to changed from 1.6 -> 2.0

    [-]Image() default constructor doesn't take width, height and color arguments anymore instead you have to use create after making the image.
    [-]To get the height and width of a float rect you just use .height or .width instead of GetHeight or GetWidth
    [-]SetText is now SetString
    [-]SetCenter is now SetOrigin
    [-]SetSize is now SetCharacterSize
    [-]GetCharacterSize has been removed because you can set font size in the text object
    [-]SetFromRect for views is now SetViewport
    [-]SocketTCP is not TcpSocket (Note the capitals it is case sensitive)
    [-]Connect(port,IP) is now Connect(IP,port,timeout)
    [-]Close() for networking is now Disconnect()


If you would like I will continue editting this post with all the things I had to change in my project <Not really sure if its useful to you>

EDIT:
Thanks for the clarification on SetCenters replacement

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Simple static 2d shadows
« Reply #10 on: August 11, 2010, 03:08:56 pm »
Quote
[-]SetCenter is now SetPosition <I think...>

SetOrigin ;)
Laurent Gomila - SFML developer

general sirhc

  • Newbie
  • *
  • Posts: 19
    • View Profile
Simple static 2d shadows
« Reply #11 on: August 11, 2010, 04:38:38 pm »
Never mind, it couldn't find the files because when they're compiled by the SFML 2.0 stuff they get put into a mingw folder inside the lib folder and that was the problem cause I was searching in the lib folder and not the mingw folder

Btw I added some more things to my list

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Simple static 2d shadows
« Reply #12 on: August 11, 2010, 05:09:04 pm »
Quote
[-]SocketTCP is not TcpSOCKET (Note the capitals it is case sensitive)

TcpSocket, not TcpSOCKET.

There are many many more changes, so I'm not sure this list is worth the effort. I should probably make my own changelog public, instead :lol:
Laurent Gomila - SFML developer

general sirhc

  • Newbie
  • *
  • Posts: 19
    • View Profile
Simple static 2d shadows
« Reply #13 on: August 11, 2010, 05:21:28 pm »
Hehe woops =p

Yeah it probably isn't worth the effort.

Btw I fixed my other problem and it compiles and runs and the login screen is fine and everything is drawn as normal (however this bit doesn't have views yet) After the login screen it starts using views, so I am using view.SetCenter but the screen is just black, im not sure if its something I'm doing or what, however I just realised I have some HUD which are always drawn no matter where the view is so the HUD should be getting drawn but its not, any ideas?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Simple static 2d shadows
« Reply #14 on: August 11, 2010, 05:46:22 pm »
The View class has changed quite a lot, you should make sure that you've properly converted everything.
Laurent Gomila - SFML developer

 

anything