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

Pages: [1] 2
1
Sorry I didn't answer sooner, but my laptop was stolen.
Right now I only have a linux machine, I installed c# and SFML, but I get random errors, so I think I'll migrate to C++ to be able to develop under linux.

Thank you very much for your time and answers.

2
Thanks for your answer eXpl0it3r.

I understand the root of the problem, but I'm not sure how to fix it.

I want to point out, my problem is that I do NOT have access to the joystick, even using Joystick.Update() in each loop, if the joystick is not connected from the start of the application (I highlight this part, because it is the condition that leads to the error )

I comment on this, because in the issue they wrote this:
"Unless I manually update the joystick state before the calls."
If I understand correctly, this refers to calling "Joystick.Update()", but again, I called Joystick.Update and still don't have access to the joystick.
Which makes me doubt that it is exactly the same problem.

It also read "I changed window to regular sfWindow (instead of sfRenderWindow)", but I don't know how to replicate this in C# with Net 6.0

I understand recompiling SFML with the proper flags, but I'd have to study how to compile SFML for Net 6.0 and before doing that, I'd like to make sure it's the same error.

3
Hi.
If you look at the source code, you'll see that "Joystick.update()" is called every loop.

Also, in my tests, the "DirectInput" error occurs precisely when I call "Joystick.update()".

EDIT:
In C# if you don't call Joystick.update() every loop, SFML doesn't refresh the value of the gamepad input.

4
I encountered a problem when trying to use a gamepad or joystick that is connected in the middle of program execution.

I have this minimum code:
Code: [Select]
// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");

using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.System;
using SFML.Window;

namespace sfml
{
    class Program
    {
        static void Main(string[] args)
        {
            string TITULO = "Test Input";
            string VERSION = "0.0.1";
     
            //Selección estilo de ventana
            Styles auxStyle = Styles.Default;

            //Creamos el objeto windows
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), TITULO + "  v " + VERSION, auxStyle);
            window.Closed += (_, __) => window.Close();           
            window.JoystickConnected += (o, e) => gamePad_connect(e);
            window.JoystickDisconnected += (o, e) => gamePad_disconnect(e);
           

            //Variable propias de este contexto, como color de renderwindow o auxiliares para shader
            Color backColor = new Color(0,0,255); //Color de fondo

            Joystick.Update();

            int Joystickcount = 0;
            for(uint i=0;i<8;i++){
                if (Joystick.IsConnected(i)) { Joystickcount++; }
            }
            Console.WriteLine("Total de Joystick: " + Joystickcount.ToString());

            //Ciclo principal
            while (window.IsOpen)
            {

                //***** Rutinas especiales como actualizacíon de gamepad *****
                Joystick.Update();
                int newJoystickcount = 0;
                for(uint i=0;i<8;i++){
                    if (Joystick.IsConnected(i)) { newJoystickcount++; }
                }
                if (newJoystickcount != Joystickcount) {
                    Joystickcount = newJoystickcount;
                    Console.WriteLine("Total de Joystick: " + Joystickcount.ToString());
                }
                if (Joystick.IsButtonPressed(0,0)) { Console.WriteLine("Joystick 0, button 0 "); }
           
                window.DispatchEvents(); //Control de eventos
                window.Clear(backColor); //Limpiamos la pantalla con el color de fondo seleccionado
             
                window.Display();
            }

        }

        static void gamePad_connect(JoystickConnectEventArgs e){
            Console.WriteLine("Joystick " + e.JoystickId.ToString() + "conectado");
        }
        static void gamePad_disconnect(JoystickConnectEventArgs e){
             Console.WriteLine("Joystick " + e.JoystickId.ToString() + "desconectado");
        }
    }
}

If I have a joystick connected and I run the application, it is detected and can be used without problem.

If in the middle of the execution I disconnect the joystick, the disconnection is detected, the number of connected joystick is updated.
then i reconnect the joystick, the connection is detected, the number of connected joystick is back to 1 and i can use the joystick again, so far everything works as expected.

The console output:
Quote
Total de Joystick: 1
1661 Joystick 0, botón 0
Total de Joystick: 0
Joystick 0 desconectado
21 Failed to create DirectInput device: -2147467259
578 Failed to create DirectInput device: -2147221164
Total de Joystick: 1
Joystick 0 conectado
554 Joystick 0, botón 0
The program '[10288] test_input.dll' has exited with code 0 (0x0).


***************************************
The problem occurs when I launch the app without the joystick connected.

If, during the execution of the program, I connect the joystick, you can see that it actually triggers the "JoystickConnected" event. But I don't have access, since all the joysticks of "Joystick.IsConnected" mark false.
I have tried to force read with
"if (Joystick.IsButtonPressed(0,0)) { Console.WriteLine("Joystick 0, button 0 "); }"

But it doesn't work, it's like SFML detects that the joystick was connected, but doesn't give access to it.

