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

Author Topic: [Solved] Binding real position to shader  (Read 1763 times)

0 Members and 1 Guest are viewing this topic.

ZenonSeth

  • Newbie
  • *
  • Posts: 19
    • View Profile
[Solved] Binding real position to shader
« on: June 01, 2013, 02:34:39 am »
I'm having a small issue, maybe someone can help me.

I set a custom view on my window, then I draw a CircleShape at a certain position, using a custom vert/frag shader.

I wanted to pass the information of that position into the frag shader, in such a way that its compatible (meaning accurate) with the positional information given by gl_Vertex in the vertex shader.

When I pass just the position, exactly the same as I set it on the circle shape, it seems that the 'center' doesn't appear to be in the center of the circle shape, and even more oddly moves around when the circle shape's position changes.

I figured I'd try the getView().getTransform().transformPoint(..) on the position, but that also yields strange results. The 'center' doesn't move when the circle shape moves, but still appears to be somewhere in the far upper left of the circle shape, and not the center. Yet I have set the circle shape's origin, via setOrigin to be so that it's center appears exactly at the given position.

I realize this isn't that easy to describe, but the screenshots I took aren't really clear either... hopefully someone can figure out what I'm talking about and offer advice. Thanks.

Edit: Basically I want to take a sf::Vector2f I pass as position in c++, and then give the accurate information on where that position is to opengl's shaders, in world space (not screen space)
« Last Edit: June 01, 2013, 01:53:14 pm by ZenonSeth »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Binding real position to shader
« Reply #1 on: June 01, 2013, 09:15:39 am »
The position of the shape is its exact position in the world, you don't have to transform it.

You should provide a complete and minimal example that reproduces the problem.
Laurent Gomila - SFML developer

ZenonSeth

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Binding real position to shader
« Reply #2 on: June 01, 2013, 01:38:16 pm »
Ok, so after your post, I went back and cleaned up my code, passing only the exact position as I've passed it into the CircleShape.

This didn't work, but since I assumed you are correct (it is your code), so I went to check my other code - namely my shader code.

My problem was in the vertex shader.. I had accidentally written
Code: [Select]
fragPos = gl_Vertex * gl_ModelViewMatrix;in my hurry to test this. The correct line is of course:
Code: [Select]
fragPos = gl_ModelViewMatrix * gl_Vertex;
So, problem fixed, thanks! It's still good to know that the exact world position as I pass it into shapes is what I need to pass in to the shaders.