Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 2 questions regarding shaders and the entity example.  (Read 6755 times)

0 Members and 1 Guest are viewing this topic.

arxae

  • Newbie
  • *
  • Posts: 6
    • View Profile
2 questions regarding shaders and the entity example.
« on: September 27, 2013, 11:30:45 am »
Hi, i'm a bit new to SFML and the whole graphics programming stuff, but SFML has been really helpfull in learning it all. I've looked at the tutorials on the site and some others and got the basics down (moving a sprite around, even got box2dx working). But there are 2 problems that i have no idea what i'm doing wrong.

It is probably really obvious, but sometimes you need someone to press your face against the issue :P

It's a small project test project, so some variables might be badly named: https://gist.github.com/arxae/71ff6c188162d8b2c0d8

Problem 1, shaders:
I draw a quad and try to apply a texture to it using shaders, but all i get is a black square. The texture itself is the black and white 2x2 block from tetris.
Side question: i presume using a shader on a sprite works the same as drawing a quad. Because if it is, my second problem isn't that huge :p

Problem 2, the entity example:
I followed the entity example from the C++ tutorials. Drawing works, the problem is that if pass a new vector2f to it to change it's position, it doesn't do anything.
The tutorial says that i should use getTransform(), but that method is not available in the C# bindings.

Can i get any assistance on this? It's been bugging me for the past week and i really wan't to know what i'm doing wrong here :p

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 2 questions regarding shaders and the entity example.
« Reply #1 on: September 27, 2013, 11:40:28 am »
Use this instead:

shader.SetParameter("texture", Shader.CurrentTexture);

... so that the shader will use whatever texture is used by the currently drawn entity.

You should also use the default shaders given in the tutorial, yours are lacking some stuff.

And what  "entity" tutorial are you referring to? Can you be more precise about your second problem?
Laurent Gomila - SFML developer

arxae

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: 2 questions regarding shaders and the entity example.
« Reply #2 on: September 27, 2013, 11:57:29 am »
Yay, fast response :p

The title of the tutorial was Designing you own entities with vertex arrays, the Creating a SFML-like entity part, sorry my bad :)

using Shader.CurrentTexture doesn't work, the square is still completely black.
Problem 1 and 2 are sepparate btw. I think you mean that i want to draw Shaders with the entity system, but i just switch the draw statement to the entity when i wanted to test that. If that is the case, sorry for being conusing :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 2 questions regarding shaders and the entity example.
« Reply #3 on: September 27, 2013, 12:20:11 pm »
Quote
using Shader.CurrentTexture doesn't work, the square is still completely black.
Have you fixed your shaders too?

Quote
I think you mean that i want to draw Shaders with the entity system, but i just switch the draw statement to the entity when i wanted to test that. If that is the case, sorry for being conusing
I'm sorry but this is very unclear, I don't understand you :P
Please use precise words (what is the "entity system"??).
Laurent Gomila - SFML developer

arxae

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: 2 questions regarding shaders and the entity example.
« Reply #4 on: September 27, 2013, 01:21:41 pm »
The shaders are also in the gist, at the bottom. or what do you mean fixing the shaders? :p

And maybe calling it system is kind of a stretch, but it's from this page: http://sfml-dev.org/tutorials/2.1/graphics-vertex-array.php
About halfway down the page

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 2 questions regarding shaders and the entity example.
« Reply #5 on: September 27, 2013, 01:55:40 pm »
Quote
The shaders are also in the gist, at the bottom. or what do you mean fixing the shaders? :p
I mean this:
Quote from: Laurent
You should also use the default shaders given in the tutorial, yours are lacking some stuff.

Quote
And maybe calling it system is kind of a stretch, but it's from this page: http://sfml-dev.org/tutorials/2.1/graphics-vertex-array.php
About halfway down the page
Ok, I finally see what you're asking :P
As any other getter, getTransform() is a property which is named Transform in SFML.Net.
Laurent Gomila - SFML developer

arxae

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: 2 questions regarding shaders and the entity example.
« Reply #6 on: September 27, 2013, 02:03:40 pm »
Entity thingy works now :D One down :p

Shaders still don't work, i copied the minimal shaders given on your tutorial page (http://www.sfml-dev.org/tutorials/2.1/graphics-shader.php) but still just a black square.
vert
Code: [Select]
//gl_Position = ftransform();

void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}
frag
Code: [Select]
uniform sampler2D texture;

void main()
{
vec4 pixel = texture2D(texture, gl_TexCoord[0].st);
gl_FragColor = gl_Color * pixel;
}

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: 2 questions regarding shaders and the entity example.
« Reply #7 on: September 27, 2013, 02:08:47 pm »
Have you tried the shader examples included in the .NET binding?
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 2 questions regarding shaders and the entity example.
« Reply #8 on: September 27, 2013, 02:58:10 pm »
Can you post your entire updated code?
Laurent Gomila - SFML developer

arxae

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: 2 questions regarding shaders and the entity example.
« Reply #9 on: September 27, 2013, 03:38:33 pm »
I updated the code at the same link: https://gist.github.com/arxae/71ff6c188162d8b2c0d8
Took a different texture, one that is not black/white. But now it displays nothing at all anymore

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 2 questions regarding shaders and the entity example.
« Reply #10 on: September 27, 2013, 04:28:53 pm »
You're still not using Shader.CurrentTexture.
Laurent Gomila - SFML developer

arxae

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: 2 questions regarding shaders and the entity example.
« Reply #11 on: September 27, 2013, 05:23:27 pm »
Bah, sorry must have forgotten. But it works now! :D At first i found it strange that it didn't work, but am i correct that you pass the texture like this?:

Code: [Select]
Shader shader = new Shader( "media/shaders/basic.vert", "media/shaders/basic.frag" );
shader.SetParameter( "texture", Shader.CurrentTexture );
RenderStates rState = new RenderStates( shader );
rState.Texture = texture;

 

anything