Quote
Total de Joystick: 0
Joystick 0 conectado
Joystick 0 desconectado
14
Failed to create DirectInput device: -2147467259
Joystick 0 conectado
The program '[4728] test_input.dll' has exited with code 0 (0x0).

Is it necessary to do something to be able to access the Joystick or is it a bug?


Spec
Windows 10.
C#
Code: [Select]
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="SFML.Net" Version="2.5.0" />
  </ItemGroup>

</Project>

5
DotNet / Re: Refresh draw but in background?
« on: October 24, 2022, 08:15:01 pm »
Hi.
First, thanks for your time.
It took me a while to answer because I had to coordinate with my friend.

We did several tests, I made sure that the SFML application window was not minimized.

We placed the window in the upper left corner and with some emulators (mame) the application did work in the background.
But with other emulators (mednafen) we couldn't find a way to make it work.
I always mean having SFML in the background and the emulator in full screen.

I wouldn't know what to conclude, I really don't know because with some emulators/games it doesn't give a problem, but with others it does.


PS: In the afternoon I will edit this message with some videos of the tests we did.


6
DotNet / Re: Refresh draw but in background?
« on: October 19, 2022, 11:51:33 pm »
I imagined that it would not be something simple.

I already proposed the second monitor to him, but he would only use it for this, so I don't think he would connect a second monitor.

As always, thank you very much for your reply eXpl0it3r

EDIT:
In case it helps someone in the future.

In the end I have used a NET winform, the graphics are PictureBox and I have used SFML to capture the input.

The form's pictureBox is updated in the background, it's not ideal, but at least it works for what I need.

7
DotNet / Refresh draw but in background?
« on: October 15, 2022, 07:27:13 pm »
Hi, I have a rather strange question.

I will try to explain what I need.

I have a friend who streams games to youtube, he currently uses the settings window of an emulator called Dolphin to capture his gamepad input and stream it to youtube.



With SFML (Core net 6 and SFML 2.5.0) I programmed an application that did the same thing, but was prettier.


To transmit, he uses the OBS program that allows him to capture the windows of the different applications, he normally transmits playing in full screen and the Dolphin window (the program he currently uses to capture the inputs of the gamepad) stays in the background and works without problem .

My application works even if the window does not have the focus, even SFML does capture the input of the gamepad while it is in the background (having the game in full screen).
I know this because I programmed a log every time an input was detected.

The problem is that visually SFML does not update while in the background, in the OBS stream, you see only the static image.


I understand that SFML is not meant to run in the background and this is a pretty weird application.

But is it possible to get SFML to refresh the windows while in the background?

If not, do you know any other way to do it?


EDIT:
I just noticed something similar, if you put the window created by SFML cut in the middle of one of the sides of the desktop.

The thumbnail generated by windows 10 only updates the part of the SFML window that is visible inside the script.


sorry for the blurry image, but I couldn't find a way to capture the thumbnail if it wasn't with a photo from my cell phone.

8
General / Re: change shader origin from renderwindows to rendertexture
« on: August 02, 2022, 02:48:26 am »
Hi, as always, thanks for your answers


Short answer, yes.

But thanks to your answer, I realized something,  I need call for a display after pass the shader.

Originally my loop was:
Code: [Select]
- Draw sprite from game to a rendertexture named oGame.gameWindow.
- oGame.gameWindow.Display();
- Convert de renderTexture to a sprite named sprGameWindow.
- Scale and center the sprite sprGameWindow.

- Pass the new sprite and the shader to windowsrender:
window.Draw(sprGameWindow, new RenderStates(fragShader));

From what I understand, gl_FragCoord is returning the coordinate of the object that calls draw() (windowrender in this case) and not the object that I pass as a parameter (sprGameWindow).

With that in mind, I changed my loop, adding a temporary renderTexture that calls the draw function and now works it as intended.

New loop:
Code: [Select]
- Draw sprite from game to a rendertexture named oGame.gameWindow.
- oGame.gameWindow.Display();
- Convert de renderTexture to a sprite named sprGameWindow.
- Scale the sprite sprGameWindow.

- Pass the sprite sprGameWindow and the shader to tempRenderTexture:
tempRenderTexture.Draw(sprGameWindow, new RenderStates(fragShader));
tempRenderTexture.Display().

- Convert de temprenderTexture to a new sprite.
- Center the new sprite.

window.Draw(tempRenderTexture);

Thank you very much eXpl0it3r

9
General / change shader origin from renderwindows to rendertexture
« on: July 31, 2022, 08:58:07 am »
Hi.

It is the first time that I use a shader and after reading several tutorials and a lot of trial and error I have managed to program a shader to imitate an LCD screen.

My game resolution is 160x144 pixels, so I use a rendertexture to draw all the game content and then I scale and center the rendertexture over the windowstexture which is created with a more compatible resolution. (see attached image).



