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.


Messages - kojack

Pages: 1 ... 17 18 [19] 20 21 22
271
Graphics / Re: SFML can not open window.hpp
« on: May 20, 2021, 10:24:52 pm »
You are missing the .. on the window.hpp include line.
..\ means go back one directory. Just a \ at the start means go to the root directory of the hard drive, which is a very different location.

272
Graphics / Re: Overriding sf::Drawable::draw
« on: May 16, 2021, 02:08:06 pm »
To override the draw function in an inherited class, you need to exactly match the function's signature.
The Drawable class has:
draw(RenderTarget& target, RenderStates states)
But yours is
draw(sf::RenderWindow& window, sf::RenderStates states)
(The sf namespace bit is fine)
A RenderTarget can refer to a RenderWindow or a RenderTexture.

273
Graphics / Re: Invisible vertical padding on text
« on: May 16, 2021, 01:18:45 pm »
    std::cout << "gb_box.left = " << text.getGlobalBounds().left << std::endl;
    std::cout << "gb_box.top = " << text.getGlobalBounds().left << std::endl;
    std::cout << "lb_box.left = " << text.getLocalBounds().left << std::endl;
    std::cout << "lb_box.top = " << text.getLocalBounds().top << std::endl;
The second line is printing the global bounds left again as the top value.

274
The Y part looks right, it's checking if the test point is below the top of the entity and above the bottom (so within the vertical range of the entity).
The X part is only checking if the test point is to the left of the entity.

Changing the X code to match the Y code should fix it.
if (Position.y > Entity->GetPosition().y && Position.y < Entity->GetPosition().y + Entity->GetSize().y) {
            if (Position.x > Entity->GetPosition().x && Position.x < Entity->GetPosition().x + Entity->GetSize().x) {
                return true;
            }
        }
The bottom return true should probably be return false though, since it fell through there because no entity overlapped the test point.

275
Ok, I was slightly wrong there. SFML does allow you to query how many buttons are really on a joystick, but clamps the value to 32 max. But there's no way to query how many axes or POVs there are.

Another issue, it sets up the Direct Input format for 4 groups of analog values, each having 6 axes and 2 sliders (so 4*(6+2)=32 total). Plus there's 4 POVs. But then says there's only 8 axes possible, and returns a single POV as the 7th and 8th axes, which should be the first 2 sliders.

An example of a common device that would break this limit if fully supported: Playstation controller. A DualShock4 controller has 16 analog axes:
- left thumb x
- left thumb y
- right thumb x
- right thumb y
- left trigger
- right trigger
- touchpad finger 1 x
- touchpad finger 1 y
- touchpad finger 2 x
- touchpad finger 2 y
- IMU gyro pitch
- IMU gyro yaw
- IMU gyro roll
- IMU acceleration x
- IMU acceleration y
- IMU acceleration z

Of course DirectInput only shows the first 6, but the rest are there if you go down to the HID level like I do. :)

Anyway, you got your issue working, I'll stop ranting now. :)

276
Yay.

I guess the issue with the change is that other platforms might not support it (I don't know, I only do windows dev). It's only in the windows specific implementation that the higher number is used, maybe linux/mac/android/etc wouldn't like it.

Ideally, SFML wouldn't use one set of constants for all joystick devices, but query the devices for exact numbers.

Soon I should receive a Wooting Two Lekker Edition keyboard. It has over 100 analog axes (every key is analog). So even 32 axes can be a little limiting. :)

I haven't checked on the first poll issue. It might depend on the device as to whether it sends initial state of everything on startup or only changes. That's one thing that really annoys me with MIDI programming. There's no way in MIDI to ask a device something like "what is the value of this slider?". Instead you have to wait for the slider to move, then you get an event saying the new value. So you can't get initial state of all controls.

277
Support for 128 buttons came out in 1997 in DirectInput 5.
But we still have games like Elite Dangerous that refuse to support it.
(It's a pet hate of mine, I've got Virpil hardware with more than 32 buttons and have to use software like Joystick Gremlin and vJoy to redirect my throttle through multiple virtual 32 button devices)

Looking at the SFML joystick code, it seems at least for Windows they may have forgotten to update the counts. Currently it's set to 8 axes and 32 buttons (and 4 POVs, but they don't get a count constant).
But the setup code is using a custom format structure with 32 axes, 32 buttons and 4 POVs.
But then the setup code says the number of objects in that struct is 32 axes, 128 buttons and 4 POVs (with 96 buttons undefined) by saying the format was the same size as DIJOYSTATE2 afterall.

So by the look of it (haven't tested) changing ButtonCount to 128 and AxisCount to 32 in joystick.hpp (and recompiling SFML) should be enough. The joystick setup code is ignoring AxisCount and is hard coded to 32 anyway (just won't let you look at them due to AxisCount), while it does use ButtonCount to set up the buttons.

On a side note, since nothing dynamic is being done there (like allocating exactly the number of axes/buttons on the device by enumerating all controls), the 80+ lines of format setup could be replaced with:
result = m_device->SetDataFormat(&c_dfDIJoystick2);
(c_dfDIJoystick2 is the already set up by DirectInput 32 axis, 128 button, 4 POV format)
Unless I missed something it's doing in there.

