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

Pages: [1]
1
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>

2
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.

3
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();

4
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

5
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?

6
DotNet / [SFML2.4 - VB NET 4.5.2] Overlap memory with heavy font files.
« on: August 21, 2021, 07:24:58 am »
Hi.
I have an very odd error.

I have finished a game (Evorales), this game works without any problem.
Now I am trying to add the Japanese language, which meant changing the fonts files (the ones I was using originally did not support Japanese characters).

At changing the fonts, the game began to give memory errors or texts that did not display well (and I don't mean string encoding problems).



Exactly the same source code, just changing the font files.

- Change "steamwreck" (35 kB)  for "NotoSerifCJKjp-hinted" (23 MB ), rear/write protected area memory error from sfml-graphics.dll when used SFMLwindows.draw(TEXTobject)
There was no error loading the font or creating the TEXT objects

- Change "steamwreck" (35 kB)  for  "mplus" (1300 kB), no memory error, but text strings were displayed with errors, for example "spaol" instead of "Español", etc.


After several hours of testing, I found that when creating a very big array to store the game's keystrokes, it overwritten the same memory area used by the font, causing this problem.

In my particular case, creating these variables somehow corrupts the font texture
Code: [Select]
Private plstGamePad(199999) As UInt32

Change 199999 for other number more small (999) or even more greater (999999) solve all previus TEXT problems.


My assumption is that the SFML implementation in NET does not reserve memory properly when loading font files. Apparently this error is notorious only with relatively large files.

I tried to produce a minimal code that would replicate the problem, but it was impossible, due to the limitations of the language when reserving memory.


7
SFML projects / Evorales Bullet hell game.
« on: August 19, 2021, 07:44:53 am »
Hi.
Evorales It is a project that I have been working on for the last 4 years and published on Steam 2 weeks ago.
It is a classic bullet hell with mechanics similar to "cave" shmups games.

It is programmed with vb studio, Net framework 4.5.2 and SFML (graphics, sounds, music and input).







Trailer


Here a gameplay from a friends (spanish)


About the game
Defeat the gnu-demon and his army and save the day in this top-down bullet hell focused on slowdown and bullet time mechanics. Easy to play but hard to master, it requires great strategy if you aim for a hi-score while dodging bullets across 12 hand-drawn, steampunk aesthetic stages, set in South America at the end of the 19th century, in an alternate universe.​

Evorales is inspired by the classic games of the mid-90s but with a Danmaku twist.
The first time you play it might seem like a very difficult game, but mastering the Alma and Ultra modes is the key to finishing the game and getting amazing scores.


8
DotNet / [SFML2.4 - VB NET 4.52] Vertex Array doubts
« on: December 13, 2019, 04:48:24 am »
Hi.
I try to work with vertex array over VB NET 2.4, and I discovered the following:


if I Try to draw a triangle with this code:
Code: [Select]
dim pX as integer = 100
dim pY as integer = 100
dim pVertex(2) as Vertex

pVertex(0) = New Vertex(New Vector2f(pX, pY), New Color(255, 0, 0, 255))
pVertex(1) = New Vertex(New Vector2f(pX+64, pY), New Color(255, 0, 0, 255))
pVertex(2) = New Vertex(New Vector2f(pX+64, pY+64), New Color(255, 0, 0, 255))

oRtScreen.Draw(pArrayAura, PrimitiveType.Triangles)

Work perfect.

But, if I declare the vertex without any parameter, and then try to set the value, then, SFML don't draw anything, but don't report any error.

Code: [Select]
dim pX as integer = 100
dim pY as integer = 100
dim pVertex(2) as Vertex

pVertex(0) = New Vertex()
pVertex(1) = New Vertex()
pVertex(2) = New Vertex()

pVertex(0).position = New Vector2f(pX, pY)
pVertex(1).position = New Vector2f(pX+64, pY)
pVertex(2).position = New Vector2f(pX+64, pY+64)

pVertex(0).color =  New Color(255, 0, 0, 255)
pVertex(1).color =  New Color(255, 0, 0, 255)
pVertex(2).color =  New Color(255, 0, 0, 255)

oRtScreen.Draw(pArrayAura, PrimitiveType.Triangles)

Don't work, but don't show any error.

Any idea why this happens?

9
Hi, this is my first post here, but I have a time reading the forum.

I have a very rare and funny problem, I tried to find other similar bug but no luck.

Description:
Randomly a sprite area change when I move the sprite.

I create only one time a sprite from a Texture with a "intrect", the texture and the sprite are power of 2  (texture 512*256 and sprite 64*64).
In the main loop, I'm only move the sprite with the position method, in some frame the drawing looks perfect, but in others, a part of the texture that is not originally in the sprite appears on the screen.

What I did notice is that the bug does not appear if the speed is a rational number, example VelX = VelY = 0.5, etc.

code:
Code: [Select]
Imports SFML.Window
Imports SFML.System
Imports SFML.Graphics

Public Class FrmFrameWork
    Dim WithEvents SFMLwindow As RenderWindow

    Private Sub FrmFrameWork_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim auxStyles As Styles = Styles.Default

        Dim MainLoop As Boolean = True
        Dim auxTimer As Integer = 0

        SFMLwindow = New RenderWindow(New VideoMode(1366, 768), "Prueba error SFML ", auxStyles) 'styles.fullscreen
        SFMLwindow.SetVisible(True)
        SFMLwindow.SetVerticalSyncEnabled(False)
        SFMLwindow.SetFramerateLimit(60)

        Dim texTest As New Texture("proyectiles2.png")
        Dim rctTest As IntRect
        rctTest.Width = 64
        rctTest.Height = 64
        rctTest.Left = 0
        rctTest.Top = 64
        Dim sprTest As New Sprite(texTest, rctTest)

        Dim PosX, PosY As Single
        Dim VelX, VelY As Single

        VelX = 4 * Math.Sin(15 * Math.PI / 180)
        VelY = 4 * Math.Cos(15 * Math.PI / 180)

        While MainLoop
            SFMLwindow.DispatchEvents()

            If Keyboard.IsKeyPressed(Keyboard.Key.Escape) Then MainLoop = False 'ESC siempre cierra el juego

            SFMLwindow.Clear(Color.Black) 'Limpiamos la pantalla

            auxTimer += 1
            If auxTimer Mod 30 = 0 Then
                PosX += VelX
                PosY += VelY
                sprTest.Position = New Vector2f(PosX, PosY)
            End If

            'auxSprite = New Sprite(oMeta.oRtScreen.Texture)
            'auxSprite.Position = oMeta.posScreen
            SFMLwindow.Draw(sprTest)

            SFMLwindow.Display()
        End While

        SFMLwindow.Close()
        Me.Close()


    End Sub
End Class


Detail:
I have the same problems with 2 PC.
PC 1
SFML.NET 2.2(32bit) + NET 4.52
VB NET community 2017
OS: Windows 10
CPU: Intel i7 3610qm
GPU: Nvidia GTX 660m

PC2
SFML.NET 2.4(64bit) + NET 4.52
VB NET Community 2019
OS: Windows 10
CPU: Intel i7 4790
GPU: 4095MB NVIDIA GeForce GTX 980 (MSI)

I always have my drivers and OS updated


PD: Sorry for my English is not my native language.

Pages: [1]
anything