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

Author Topic: Problem with RenderTexture's Position  (Read 6552 times)

0 Members and 1 Guest are viewing this topic.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Problem with RenderTexture's Position
« on: January 24, 2016, 02:55:03 am »
Hi, Ladies and Guys from SFML

I'm running into an issue about RenderTexture and displacing of the drawing of my poor Sonic game's screen content

I create a RenderTexture(800, 600) as the screen's measures, and then everything that has to be drawn on the screen is drawn on it; then i call RenderTexture.Display(); then i create a Sprite and pass the RenderTexture.Texture to it; then i draw that sprite on the RenderWindow; and then i call RenderWindow.Display(); what i can see is like the screen's content (the Sprite) has been displaced to near the bottom of the screen, that is its top is near the physical screen's bottom.   

I have seen a post where this issue (or something similar) was treated, there they mention that the coodinates are inverted but they don't explain how is that inversion neither how to handle that issue and make the (0, 0) from the sprite matches the (0, 0) from the screen
Can someone help me on this?

Thanks in advance

Resethel

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #1 on: January 24, 2016, 03:24:40 am »
I don't have a proper answer for your question, yet i wonder:

Why not directly rendering on your sf::RenderWindow? unless you're applying a post effect or something, it might save you from a lot of worries :-\

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #2 on: January 24, 2016, 06:34:47 pm »
Hi Resethel,

I use the RenderTexture instead of drawing directly to the RenderWindow because, what i understood of what eXpl0it3r told me is that that would improve my poor Sonic game's performance (speed) ... i had asked for help because it runs a bit slow on my 64 bit system

Hapax

  • Hero Member
  • *****
  • Posts: 3339
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Problem with RenderTexture's Position
« Reply #3 on: January 24, 2016, 10:51:19 pm »
Render textures don't invert the y axis; they are the same as the rest of SFML's co-ordinates. SFML is inverted from OpenGL though, so things flip when you communicate with OpenGL directly (including shaders).

If you're using only SFML for this, what you described should work perfectly. Could you post a minimal and complete example where this problem (is it inverting the render texture or just moving it?) is present?

Just to make sure, your rendering could looks something like this:

renderTexture.clear();
renderTexture.draw(object);
renderTexture.display();
renderWindow.clear(); // although not actually necessary if the render texture is the same size as the window and fully opaque
renderWindow.draw(sf::Sprite(renderTexture.getTexture()));
renderWindow.display();

Also, confirm that you the render texture and the window are indeed the same size and that the origin and position of the render texture are both at (0, 0).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #4 on: January 26, 2016, 07:01:51 pm »
Hi, Hapax, and other Ladies and Guys

I tested the problem making a minimal code example, and occurs the same ...  :-[

Here i attach the code, that is in C# and with the DLLs for 64 bit systems ...

Could you continue helping me? Perhaps with this my poor Sonic game will run normally fast as it did on 32 bit system on the same hardware

Thanks

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Problem with RenderTexture's Position
« Reply #5 on: January 26, 2016, 08:55:52 pm »
Can you take a screenshot to show us what you're seeing? I ran your project with a few tweaks. I made it not fullscreen, changed the positions of the yellow and blue rectangles (to the top left, and the bottom right) so the issue would actually be visible.

Works just fine:


Changed code:
(click to show/hide)

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #6 on: January 27, 2016, 02:07:44 am »
Hi dabbertorres; other Ladies and Guys

I changed (just) the Style from Fullscreen to Resize (in order to be able to take a good screenshot, because with Fullscreen it appeared cut a part of the bottom, the one where you can see the top of the Sprite(RenderTexture.Texture) ), and the result is the same. It seems as if the sprite.Position was (0, 500) more or less, instead of (0, 0).
Here i attach the screenshot

Thanks for your help

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Problem with RenderTexture's Position
« Reply #7 on: January 27, 2016, 06:03:12 am »
Well that IS odd. Especially the gray background, as your code does not specify that gray anywhere that you've shown.

What kind of graphics card are you using?

Hapax

  • Hero Member
  • *****
  • Posts: 3339
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Problem with RenderTexture's Position
« Reply #8 on: January 27, 2016, 02:36:33 pm »
The grey background (and also square outlines) is because the application is not responding.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #9 on: January 27, 2016, 07:15:51 pm »
I think everything will be correct after yuo insert event loop :)

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Problem with RenderTexture's Position
« Reply #10 on: January 27, 2016, 08:31:55 pm »
The grey background (and also square outlines) is because the application is not responding.

Oh. Goes to show my familiarity with Windows. Haha.

I think everything will be correct after yuo insert event loop :)
Well, not necessarily... It worked fine on my machine without an event loop, and I presume his actual game has an event loop. This is a minimal example.

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #11 on: January 28, 2016, 10:39:00 am »
the app must have event loop because in some oses it will bug. As i see windows 8 and 10 don't have this bug.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #12 on: January 28, 2016, 06:23:43 pm »
Hi all Ladies and Guys

I searched what my graphics card was, and found this;

Display adapters: Mobile Intel (R) 45 Express Chipset Family (Microsoft Corporation WDDM1.1)
Monitors: Generic PnP Monitor
Sound, video, and game controllers: High Definition Audio Device

In my poor Sonic game, there is an infinte loop, not an Event loop, this is:

for ( ; ; ) { 
....
if (dead) break;
if (levelPassed) break;
}

Thanks for your help

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #13 on: January 28, 2016, 06:49:46 pm »
If you don't read events from the OS it will conclude that your app is not responding. You must read/process events.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 225
    • View Profile
    • Email
Re: Problem with RenderTexture's Position
« Reply #14 on: January 28, 2016, 11:12:07 pm »
Hi Jesper Juhl; other Members

Yes, i included the RenderWindow.DispatchEvents() method, in the minimal example, and in my poor Sonic application. What i wanted to say is that i was not handling the Frame Event, or the FPS, even i don't know if there is one, because i can manage with just the for loop.

In my previous post i described my graphics card and that.

Thanks for continue helping me