The problem is that the shader uses the bottom-left corner of the windowstexture as the point of origin and depending on the resolution, when centering the rendertexture, it turns out that the shader does not synchronize with the game image.



One solution is to pass the position of the rendertexture to the shader, but since I'm new to shaders, I was wondering if there isn't a way to tell the shader that I want the origin point to be the bottom-left corner of the rendertexture?


Shader
Code: [Select]
uniform sampler2D texture;

uniform float brillo;
uniform float linea;
uniform float scale;

vec4 vecbrillo = vec4( brillo+0.5, brillo+0.5, brillo+0.5 , 1.0);
vec4 veclinea = vec4( linea, linea, linea , 1.0);

void main( void ) {
// lookup the pixel in the texture
    vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

//vec2 xy = gl_FragCoord.xy;
vec2 xy = gl_FragCoord.xy;
if(floor(mod(xy.y,scale)) == 0 || floor(mod(xy.x,scale)) == 0){
        pixel = veclinea * pixel;
    }else{
if(pixel.r<0.05){ pixel.r = 0.1;}
if(pixel.g<0.05){ pixel.g = 0.1;}
if(pixel.b<0.05){ pixel.b = 0.1;}
}

gl_FragColor = vecbrillo * pixel;
}

C#
Code: [Select]
// ACTUALIZAR DISPLAY
                oGame.gameWindow.Display();
                sprGameWindow = new Sprite(oGame.gameWindow.Texture);
                sprGameWindow.Scale = new Vector2f(scalewindows,scalewindows);
                sprGameWindow.Position = new Vector2f(200,0);

                //fragShader.SetUniform("resolution", new Vector2f(400,400));
                //fragShader.SetUniform("time", clk.ElapsedTime.AsSeconds() );
                //fragShader.SetUniform("mouse", new Vector2f(Mouse.GetPosition().X, Mouse.GetPosition().Y));
                if (Keyboard.IsKeyPressed(Keyboard.Key.Up)) { brillo += (float)0.01; }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Down)) { brillo -= (float)0.01; }
                if (brillo > 1) { brillo = 1;}
                if (brillo < 0) { brillo = 0;}
                fragShader.SetUniform("brillo", brillo);
                fragShader.SetUniform("linea", (float)0.1);
                fragShader.SetUniform("scale", (float)scalewindows);

                window.Draw(sprGameWindow, new RenderStates(fragShader));
               
                window.Display();

10
DotNet / Re: c# switch fullscreen/window
« on: June 01, 2022, 04:05:59 am »
Yes, in C# you'll have to create a new window. Biggest down side of the current design is that you'll need to reassign the event handlers...

Thank.

11
DotNet / Re: c# switch fullscreen/window
« on: May 29, 2022, 05:12:41 am »
After several trial and error. I have managed to switch between modes with the following code, I don't know if it will be optimal or if it will have some disadvantage, but for now it works.

if (Keyboard.IsKeyPressed(Keyboard.Key.Enter) == true && Keyboard.IsKeyPressed(Keyboard.Key.LAlt) == true) {
                    auxStyle = (auxStyle == Styles.Default)? Styles.Fullscreen: Styles.Default;
                    window.Close();
                    window = new RenderWindow(new VideoMode(oProperties.ScreenWidth, oProperties.ScreenHeight), "SFML running in .NET Core", auxStyle);
                    window.Closed += (_, __) => window.Close();
                } //Alternar ente pantalla completa y ventana con Alt-Enter
 

12
DotNet / c# switch fullscreen/window
« on: May 27, 2022, 08:16:34 pm »
Hi.

I would like to know how I can switch between fullscreen and windows mode but without having to restart the game (To implement a mode switch with Alt-Enter).

Searching in google I found that with C it can be done with "Window->create", but I have not been able to find how to do it with C# in .NET Core.

Thank in advance

13
DotNet / Re: Switch GPU with code?
« on: September 08, 2021, 10:53:49 pm »
I'm going to see if I can implement it in VB, but I will save that code for my next project. I will do with code and C #.

Thanks very much.

14
DotNet / Re: Switch GPU with code?
« on: September 08, 2021, 03:22:06 am »
Thank you very much for your answer.
I've been trying to activate the macro in VB NET for a while but without success.
Will you have an example to guide me?

15
DotNet / Switch GPU with code?
« on: September 05, 2021, 04:18:19 am »
Hi.
it is possible through code, determine which GPU a game should use?

Many laptops use 2 GPUs (integrated intel and dedicated nvidia for example).

If I run a game as "factorio", the laptop automatically knows to run that game with the Nvidia GPU.
On the contrary, if I have a game programmed with SFML, when it runs, it does so with the integrated GPU.

I know it is possible to change this manually in the Nvidia settings, but I would like to know if there is any way to select the GPU automatically. when creating videomode maybe?

Pages: [1] 2