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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Moonkis

Pages: [1] 2
Graphics / Lights with blending, doing something wrong.
« on: January 23, 2014, 12:38:54 pm »
I'm trying to implement some basic light using blending. It's based of this https://dl.dropboxusercontent.com/u/36451301/ld/ld27/index.html

I'm trying to implement it by doing it in a few small steps:
You must do it this way:
- fill a render-texture (which covers the whole window) with the dark color
- draw your light(s) to the render-texture with sf::BlendAdd
- draw the render-texture on top of your scene with sf::BlendMultiply

but for some reason the only thing I get is an completely black screen, I'm not sure what exactly I'm doing wrong. If I use Multiply when drawing the lightmap-buffer it litterly only shows black.

Here is a minimal code example:
int main()
        sf::Sprite s_lightmap;
        sf::Sprite s_light;

        sf::RenderTexture t_lightmap;
        sf::Texture t_light;


        sf::Color ambient(0,0,0,255);
        sf::Color lightColor(255,0,0,178);


        sf::RenderWindow window(sf::VideoMode(800,600,32),"Window");
        sf::Event event;


                t_lightmap.draw(s_light, sf::BlendMode::BlendAdd);
                window.draw(s_lightmap, sf::BlendMode::BlendMultiply);

        return 0;

SFML wiki / Is the page still around?
« on: December 06, 2013, 12:13:46 am »
I'm trying to hunt down the:  "[Tutorial]Stock all your resources in a single DAT file" but it appears as the links are broken. Is the tutorial still around somewhere? 

General / [SOLVED] Scaling the window and mouse offset issues
« on: November 13, 2013, 10:04:53 am »
Silly me not properly checking the sf::View tutorial. The answer lies in converting between pixel to world coordinates!



I'm currently working on my Zombie shooter that was originally for the GameBoy Jam. The resolution is 160x144px which is quite small, however we are allowed to scale the game (not the graphics itself) to make it larger.

sf::RenderWindow window(sf::VideoMode(160*4, 144*4, 32), "Doki Doki DX", sf::Style::Titlebar);
window.setView( sf::View(sf::FloatRect(0,0,160,144)) );

The code above is my window scaling code. It works flawlessly except the mouse has a weird offset from the REAL mouse which is a problem since you aim your gun with the mouse and will most likely open another app or click outside of the window seeing as it's not actually there.

In this picture the windows mouse cursor is actually outside of the window, whilst the game cursor (that takes the position of the cursor relative the window) is inside of the window. I can't properly move the mouse around without sliding outside of the window.

I have never scaled a game before and I'm not sure how to "fix" this?

In addition i need to be able to follow my character with a camera however the "mouse" don't keep it's relative position towards the character. I'm not really sure how to solve this, I'v been at it for a while (days) but I'm not sure how to figure out the new position of the...mouse.

I thought getting the new (relative to window) position would have returned the new position relative to where the current view is but that's not how it works.

#include "TextureLocator.hpp"

sf::Texture TextureLocator::textures[TIDS::UNIQUE_TIDS] = {sf::Texture()};

