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 - zmertens

Pages: [1]
Feature requests / Simple method for Centering Window Position
« on: July 29, 2015, 07:01:56 am »
I think it might be beneficial for the SFML library to have a quick method for setting the window in the user's screen center. I'm sure this has been thought of before by SFML devs, however, I don't see any discussion in the forums that I could find. Here's a quick and simple look at how I think it might be implemented in the Window class.

For instance, at line 220 in SFML/src/SFML/Window.cpp:
void Window::setPosition(const Vector2i& position)
    if (m_impl)

could be called using something like:

window.setPosition(sf::Vector2i(sf::Window::CenterHorizontal(), sf::Window::CenterVertical()));

Where sf::Window::CenterHorizontal/Vertical are static public methods that calculate the equivalent call:

window.setPosition(sf::Vector2i(sf::VideoMode::getDesktopMode().width * 0.5 - window.getSize().x * 0.5, sf::VideoMode::getDesktopMode().height * 0.5 - window.getSize().y * 0.5));

I'm sure there'd be better ways to implement this functionality within SFML's API but this was a quick way to illustrate what I was referring by setting the window to the user's screen center. I realize it's not very much code to replace but I think it does reduce some clutter in the call. Part of the inspiration was from SDL's library with regards to:
SDL_CreateWindow(titleString.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, SDL_WINDOW_OPENGL);

General discussions / SFML 3D logo
« on: July 26, 2015, 01:12:44 am »
I worked on a very basic 3D logo (using Blender) for a project and I came up this:

I attached the .blend file below and you're free to use it for anything if you fancy. I was going to use it as a splash screen (and give it some rotation). You'll need to use OpenGL and will have to parse the .blend file, or you can export it to wavefront object and that's pretty easy to parse.

SFML projects / Testing out real-time (GLSL) raytracing
« on: July 03, 2015, 09:38:05 pm »
I've been playing around with making a real-time raytracer using OpenGL (and SFML for window management). I got a pretty simple scene down but the camera is broken. Here's a very brief video:


I'm using the same camera system I use for my OpenGL projects, but I think there's an issue with the coordinate system. The camera rotation isn't working but the movement appears to work decently (at least forward and backward). I think that I need to transform the vertices of the objects into view space using the ModelViewProjection matrix which is what I normally would do using OpenGL:

layout(location = 0) in vec3 VerticePosition;

uniform mat4 uMVP;

void main()
    gl_Position = uMVP * vec4(VerticePosition, 1.0);

However, I'm not sure how to emulate this with the purely GLSL raytracer raytracer. I found an example on GitHub which I'm working on reverse-engineering for educational purposes.

I have my code on GitHub if anyone's interested in checking it out. I used the C++ raytracer in the same repo as a guideline. The GLSL version is not optimal but more focused on getting the job done for testing purposes. I'm interested with the idea of learning compute shaders and maybe making raytraced Pong or something which could be cool.

I'm interested in any comments or critisicms of course!

Feature requests / Shader Subroutines
« on: May 31, 2015, 12:40:05 am »
On my SFML fork I tried to implement subroutine functionality. This feature would allow the sf::Shader class to modify subroutines in a similar fashion to modifying parameters or uniforms in Vertex, Fragment, or Geometry shader files. I think this could be beneficial to a SFML user as it can reduce the number of shader files that the they need to manage. Currently, the user could use uniform variables and the "setParameter(...)" overloads but that could become cumbersome with many different branches of execution. I believe they would need to constantly set every uniform false or true due to the previous iteration of execution maintaining the respective uniform's value. The specific subroutine is specified using a Shader class object:

myShader.setSubroutine("subroutineName", sf::Shader::Type, 1);

The last parameter is the index of the subroutine array according to OpenGL documentation. I created a brief example below to display the functionality below and I only tested an array length of 1.

In this example, a single vertex file is used with a subroutine that can modify the text graphics using the "wave" or "storm" vertex shaders taken from the SFML examples.

#include <iostream>
#include <SFML/Graphics.hpp>
#include <cmath>

using namespace sf;

