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

Pages: 1 [2]
16
SFML projects / My Practice Beginner Games
« on: August 23, 2015, 08:47:23 pm »
Foreword
I realised that I have avoided programming those beginner games that everyone does to learn stuff and for general practice so I decided that I'm going to finally attempt them.

This project (of multiple games) doubles as practice for using GitHub too so it will all be available on GitHub. The repositories are the actual files that I am working on so you so you will be able to see my workings, mistakes, and re-factoring (I tend to do that a lot, I think). This also means that you can feel free to raise issues on the repository and the like.

Of course, SFML will be the base library for all games. Who actually wants to write console-only games?  :P
I also will be using a few small libraries of my own - all of which are completely available on GitHub.

I'll be up for discussions on any part of the project - including suggestions - but not really questions about C++ that should be, at the very least, first googled.

Games
Complete:
Current Work In Progress:

Early video of MTD (v0.0.2):
http://youtu.be/K5IZUl_7BaY

Video of Puzza (v1.0.0):
http://youtu.be/Hp1IyuBLyRE

(click to show/hide)

The Code
Click here to visit the GitHub repository.

Disclaimer
These "games" are work(s) in progress and no guarantees to their working success are given.
I may or may not decide to work on more than one game at a time.
None of this can be considered tutoring. It is not intended to teach. I am learning and this is what I am doing. That is all.

17
SFML wiki / Sprite3d
« on: July 30, 2015, 05:03:11 pm »
NOTE: Sprite 3D is now included (and maintained) as a part of Selba Ward.

Sprite3d

Sprite3d could be considered a follow-up to the sprite animation temporary class, SpinningCard, which allows you to rotate a sprite around either the x axis or the y axis. It does this by animated the corners in an ellipse.
However, where SpinningCard was only intended to used during the spinning animation and then discarded, Sprite3d is intended to be used on its own.

Sprite3d does not animate corners using an ellipse; it uses a "proper" transformation matrix (albeit a rather compact one) to rotate around the x and y axes. This combined with the usual rotation around the z axis (this class inherits from sf::Transformable) and you can rotate around all three axes.

Sprite3d injects itself into the same namespace as SFML to allow for an easy and seamless transition from sf::Sprite to sf::Sprite3d.
Sprite3d is intended to be able to used in place of a standard SFML sprite with no changes to the code.

The source is, of course, available on my GitHub and is also available on its Wiki page.

Here's an early test screenshot (it really does not do it justice!):


The screenshot doesn't properly show what it does so here is a video of an early test example:
http://youtu.be/EAPDIlVEMKA

One thing to note is that this class doesn't solve the texture mapping problem evident in SpinningCard (and is evident in that screenshot - look at the lines). It does attempt to reduce the effects by a user-controlled number of triangles. The quality of this effect is therefore dependant on both mesh size and apparent depth.

If you want to see the mesh fixing the texture distortion, run the current example and start the rotation (press Space). Increase the Mesh Density to 4 (use the square brackets [ ] to adjust) and turn on dynamic subdivision (Return). Then increase the depth to 50 (use - and = to adjust). The example displays how many triangles are being used at any point in time.
For more controls, see the comments at the head of the example code.

