Comments (12)
when using a shader in combination with any shape
Can you be a bit more specific on that? In combination how? etc.
from csfml.
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.
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.
I forgot to mention that the AV happens in sfRenderTexture_drawSprite (the second call in the above code).
from csfml.
Just to confirm, this happens when only compiling with x64 and what compiler?
from csfml.
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.
@CWBudde Looking at the code you posted... any chance you could provide a stacktrace when it crashes?
from csfml.
@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.
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:
from csfml.
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.
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.
Good to hear! 😊
from csfml.
Related Issues (20)
- setSmooth feature for Fonts HOT 2
- Problem building on Debian Bookworm HOT 2
- Calling `sfRectangleShape_getSize` causes program to show black screen HOT 1
- Consider adding a Default RenderState HOT 1
- Sf::drawable HOT 1
- Implement remaining SFML 2.6.0 changes HOT 17
- Add pkg-config support HOT 4
- Use .hpp extension for private C++ headers HOT 1
- Apple silicon compatibility HOT 6
- Generated CSFML documentation does not document any functions HOT 2
- Add example programs HOT 1
- Build in Debug mode in CI HOT 1
- Add `format` and `tidy` targets as seen in SFML
- Use inheritance to implement wrapper struct types HOT 2
- 2.6.0 release HOT 2
- Add private conversion utilities between corresponding C and C++ data types HOT 2
- Insufficient documentation for `sfVulkan_getGraphicsRequiredInstanceExtensions`? HOT 4
- Install prefix not honored HOT 4
- Some CSFML 2.6.x API Discrepancies HOT 2
- Fail fast on invalid null arguments
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csfml.