int main(void)
    RenderWindow window (VideoMode(800, 600), "My SFML Window", sf::Style::Default);
    window.setPosition(sf::Vector2i(0, 0));

    Shader shader;
        return EXIT_FAILURE;
    if(!shader.loadFromFile("vertex.glsl", Shader::Vertex))
        return EXIT_FAILURE;

    Font ubuntuFont;
        return EXIT_FAILURE;

    Text textToShow ("SFML Rocks!", ubuntuFont, 100);
    textToShow.setPosition(0, 600 / 2 - 100);

    Clock clock;

    bool waveEffect = true;

    while(window.isOpen()) {
        float elapsedTime = clock.getElapsedTime().asSeconds();

        sf::Event event;
        while(window.pollEvent(event)) {
            if(event.type == event.Closed) {
            else if(event.type == Event::KeyPressed && event.key.code == Keyboard::Escape) {
            else if(event.type == Event::KeyPressed && event.key.code == Keyboard::Num1) {
                shader.setSubroutine("wave", Shader::Vertex, 1);
                waveEffect = true;
            else if(event.type == Event::KeyPressed && event.key.code == Keyboard::Num2) {
                shader.setSubroutine("storm", Shader::Vertex, 1);
                waveEffect = false;

        // update shaders
        if(waveEffect) {
            shader.setParameter("wave_phase", elapsedTime);
            shader.setParameter("wave_amplitude", 40 * 0.3f, 40 * 0.002f);
        else {
            float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
            float y = static_cast<float>(sf::Mouse::getPosition(window).y) / window.getSize().y;
            float radius = 200 + std::cos(elapsedTime) * 150;
            shader.setParameter("storm_position", x * 800, y * 600);
            shader.setParameter("storm_inner_radius", radius / 3);
            shader.setParameter("storm_total_radius", radius);

        // render

        RenderStates states;
        states.shader = &shader;
        window.draw(textToShow, states);



    return EXIT_SUCCESS;

... And here is the corresponding vertex shader file.

// wave and storm effects from SFML examples

subroutine vec4 VertexModType();
subroutine uniform VertexModType GetModifiedVertex;

// uniforms for wave shader
uniform float wave_phase;
uniform vec2 wave_amplitude;

// uniforms for storm shader
uniform vec2 storm_position;
uniform float storm_total_radius;
uniform float storm_inner_radius;

vec4 wave()
    vec4 vertex = gl_Vertex;
    vertex.x += cos(gl_Vertex.y * 0.02 + wave_phase * 3.8) * wave_amplitude.x
              + sin(gl_Vertex.y * 0.02 + wave_phase * 6.3) * wave_amplitude.x * 0.3;
    vertex.y += sin(gl_Vertex.x * 0.02 + wave_phase * 2.4) * wave_amplitude.y
              + cos(gl_Vertex.x * 0.02 + wave_phase * 5.2) * wave_amplitude.y * 0.3;
    return gl_ModelViewProjectionMatrix * vertex;

vec4 storm()
    vec4 vertex = gl_ModelViewMatrix * gl_Vertex;
    vec2 offset = vertex.xy - storm_position;
    float len = length(offset);
    if (len < storm_total_radius)
        float push_distance = storm_inner_radius + len / storm_total_radius * (storm_total_radius - storm_inner_radius);
        vertex.xy = storm_position + normalize(offset) * push_distance;

    return gl_ProjectionMatrix * vertex;

void main()
        gl_Position = GetModifiedVertex();
        gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
        gl_FrontColor = gl_Color;

I know there might be some underlying issues with my implementation. For starters, subroutines require OpenGL 4.0 Core context and I think SFML only supports 3.0 I think. This is my first time modifying the SFML library directly, so I think I may have butchered some of the conventions (sorry!). I mainly did this to see what kind of feedback I could get as I've been looking for ways to contribute to this library and I noticed there's been some disuccsion on this topic. I did talk with Mario on IRC very briefly but I don't think he understood what I was referring to and then I went to sleep.  ::)

edit: added clarification as to why the feature may be useful

General discussions / distributing SFML projects on Linux (binaries)
« on: February 07, 2015, 06:43:03 am »
I just started really using Linux (Ubuntu) a couple months ago and I was wondering how you guys distribute a binary on Linux (so excluding CMake or source files which I realize is the preferred Linux way). The context for this situation is if I just wanted somebody to be able to play my game right away (like on itch.io). Could I just have the SFML .so files adjacent to the binary similar to .dlls on Windows? I looked at static linking but I saw some posts on Stack Overflow which suggested this might be a bad thing to do.

Anyone comments or tips would be awesome.

Feature requests / Object Loader (similar to AssImp)
« on: February 06, 2015, 09:43:58 pm »
Any chance SFML could add an in-house object loader for common files types (.obj, .tga, ...) similar to ASSIMP? It could be very useful just to get the vertices, indices, normals, and so forth for 3D projects. I'm not too familiar with all the file types, but I know .obj files are pretty straight forward to parse.

SFML projects / Escape From Fog - 3D fps
« on: December 07, 2014, 06:58:58 am »

Escape From Fog

I am working on a first person shooter similar to Wolfenstein 3D, but will have additional features and a kind of surrealistic themed gameplay. The objective of the game is to shoot the point-sprites (they're supposed to be minotaurs) and not die. The music and sound effects are pretty hashed together as well as the sprites. I'm focusing mostly on the programming right now and not so much the artwork. Much of the features are adapted from tutorials that I've found regarding OpenGL tutorials which gives the project a sort of a Frankenstein structure to it. I'm using SFML 2.3 (naturally), OpenGL 4.3, AssImp, and FreeType libraries.

Use left mouse button to shoot the bullets. Each level ends when the player hits the exit signs and then another level is automatically loaded. They're only three levels right now and when you get to the third level it resets back to the first level.

The video below shows a full walk-through of the three levels, combat, animations, sound effects, and some other aspects of the game.


Image Album


TODO List (in no particular order)
  • More descriptive HUD
  • Better level design including a skybox style level.
  • Better soundtrack and sound effects (3D spatialization)
  • Add networking capabilities so multiple players can join
  • Add joystick support

  • The bullets run out at the moment for some strange reason. I need to come up with a better method of instancing

SFML projects / Word puzzle game of sorts
« on: August 01, 2014, 02:47:16 am »
This gif basically sums it up http://i.imgur.com/UF3Q4R4.gif

The words are loaded (along with a hint) from an external file. Then one is chosen at random, sorted (alphabetically), and then you get to swap the letters back into place (point and click and then SFML will find the letter that contains mouse coords). White letters are in the wrong place, green are in the correct place. I also used the "wave-blur" shader from the SFML SDK to give the neat wave effect on the hint words.

The purpose of this project was basically to toy around with some of the basic classes in SFML and see if I could make something simple. I was also partially inspired by Vittreo Romeo's "Arkanoid in ~160 lines, " and I wanted to see if I could make something small and compact like that (although this project came out to be about ~300 lines).

One thing I thought about adding was a better predicate to sort / scramble the words, but I wasn't too focused on changing that at the time.

Anyway, I'm let me know if you have any questions or comments. I'm interested to see if anyone tries it out and likes it.  :D

General discussions / Making a game for an emulator
« on: June 10, 2014, 07:13:14 am »
This is more of an emulator question than an SFML question but I think someone might have an answer here anyway. I was looking at the Snes9x Emulator, and I was wondering if it would be possible to make a game using a library like SFML and then somehow run the game in Snes9x emulator. In other words, make an executable that the emulator could run using the SNES specifications. I know this sounds a little pointless but I wasn't sure if its been tried or done before. Furthermore, could one make there very own hardcopy ROM and run it on a real SNES given that the hardware specifications that are in the Snes9x emulator?

SFML projects / Checkers ( work in progress )
« on: April 26, 2014, 11:36:42 am »
Hello all, I've been lurking here a couple months, and I wanted to share my Checkers project I've been working on which uses the SFML library.

I'm still learning the ropes of C++ and SFML. This project was originally from a school assignment and I have expanded upon it by adding the GUI and some other features.

New link!: https://github.com/zmertens/Checkers/releases


P.S.: I used Visual Studio 2012 Professional as my IDE. I notice that the project runs ultra slow in Debug mode, but if I run it without debugging it runs fine. Is that normal?

Window / Resizing Window, but contens don't update
« on: December 25, 2013, 07:37:56 am »
Hello, I just started using SFML not too long ago and I decided to try to make a checker game project. I'm also new to C++ as well (figured I should mention that as a disclaimer...).

This post is about an issue I have with resizing the window and the checkerboard not updating. The attatched screenshot ("Window_Resize_Test_1.png") shows how the checkerboard doesn't scale with the size of the window, but the checkerpieces do! In my code, I use a main game loop that does the event handling and a window.clear(), "draw stuff", and then window.display() cycle like in the tutorials. The checkerboard in the screenshot is made using the Shape class.

void Checkerboard :: drawGrid(sf::RenderWindow& window, int mouseOverX, int mouseOverY)
        int xOffset = 0, yOffset = 0;

        for(int i = 0; i < SQUARES_VERTICAL; ++i)
                for(int j = 0; j < SQUARES_HORIZONTAL; ++j)
                        if((j % 2 == 0 && i % 2 == 0) || (j % 2 != 0 && i % 2 != 0)) // find the white squares

                        squareArray[i][j]->setPosition(xOffset, yOffset); // set the position for drawing
                        squareArray[i][j]->setSize(sf::Vector2f(window.getSize().x / SQUARES_HORIZONTAL, window.getSize().y / SQUARES_VERTICAL));

                        xOffset += window.getSize().x / SQUARES_HORIZONTAL;

                yOffset += window.getSize().y / SQUARES_VERTICAL;
                xOffset = 0;

It was my hope that passing the window reference in the draw cycle of the main game loop would keep the checkerboard size updated. What really confuses me is that the checkerpieces scale perfectly with the window, so I think I'm just overlooking something altogether (I can post the checkerpiece draw function but its functionally the same as drawGrid). I Googled the issue and saw this guy had a similiar issue http://chrisheydrick.com/2013/06/04/problems-re-sizing-sfml-renderwindow/. Needless to say I tried it and it didn't work out. Lastly, I should mention that I can initialize the window to any reasonable size when the RenderWindow object is constructed in the main function and the checkerboard looks fine. The issue is only when I resize the window.

Pages: [1]