bool TextureLocator::init() {
        return true;

sf::Texture& TextureLocator::get(TIDS id) {
        return textures[id];

I get a runtime error, why? Isn't this legal?
First-chance exception at 0x779422D2 (ntdll.dll) in Leklåda.exe: 0xC0000005: Access violation writing location 0x00000004.
Unhandled exception at 0x779422D2 (ntdll.dll) in Leklåda.exe: 0xC0000005: Access violation writing location 0x00000004.

These are the errors I get. I think they are related to initializing the static array in the .cpp file above. Feels pretty weird to me. Anyone want to shine some light on this.

Here is the callstack as well:

   ntdll.dll!779422d2()   Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]   
    Leklåda.exe!sf::priv::MutexImpl::lock(void)   Unknown
    Leklåda.exe!sf::Mutex::lock(void)   Unknown
    Leklåda.exe!sf::Lock::Lock(class sf::Mutex &)   Unknown
    Leklåda.exe!sf::GlResource::GlResource(void)   Unknown
    Leklåda.exe!sf::Texture::Texture(void)   Unknown
>   Leklåda.exe!`dynamic initializer for 'TextureLocator::textures''() Line 3   C++
    msvcr110d.dll!_initterm(void (void) * * pfbegin, void (void) * * pfend) Line 889   C
    Leklåda.exe!__tmainCRTStartup() Line 460   C
    Leklåda.exe!mainCRTStartup() Line 377   C
    kernel32.dll!75a2336a()   Unknown
    ntdll.dll!77959f72()   Unknown
    ntdll.dll!77959f45()   Unknown

General / Running my game in Linux
« on: September 11, 2013, 12:49:11 pm »
I'm currently running Linux ( Ubuntu ) to be specific and I'v managed to build SFML2.1 from the sources. My only problem now is that I'm not sure how to run my binary ( it compiles just fine ).

It complains about missing the specific .so files - I'm guessing the binary dosen't look in the right place. I know this isn't technically speaking an issue of SFML but I figured ( since it's related ) people here would know what to do.

I followed this guide here about compiling and installing sfml om my system:

So, anyone know how to make sure my binary finds my .so files?

( I know I can do LD_LIBRARY_PATH if I run it from the terminal but I want to be able to just "Run" it like normal without the terminal, so there got to be a map )

General / I'm getting errors when trying to build sfml2 in Ubuntu
« on: May 10, 2013, 01:17:54 pm »
I recently merged from Windows to Ubuntu and so far it's going fairly well. Now I'm trying to set up a development environment thus I need to freshly build SFML and I was following this guide http://sfmlcoder.wordpress.com/2011/08/16/building-sfml-2-0-with-make-for-gcc/:

I installed all the dependencies and ran cmake and then make and all goes well until it's time to build the sound files. I get an error:
[ 87%] Building CXX object src/SFML/Audio/CMakeFiles/sfml-audio.dir/SoundFile.cpp.o
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp: In static member function ‘static sf_count_t sf::priv::SoundFile::Stream::read(void*, sf_count_t, void*)’:
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:388:56: error: no matching function for call to ‘min(sf_count_t&, sf::Int64)’
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:388:56: note: candidates are:
In file included from /usr/include/c++/4.7/bits/char_traits.h:41:0,
                 from /usr/include/c++/4.7/string:42,
                 from /home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.hpp:34,
                 from /home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:28:
/usr/include/c++/4.7/bits/stl_algobase.h:187:5: note: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
/usr/include/c++/4.7/bits/stl_algobase.h:187:5: note:   template argument deduction/substitution failed:
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:388:56: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long int’ and ‘sf::Int64 {aka long long int}’)
In file included from /usr/include/c++/4.7/bits/char_traits.h:41:0,
                 from /usr/include/c++/4.7/string:42,
                 from /home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.hpp:34,
                 from /home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:28:
/usr/include/c++/4.7/bits/stl_algobase.h:233:5: note: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
/usr/include/c++/4.7/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
/home/vkarlsson/Skrivbord/SFML-master/src/SFML/Audio/SoundFile.cpp:388:56: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long int’ and ‘sf::Int64 {aka long long int}’)
make[2]: *** [src/SFML/Audio/CMakeFiles/sfml-audio.dir/SoundFile.cpp.o] Error 1
make[1]: *** [src/SFML/Audio/CMakeFiles/sfml-audio.dir/all] Error 2
make: *** [all] Error 2

And I'm not sure how to proceed, I though someone here might know.

Kind regards Moonkis

General / [SOLVED]Collision detection and sliding alongside walls.
« on: April 12, 2013, 10:44:12 pm »
I'v been trying to get collision detection between the tiled world and my free moving objects to work, I'v been through MANY hiccups but I finally found a way to do the collision detection right, the only problem is I don't know how to make the player slide alongside a wall if he is moving in more than one direction and the other one is collision free.

This is what I have so far...it's working on the top and bottom walls but not the right and left:
void Player::update(float dt, const Tiles& tiles)
        float x = m_x;
        float y = m_y;
        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
                y -= m_speed;
        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) )
                y += m_speed;
        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
                x -= m_speed;
        if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
                x += m_speed;
        /* Calculate the nerest tiles around the player. */
        int startY = ( m_y - 32 ) / 32;
        int startX = ( m_x - 32 ) / 32;
        int endY = ( m_y + 64 ) / 32;
        int endX = ( m_x + 64) / 32;
        for( int sy = startY; sy < endY; sy++ )
                for( int sx = startX; sx < endX; sx++ )
                        if( tiles[sx][sy] != 1 && tiles[sx][sy] != 5 )
                                sf::IntRect wall;
                                wall.top = sy * 32;
                                wall.left = sx * 32;
                                wall.width = 32;
                                wall.height = 32;
                                m_boundingbox.top = y+20;
                                m_boundingbox.left = x+8;
                                        sf::IntRect xaxis(x+8,m_y+20,16,8);
                                        sf::IntRect yaxis(m_x+8,y+20,16,8);
                                        if( !xaxis.intersects(wall) )
                                                m_x = x;
                                        else if( !yaxis.intersects(wall) )
                                                m_y = y;

        m_x = x;
        m_y = y;

I'v been trying all day and I have no idea how to achieve this.

Quick backstory:
I'm collecting useful classes inside my own library called Vildhjarta that is dependent on SFML, it's dynamic ( .dll ) and links statically towards SFML when compiled.

Inside Vildhjarta there is a class called "Graphics" that loads and returns texture files and caches them inside a map.

Problem is when using Graphics::getTexture() ( loads texture if not found in cache ) it returns a valid pointer but It doesn't display when trying to draw it.

I can however access it, getting information such as size.

Minimal Recreation
Tricky but here is the main.cpp:
#include <SFML\Graphics.hpp>
#include <Vildhjarta\Graphics.hpp>
#include <iostream>

int main(int argc, char **argv)
        sf::RenderWindow window(sf::VideoMode(600,400,32), "@Window" );
        sf::Event event;
        vh::Graphics g;
        sf::Texture* t = new sf::Texture();
        std::cout << t->getSize().x << " " << t->getSize().y << std::endl;
        delete t;
    t = g.getTexture("victorsplash.png");
        std::cout << t->getSize().x << " " << t->getSize().y << std::endl;
        sf::Sprite s;
        while( window.isOpen() )
                while( window.pollEvent(event))
        return 0;

Here is Graphic.hpp inside Vildhjarta.dll :

#include <SFML\Graphics.hpp>
//#include "ResourceCache.hpp"
#include <string>
#include <map>
namespace vh
        class Graphics
                sf::Texture* getTexture(std::string gfx);
                void removeTexture(std::string gfx);
                void loadTexture(std::string gfx);
                //vh::ResourceCache<sf::Texture> m_cache;
                std::map<std::string, sf::Texture*> m_cache;


And here is the implementation ( stripped from everything else ):
/* Includers and stuff */
sf::Texture* vh::Graphics::getTexture(std::string gfx)
        sf::Texture* texture = nullptr;
        if( m_cache.find(gfx) != m_cache.end())
                texture = m_cache[gfx];
        if( texture == nullptr )
                texture = new sf::Texture();
                if( !texture->loadFromFile(gfx) )
                        std::cout << "Graphics couldnt load file " << gfx << std::endl;
                        delete texture;
                        return nullptr;
                std::cout << "Graphics loaded file " << gfx << " correctly" << std::endl;
                m_cache[gfx] = texture;
        std::cout << "Returned texutre pointer" << std::endl;
        return m_cache[gfx];

Additional information
The above code will output 0,0 and then after calling graphics-getTexture("victorsplash.png") it will output 600,400 which is the dimension of the image that is loaded, but setting the sprite to it will still not draw it.

If I include the raw files i.e the headers and .cpp files to my project it works fine, loading and drawing.

Both the project and the library project links statically towards SFML

I have no clue on how to solve this, I'v been trying like crazy.

Audio / Sf::Music - Supported file format but file is malformed.
« on: March 18, 2013, 08:01:19 pm »
I'v googled the problem before making a new thread but I'v failed to see any solutions to my problem. I downloaded the LATEST ( as time of writing ) SFML 2.0 from Github and compiled it fresh ( static ), I'v added the x86 versions of openAL and libsnd that was inside of the SFML-master, included the include that's inside master and of course linked to the freshly compiled libs as well.

I'm still getting the error though and I really don't know what to do. I'm on Windows 7 ( 64 bit ).

I'm sorry if this has been asked a couple hundred of times!

Kind regards,

#include <SFML\Audio.hpp>
int main(int argc, char **argv)
        sf::Music m;
        return 0;

General / Statically Linking SFML and Executable Size Reduction
« on: March 06, 2013, 02:25:31 pm »
I know most people don't really bother with this, but I have a relatively small project ( A graphical console ) which I'm trying to reduce the size of.

So far I'v been searching and trying out link-flags and compiler-flags like a mad man, but at it's smallest I'v been able to reduce it to 1,4 mb ( 1'430 KB ) which I still think is large.

I came across this: http://stackoverflow.com/questions/12449387/bloated-exe-sizes-and-unwanted-dependencies-with-qt-mingw

But even when re-compiling SFML with this ( and -s ) the size is still very large, I only noticed a very ( VERY small ) difference in size.

Is there any other way to NOT include code that isn't going to be used or am I doing something wrong, and/or reduce the size of an SFML executable ( other than UPX )?

I'm compiling with MinGW ( g++ ) and Code::Blocks.

I'm really fascinated on how to reduce executable size.

Kind regards Moonkis.

General / Failing to link SFML 2.0 with CodeLite
« on: March 05, 2013, 09:56:24 pm »
I'v been trying to get this to work but I can't figure out what is wrong.

Linker Output:

Source Code:
#include <iostream>
#include <SFML\Graphics.hpp>

int main( int argc, char** argv )
        sf::RenderWindow window;
        window.create(sf::VideoMode(800,600,32), "SFML WINDOW");
        sf::Event event;
        return 0;

Compiler Settings:

Linker Settings:

Linker Libraries:

Anyone know what I'm doing wrong?

General / Code::Blocks 12.11 and SFML 2.0
« on: February 15, 2013, 11:21:44 am »
After my Windows fucked up quite a bit I decided to format my computer, this time around I'm going with Code::Blocks 12.11 instead of Visual Studio 11 because of all the "Windows"-specific keywords and none standard C++ keywords, also because VS 11 comes with a ton of software I'll o´most likely never use.

So after a bit of struggling getting Code::Blocks, CMake'ing SFML 2.0 from Github and linking/including I'v ran into this ... thing.

Maybe I'm a bit spoiled by how Visual Studio treats me, but Code::Blocks doesn't show me any suggestions when trying to do:
#include <SFML/Graphics.hpp>

It does for the standard libraries such as "iostream". Is their anyway of getting this behavior? It's a minor thing but very convenient.

General / 3 Questions I have.
« on: February 03, 2013, 10:24:37 am »
I know the title is rather unspecific but It's hard when your questions are not related to each other, instead of creating 3 topics I'd rather gather them here.

Dragging GUI Console Window

I'v been going at this for a while and I haven't been able to receive the effect I wanted. Inside my game I have this Console that is basically a square picture. Now I want to be able to drag that image across the screen using the top as a draggable zone ( you know like how a normal window works ).

Problem with this is that the only solution I have come across SNAPS the window top left corner to the mouse location. I'v been trying to calculate an offset for where the place the dragged window when I'm moving my mouse but it results in the window not being draggabele at all.

I'm checking if the mouse left button is down-

Transparent SFML Window
Is there a way to achieve this? Like those patches where they have an irregular shaped image that is not a square and they keep the rest of the rendering window totally transparent so you can only see the irregular image. Kinda of like Perfect Worlds patcher window.

Handling resources
This one might be a bit longer but maybe you can point me in an direction? I wounder how to efficiently store my audio, graphics ect within the game so that all that needs have access to it. Right now I'm going with a singleton, but my main problem here is I don't know how I should write the code that determines wheither an graphical resources should be unloaded or keept in memory, like for example if you switch between "States/Screens" I want to keep the resources that are loaded the most so that I don't do unload the imidiatly load them again.

I know this was kinda a mouth full but you know, I'v always wondered.

General / 2D First Person Dungeon Crawler
« on: November 26, 2012, 01:00:49 am »
I'm inspired to make a 2D FPV Dungeon Crawler like Arcana, Eye of the Beholder.
You know when you see a psuedo 3D dungeon in a first person perspective like this:

Now, I'm note sure that SNES supported 3D so I suppose it was all done in 2D, I know that all tiles are drawn to look 3D when pieced together.

It's just that I have no idea on how to code this, at all, not even the simplest clue. I have done 2D top-down and side-scrolling but not a 3D-looking 2D dungeon with "depth". I know this can be achieved through 3D-programming with z-depth and all that fancy stuff, but I'd REALLY just like to do it in 2D, the classical way.

I figured some of you old foxes might know how to code this, and might nudge me in or explain it. I'v tried googling it but I came up with 0 topics around first person view in 2D.

The harders part I can imagine is scaling and positioning the walls, floors and ceilings that's further away so it looks like a complete hallway that you can see a defined amount of "cells" into.

Items, Monsters and other stuff is just plain scaling and not much piecing together with the other tiles so it shouldn't be hard to do.

So how do you do a 2D first person view for a Dungeon Crawler using strictly 2D?

General / Raspberry Pi
« on: October 24, 2012, 08:16:08 pm »
I'm really thinking of buying a Raspberry Pi ( Mini Linux Computer ).
I know really nothing about Raspberry Pi ( I'm actually discovering it right now ) but it seems awesome as a toying computer!

I was thinking of running Raspbian ( Debian optimized for Raspberry Pi ). I'm completely new to Linux in general but I was thinking it was a good way to start with it.

I'd like to write graphical applications using C++ and I was wondering if I could use SFML 2.0 on the Rasberry Pi?

Kind regards,

Pages: [1] 2