To combat the texture distortion evident when a non-affine transformation (three dimensional rotation is a non-affine transformation as the edges stop being parallel) is applied to a quad, there are three features in Sprite3d that alter the mesh (size and number of triangles).
  • Mesh Density
    This is how many points are used per dimension, not including the edges. For example, if the mesh is created from 5x5 points, that's 5 points per dimension - 3 points per dimension, not including the edges. So, a mesh density of 3 would give you a mesh created from 5x5 points (a single quad is 2x2 points; 5x5 points creates 4x4 quads)
  • Subdivision level
    This is very similar to Mesh Density. It changes how many points are used for the mesh. Each subdivision divides each quad in the mesh into four quads. e.g.: 1 quad that is subdivided once becomes 4 quads, 1 quad that is subdivided twice becomes 16 quads, etc.
  • Dynamic Subdivision
    When enabled, Dynamic Subdivision changes the subdivision level automatically based on the most extreme angle. That is, the greatest rotation angle of pitch and yaw (around the x and y axes respectively). The range of subdivision can be specified; the default range is 1 to 4.
    Example: Using the default range, if pitch and yaw are both 0 (object is flat), the subdivision level would be 1, whereas if pitch or yaw is close to 90°, the subdivision level would be 3. Subdivision level 2 would be used if the most extreme angle was not almost 90° but was not almost flat.
    The range is interpolated linearly so (in the case of the default range) from 0° up to 30° the subdivision level would be 1, from 30° up to 60° degrees it would be 2, from 60° up to 90° it would be 3, and at 90° it would be 4.

I invite people to try Sprite3d in place of any standard sprite you already have to see if the replacement is seemless or needs some work. I would appreciate any feedback on this (or any) matter.

GitHub repository for Sprite3d.

EDIT: updated to reflect complete version (1.0.0)

If anyone knows if it's possible to use a shader to fix the texture distortion, please let me know how.

18
SFML wiki / RadialGradient Shader
« on: July 28, 2015, 06:18:05 pm »
Just posted a shader on the Wiki to add radial gradients to untextured SFML graphics objects e.g. rectangles, circles, vertex arrays.

There is also a complete example that - using an sf::CircleShape and an sf::Rectangle - ends up displaying this:


Here's the Wiki page:
RadialGradient Shader

EDIT: changed image width to fit into the forum.

19
Window / Error Message On Incorrect ContextSettings
« on: June 28, 2015, 08:30:16 pm »
Setting one of the context settings' attributes to one that will fail causes an error message to be displayed. I don't think it's always been like this; to quote the documentation for sf::ContextSettings:
Quote
No failure will be reported if one or more of these values are not supported by the system; instead, SFML will try to find the closest valid match.
which obviously isn't true anymore.

Is there, at least, a way to suppress this error message? Preferably, at least for release mode.

Here's some short code that now causes the error message to be shown:
#include <SFML/Graphics.hpp>
int main()
{
        sf::ContextSettings contextSettings;
        contextSettings.antialiasingLevel = 128; // changing just one unsuccessful setting can make SFML display an error message

        sf::RenderWindow window(sf::VideoMode(800, 600), "Context Settings", sf::Style::Default, contextSettings);
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                window.clear();
                window.display();
        }
        return EXIT_SUCCESS;
}
Error message (on my computer):
Warning: The created OpenGL context does not fully meet the settings that were requested
Requested: version = 1.1 ; depth bits = 0 ; stencil bits = 0 ; AA level = 128 ; core = false ; debug = false
Created: version = 4.2 ; depth bits = 24 ; stencil bits = 8 ; AA level = 4 ; core = false ; debug = false

I intentionally overshot the anti-alias maximum value by using an impossibly high value but it works the same if you overshoot it by anything (e.g. on my computer, trying 8). Overshooting seemed to be the solution previously due to not knowing the maximum (anti-alias level) it could achieve.

Commenting out the anti-aliasing assignment stops the error message as ContextSettings having default values for all of its attributes will cause it to find a match with no error message.

This also brings up another question: is it possible to disable the stencil buffer - or depth buffer - (as mentioned in this tutorial) as it requires the stencil bits to be set to zero but this is ContextSettings' default value and finds a match (see error message above).

EDIT: Turns out that for depthBits and stencilBits, anything lower will be 'promoted' while anything higher will cause the same error message.

20
Audio / AL_INVALID_OPERATION from SFML 2.3 Audio
« on: June 25, 2015, 01:44:14 am »
The closest thing that I could find that already mentioned this error is this post but since the error I'm getting is in SFML 2.3 but not 2.2, I don't think that topic is relevant - barring the fact that it didn't seem that the problem in the thread had a solution.