I might test it later if I get time.

278
System / Re: sf::Thread error
« on: May 04, 2021, 04:38:16 pm »
It seems to dislike the type of mouse_pos_loop.
How exactly is mouse_pos_loop declared? Also what exactly are au and Window? Namespaces or classes?
For example a free function in a namespace is different to a member function in a class when it comes to binding them to things like threads.

279
General / Re: Random Position Problem
« on: May 04, 2021, 08:01:17 am »
Is that Init function called every time a ship is reset to the top?
Generally srand should only be called once in the entire program (at the start).

Especially if using time() to seed it. time() works in seconds, if you srand before every rand then you'll get new random values only once per second. For example, if you reset 10 ships within a second, they will all get the same X position because the srand is resetting the random sequence back to the same starting point until the result of time() changes.

The C/C++ rand is pretty crap for repeating patterns anyway (and only returns a 15 bit value).

I generally use a 128bit Xor Shift random number generator. http://en.wikipedia.org/wiki/Xorshift
But C++11 brought in a new random number system: https://www.cplusplus.com/reference/random

280
Graphics / Re: TileMap: array of sprites vs vertexArray
« on: May 03, 2021, 12:21:56 am »
Another way to go is using a tile shader.

Using just a single quad and 1 draw call, you can have a huge area with no off screen drawing. Have an atlas texture for all your tiles and an index texture to specify which tiles to use.
The colour of each pixel in the index texture is the index of a tile in the atlas.
By changing the pixels of the index texture, you can animate tiles.

281
DotNet / Re: Problem with porting from NinePatch to C#
« on: May 02, 2021, 06:27:36 am »
The vertex array used to draw the patch has all of it's colour members defaulting to (0,0,0,0), so the patch is fully transparent (ie. invisible).
After making the patch, call this:
nine9sprite.Color = Color.White;

However this won't work yet, because there's a bug in the Color property setter. This is the current code:
        public Color Color
        {
            get
            {
                return m_vertices[0].Color;
            }
            set
            {
                foreach (Vertex vertex in m_vertices)
                {
                    Vertex tempvex = vertex;
                    tempvex.Color = value;
                }
            }
        }
The foreach loop goes over every vertex, but assigns the colour to a temp vertex, not the actual vertex array.
C# doesn't like foreach loops that modify values (if Vertex was a class, it would be ok, but as a struct, the foreach variable "vertex" is read only). So we need to change it to a normal loop like this:
        public Color Color
        {
            get
            {
                return m_vertices[0].Color;
            }
            set
            {
                for(int i=0;i<m_vertices.Length;++i)
                {
                    m_vertices[i].Color = value;
                }
            }
        }

After both of those changes, it's rendering.

282
DotNet / Re: How to use RenderWindow.SetIcon in sfml.NET
« on: May 02, 2021, 05:57:05 am »
SetIcon takes a width, a height and a byte array. Looking at the C++ header (where there's comments on how it works), the data it takes is RGBA pixels.
The Image class can load image files and provides a byte array of the pixels in RGBA. So you can make an icon like this:
Image image = new Image("icon.png");
window.SetIcon(image.Size.X, image.Size.Y, image.Pixels);
 

283
Feature requests / Re: Adding VertexArray[i].setTexture
« on: May 01, 2021, 03:17:54 am »
With some work, as long as you don't mind losing the ability to colour your vertices, it could be modified so that the vertex colour is used to select the correct tile, rather than using a lookup texture. Then at runtime changing the colour of the vertex would select the desired tile.
If there aren't too many tiles (less than 257) then the alpha channel could be used for selecting them, while RGB is used for colouring. (Assuming transparent vertices weren't required)

284
General / Re: SFML Setup with Visual Studio
« on: April 29, 2021, 12:46:56 pm »
Awesome! :)

285
General / Re: SFML Setup with Visual Studio
« on: April 29, 2021, 03:39:57 am »
Ok, getting close now.
If we look at the first error:
sfml-window-s-d.lib(InputImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__GetAsyncKeyState@4 referenced in function "public: static bool __cdecl sf::priv::InputImpl::isKeyPressed(enum sf::Keyboard::Key)" (?isKeyPressed@InputImpl@priv@sf@@SA_NW4Key@Keyboard@3@@Z)

It's saying that the isKeyPressed function in sfml-windows-s-d can't find a function called __imp__GetAsyncKeyState@4.
GetAsyncKeyState is a windows sdk function. Checking it at https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate says it comes in user32.lib.
All the following errors look like they are user32.lib (or similar windows sdk lib) related too.

So for some reason your project isn't linking user32.lib. Usually it should be inherited in the linker settings:


My first guess would be your project is trying to use the wrong windows sdk.
Try right clicking on the project in the solution explorer and selecting Retarget Projects. Then choose one of the SDKs in the combo box and hit Ok.

Pages: 1 ... 17 18 [19] 20 21 22
anything