Git Product home page Git Product logo

Comments (12)

eXpl0it3r avatar eXpl0it3r commented on May 29, 2024

when using a shader in combination with any shape

Can you be a bit more specific on that? In combination how? etc.

from csfml.

zsbzsb avatar zsbzsb commented on May 29, 2024

Can you post an example (just using CSFML calls) that shows the issue? Otherwise I'm inclined to think that it may be a bug with how your bindings work.

from csfml.

CWBudde avatar CWBudde commented on May 29, 2024

So far it seems to happen with every shader. This said, I have tried to nail it down to a very simple example.

I guess it needs to be adapted for compiling with plain C, but it's fairly simple to read I hope (given that Pascal was designed as a teaching language):

program Circles;

uses
  SysUtils,
  SfmlGraphics,
  SfmlSystem,
  SfmlWindow;

var
  VertexShader, FragmentShader: PAnsiChar;
  RenderTargetHandle: PsfRenderTexture;
  TextureHandle: PsfTexture;
  WindowHandle: PsfRenderWindow;
  Event: TsfEvent;
  States: TsfRenderStates;
  CircleShaderHandle: PsfShader;
  SpriteHandle: PsfSprite;
begin
  States.BlendMode := sfBlendAlpha;
  States.Transform := sfTransformIdentity;

  VertexShader :=
    '#version 110'#10 +
    'precision lowp float;'#10 +
    ''#10 +
    'varying vec2 uv;'#10 +
    ''#10 +
    'void'#10 +
    'main() {'#10 +
    '  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;'#10 +
    '  uv = vec2(gl_MultiTexCoord0);'#10 +
    '}';
  FragmentShader :=
    '#version 110'#10 +
    'precision lowp float;'#10 +
    ''#10 +
    'varying vec2 uv;'#10 +
    'uniform float Radius;'#10 +
    'uniform vec2 Position;'#10 +
    'uniform vec4 CircleColor;'#10 +
    ''#10 +
    'void'#10 +
    'main() {'#10 +
    '  vec4 color0 = CircleColor;'#10 +
    ''#10 +
    '  vec2 m = uv - Position;'#10 +
    '  float dist = Radius - sqrt(m.x * m.x + m.y * m.y);'#10 +
    ''#10 +
    '  float t = 0.0;'#10 +
    '  if (dist > 2.0)'#10 +
    '    t = 1.0;'#10 +
    '  else if (dist > 0.0)'#10 +
    '    t = 0.5 * dist;'#10 +
    ''#10 +
    '  color0.a = t * color0.a;'#10 +
    '  gl_FragColor = color0;'#10 +
    '}';
  CircleShaderHandle := sfShader_createFromMemory(VertexShader, FragmentShader);
  States.Shader := CircleShaderHandle;

  RenderTargetHandle := sfRenderTexture_create(800, 600, False);
  TextureHandle := sfRenderTexture_getTexture(RenderTargetHandle);

  // Create the main Window
  WindowHandle := sfRenderWindow_create(sfVideoMode(800, 600),
    PAnsiChar('SFML Shader'), [sfTitleBar, sfClose], nil);

  // Start the loop
  while sfRenderWindow_isOpen(WindowHandle) do
  begin
    // Process events
    while sfRenderWindow_pollEvent(WindowHandle, Event) do
    begin
      if Event.EventType = sfEvtClosed then
        sfRenderWindow_close(WindowHandle);
    end;

    SpriteHandle := sfSprite_create;
    try
      sfSprite_setTexture(SpriteHandle, TextureHandle, False);
      sfRenderWindow_drawSprite(WindowHandle, SpriteHandle, nil);
    finally
      sfSprite_destroy(SpriteHandle);
    end;

    sfShader_setColorParameter(CircleShaderHandle, 'CircleColor',
      sfColor_fromRGBA(Random($FF), Random($FF), Random($FF), Random($FF)));
    sfShader_setFloatParameter(CircleShaderHandle, 'Radius', 200 * Random);
    sfShader_setFloat2Parameter(CircleShaderHandle, 'Position', 800 * Random, 600 * Random);

    SpriteHandle := sfSprite_create;
    try
      sfSprite_setTexture(SpriteHandle, TextureHandle, False);
      sfRenderTexture_drawSprite(RenderTargetHandle, SpriteHandle, @States);
    finally
      sfSprite_destroy(SpriteHandle);
    end;

    // Finally, display the rendered frame on screen
    sfRenderWindow_display(WindowHandle);
  end;
end.

from csfml.

CWBudde avatar CWBudde commented on May 29, 2024

I forgot to mention that the AV happens in sfRenderTexture_drawSprite (the second call in the above code).

from csfml.

zsbzsb avatar zsbzsb commented on May 29, 2024

Just to confirm, this happens when only compiling with x64 and what compiler?

from csfml.

CWBudde avatar CWBudde commented on May 29, 2024

This basically only happens with the recent (v2.3) Win64 DLLs. It does not happen with the 2.2 DLLs (x64) nor with the x86 DLLs in version 2.3.

I have not tried other platforms, simply because I don't have much spare time. It's actually not "my" issue, but an issue of a user of my Pascal bindings. From the first glance the bindings look OK and because it is only not working with the v2.3 x64 DLLs I thought it could be a CSFML problem.

The compilers I have tried so far are FPC (Free Pascal Compiler, version 2.6.4) and some Delphi compilers (XE2 to XE7). Despite the different compilers the error is more or less identical.

from csfml.

zsbzsb avatar zsbzsb commented on May 29, 2024

@CWBudde Looking at the code you posted... any chance you could provide a stacktrace when it crashes?

from csfml.

zsbzsb avatar zsbzsb commented on May 29, 2024

@CWBudde Can you confirm this is still an issue? I really think this was due to something being mismatched or if it is a bug, it would be in SFML as nothing changed in CSFML between the releases.

from csfml.

DJMaster avatar DJMaster commented on May 29, 2024

Hello Christian,
try to change your code (in 2 places) adding the following ifdef GL_ES:

'#ifdef GL_ES'#10 +
'precision lowp float;'#10 +
'#endif'#10 +

working both i386-win32 and x86_64-win64 targets:

circles

from csfml.

eXpl0it3r avatar eXpl0it3r commented on May 29, 2024

Since we haven't received more information on the issue, I'll close this for now. If it turns out to still be an issue, feel free to reopen.

from csfml.

CWBudde avatar CWBudde commented on May 29, 2024

I updated the bindings to version 2.4 and (at least) now it seems to work as it should. In addition, the code I supplied wasn't that good, but at least everything is solved now.

from csfml.

eXpl0it3r avatar eXpl0it3r commented on May 29, 2024

Good to hear! 😊

from csfml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.