The actual error I'm receiving is:
An internal OpenAL call failed in AudioDevice.cpp (157) : AL_INVALID_OPERATION, the specified operation is not allowed in the current state

#include <SFML/Audio.hpp>
int main()
{
        sf::Listener::setGlobalVolume(100.f);
        return EXIT_SUCCESS;
}
That code is enough for me to get the error. It doesn't get an error by instancing an sf::Sound object (like in this SFML Github issue that I visited to see if it was related) instead of using the Listener. In fact, after some extra tests while writing this, I found that of the setters in Listener, setGlobalVolume() and setPosition() causes the error but setDirection() and setUpVector() do not.

I've fully linked to 2.3 and it causes this error. I then fully linked to 2.2 and there is no error.
I then tried 2.3 with 2.2's Audio dll and the error disappears. 2.2 with 2.3's Audio dll brings it back.
Both versions of the SFML DLLs are the release versions.

Indeed, the reason I noticed this was because I linked my Faux Car project to 2.3 and it caused this error at the very beginning (when setting global volume) and then I had some weird destruction crash when main() closed. I've found the source of the crashing so they're not related as I originally considered. I addressed this first (the audio error) as it's the first error and I found it easy to reproduce with minimal code.


EDIT: This error is only appearing in debug mode, not release.
Windows 7 64-bit, VS Studio 2013, SFML 32-bit - dynamic and static both same result.
EDIT 2:
64-bit gives same result as 32-bit (debug, not release; both dynamic and static same result).

21
Window / First GainedFocus Event Fails After Recreation Of Window
« on: June 11, 2015, 10:57:17 pm »
The window doesn't seem to receive a GainedFocus event if the window is recreated after losing focus.

Here's an example:
#include <SFML/Graphics.hpp>

void createWindow(sf::RenderWindow& window)
{
        window.create(sf::VideoMode(800, 600), "Gained Focus Event Failing", sf::Style::Default);
}
int main()
{
        sf::RenderWindow window;
        createWindow(window);

        sf::Color color{ sf::Color::Green };

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed || event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                                window.close();
                        else if (event.type == sf::Event::LostFocus)
                        {
                                createWindow(window); // this stops GainedFocus from working
                                color = sf::Color::Red;
                        }
                        else if (event.type == sf::Event::GainedFocus)
                        {
                                //createWindow(window); // this is fine if commented out or not
                                color = sf::Color::Green;
                        }
                }

                window.clear(color);
                window.display();
        }

        return EXIT_SUCCESS;
}

The code changes the window to red when it's not in focus and green when it is in focus.

When the window is recreated after losing focus, when returning focus to the window, it doesn't receive the GainedFocus event and therefore no longer turns green.

In the code, if you comment out the createWindow line (before turning color to red), the event works fine. In addition, if you uncomment the createWindow line (before turning color to green), it makes no difference (lost focus still works immediately). In fact, even after regaining focus but not receiving the GainedFocus event, the window will still receive LostFocus events.

It's obvious that event is still for the correct window as you can still close the window that can't regain focus.


EDIT: Win7, VS2013, SFML2.3 debug and release (32-bit).



EDIT 2: modified thread subject title.

22
SFML wiki / Zooming a view at a specified pixel
« on: January 27, 2015, 11:13:02 pm »
Hi.

A thread appeared on the forum that asked about zooming a view at the mouse's position when the mouse wheel was scrolled so I created a simple free function that zooms a view at any specified pixel (in relation to the window).

Here's the wiki page:
https://github.com/SFML/SFML/wiki/Source:-Zoom-View-At-%28specified-pixel%29

It includes an example that scrolls on mouse wheel usage as stated above.

I hope you find some use of it.

Hapax

p.s. It's also my first SFML wiki page so I hope it follows all of the rules.

23
SFML projects / Faux Car
« on: December 02, 2014, 09:45:16 pm »



Intro

It may be obvious to some that I've become interested in faux/fake/pseudo 3D. I think it shows in the Spinning Card class that I created. I began to investigate more pseudo 3D usage and stumbled upon the old car games that used it.

I felt the need to attempt to see if I could also make this pseudo 3D track effect - using SFML, obviously!

Faux Car is what I came up with.

I'm not sure if I'm going to turn it into a complete game yet, but I do intend to evolve it.

The altitudes and positions are calculated using perspective algorithms but all turns are fake. There are no technically no rotations. Bends are simply accumulations of offsets.

I'm willing to discuss the code and show parts of it too. It's a little impractical to show it all; it's in many files and is reliant on my own library (full version of Hx).

Version Info

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)

24
SFML projects / Spinning Card
« on: September 24, 2014, 02:16:06 am »
NOTE: you may be interested in the much more flexible follow-up to this class, called Sprite3D.
Sprite 3D is now included (and maintained) as a part of Selba Ward.



I remember someone once mentioning animating a card so that it spins around without using OpenGL. I think the answer was simply "scale the width". I had said it could be faked by animating the corners but I think they thought that might be too complicated.

It inspired me to create something that spins a card easily without using OpenGL but still looks 3D (enough).

I bring you...
Spinning Card

Here's a video of a really basic example of it in action (source code for example is on github):
http://www.youtube.com/watch?v=u428K0xyorI
The example code uses two SpinningCards - one for the front and one for the back - and switches which one to draw depending on the current angle. It animates the angle linearly from 0 to 360 degrees and animates the scale depending on the angle (to make it float forwards).
In this example, the card starts the spinning animation whenever the Space Bar is pressed. The "stuttering" is because of the key pressed quickly.

The class takes a sprite and mimics it by creating a vertex array and taking the sprite's position, origin, scale, rotation, colour, and its texture, which it takes a pointer to.

The card, by the way, can also be spun vertically.

If you can think of something that this class is missing, let me know. It's a simple class with a specific task in mind, though, so it probably shouldn't start including an ability to bend the card or anything  :P

As always, feel free to let me know if my code could be improved and how.  ;)

25
SFML website / Misleading Forum Link
« on: September 17, 2014, 12:37:48 am »
There is a link at the very bottom of the forum page that links to a site called Create a Forum. This link's name/title, however, is displayed as "Simple Audio Video Embedder".
Surely this could just say "Create a Forum" or something.

26
SFML projects / Objex
« on: August 06, 2014, 08:12:42 pm »
Updated to v0.2.0

I decided that I was going to have a look into OpenGL and looked at the SFML example and tweaked it to get a feel of how it works.
Then, I realised that I would want to be loading those objects from a file rather than storing them in the source code and considered saving them out and reloading them.
I then realised that I could just attempt to import existing formats of 3D objects and found .OBJ to be the easiest to get documentation for, and is so widely used, so I got side-tracked and created a class to help.

This class loads .OBJ files and converts them into vertex array of GLfloats, ready to pass to OpenGL.

It imports geometry vertices, texture vertices, and normal vertices but only geometry has been tested. This is because I am new to OpenGL and have yet to figure out lighting and texturing. Because of this, it creates a colour array of GLfloats (ready to pass to OpenGL) where each triangle is a random colour.

Feel free to use it in tests and things. As I mentioned earlier, I only really made it to make my 3D investigations a bit more interesting, and I didn't see the point in using an existing library for it when I could create it myself and learn in the process.

I would not consider it "complete" but it does the job of importing objects fine (for me). I was going to continue with importing textures etc. but I can't test if it's doing what it's supposed to be doing :P

I added the ability to manipulate the object too, so it now stores it twice - once in (sort of) .obj format, and once in GL format. You use the class to manipulate the obj version, then refresh the gl version from the obj version. This requires complete recreation of the GL version so it's quite slow for complicated objects.

Feel free to comment on my code. I'm no expert at C++ or SFML, nor especially OpenGL, so any tips would be appreciated. It's not designed to catch all errors in usage so it should be used properly. I will probably add more user-error security later.

Objex on GitHub

Here's a video of a test using a cow model from the internet:
http://www.youtube.com/watch?v=PwQJTy7zZ-w

27
SFML projects / PXL8
« on: July 19, 2014, 12:08:10 am »
PXL8 - a pixelated render target.

I wanted a simple and generic way to pixelate SFML output so I created PXL8.

You're welcome to use it as much as you like - in projects, studying - and feel free to suggest better ways of writing the code, features that it should have, or any bugs that I have missed.

You can use views with it and draw to it like a normal render target. It supplies you with its pixelated render as a standard sprite, ready to draw to your window as normal.

You can specify the size of the pixel - it does so in each frame in the example provided - by both dimensions (width and height) separately, if you desire.

I'd show you an image with a screenshot but I think you all know what pixelation looks like  ;)

Let me know what you think and I'd like to see projects that are making some use of this :)
I'm providing only source code - no builds - so you will need to compile it yourself, either within your projects or separately. If you do use it, I'd love some credit but you're not required to do so  ;D

Here is the PXL8 GitHub repository.

28
Audio / [SOLVED] Problems with .setPitch
« on: July 01, 2014, 05:01:41 am »
This has been solved for my own errors although unsure of whether openal would cause anything else related.

Here's some code to test pitches (mine now works for all of these!):
#include <SFML/Audio.hpp>
#include <iostream>

int main()
{
        sf::SoundBuffer soundBuffer;
        if (!soundBuffer.loadFromFile("piano_a3.wav"))
                return -1;
        sf::Sound sound;
        sound.setBuffer(soundBuffer);
        for (float i{ 10 }; i <= 100; ++i)
        {
                std::cout << i << std::endl;
                sound.setPitch(i);
                sound.play();
                while (sound.getStatus() == sf::Sound::Playing) { }
        }
        return 0;
}


Here's the original post:
(click to show/hide)

29
SFML projects / Squeak
« on: February 18, 2014, 03:10:52 am »
Current version: 1.0.3 (download for Windows)

Updates
1.0.3:
. Added ability to refresh the positions of the contextual display and tool-tip after altering the text within them.
. Added ability to remove the cursor and just use the toop-tip and contextual display, which allows you to use them with the hardware cursor.

About
Squeak is a simple and small add-on that easily allows you to change the mouse cursor while it's inside your window.

I created this while working on something else and decided that it would be useful to have it always accessible for future projects. I then realised that other people could benefit from a tiny bit of saved time too. It also gave me the opportunity to learn how to build a DLL, which is not something that is fun.

Squeak also has a built-in tool-tip and contextual display, both of which are automatically resized based on their text content. They are customisable too: colours, padding, outline, tool-tip timers etc.. They can both be activated and deactivated individually. They also both reposition to stay within the window's border. The contextual display can be displayed above or below the cursor whereas the tool-tip is always display on top (layer-wise, not position - positions can be adjusted).

It can be run and used with minimal code. Only two lines are required inside the main loop: update and draw. It automatically updates itself from window events.

You can decide to allow the cursor image to scale with the display as it stretches or restrain it to keep a persistent size. You can also use Squeak to "get" the current mouse position; it can return either coords or pixels.

Here is a video of it in action:
http://www.youtube.com/watch?v=VVF7ZtLBlg8

Unfortunately, you can't really see the green, custom mouse cursor as the video capturing software that I used ignores the "remove mouse cursor" command and places it right back on top :( So, here's a screen shot:


Download
Anyway, I hope some people find some use of it. The download is a .zip file that contains the .h file, the .lib file, the .dll file, a readme, and a couple of simple examples (the examples were used for the screenshot and video).
You can download it from MediaFire. It's provided under the zlib licence.

Feedback
If you you have any suggestions or find any bugs, feel free to leave them in a comment on this thread.

Pages: 1 [2]
anything