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

Author Topic: Odd behavior using backbuffer on OSX  (Read 3319 times)

0 Members and 1 Guest are viewing this topic.

SriK

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Odd behavior using backbuffer on OSX
« on: July 08, 2016, 07:37:10 pm »
Hey guys, I've recently started trying to get my game (which is developed using C# and SFML.NET) to run on Macs. I've followed this guide and gotten it to the point where it compiles and displays things onscreen, but the game is a flickery glitchy mess, which sprites and tiles rapidly appearing and disappearing, etc.

After some investigation trying to create a minimal example, I found that this code (which doesn't use a backbuffer) renders perfectly:

Code: [Select]
using SFML.Graphics;
using SFML.Window;
using SFML.System;

namespace TestSFML {
class MainClass {
public static void Main(string[] args) {
// initialize window
RenderWindow window = new RenderWindow(new VideoMode(640, 480, 32), "SFML Test", Styles.Close);
window.SetVerticalSyncEnabled(true);
window.Clear(Color.Black);
window.Display();

double sqrX = 20, sqrY = 20;

// game loop
while (window.IsOpen) {
window.DispatchEvents();

sqrX += 0.5;
sqrY += 0.5;

window.Clear();
Color rectangleColor = new Color(255, 0, 0);
RectangleShape r = new RectangleShape {
Size = new Vector2f(200, 200),
Position = new Vector2f((float)sqrX, (float)sqrY),
FillColor = rectangleColor,
OutlineColor = rectangleColor,
OutlineThickness = 1
};
window.Draw(r);

window.Display();
}

window.Close();
}
}
}

...but this code (which uses a backbuffer RenderTexture) is unresponsive and glitchy:

Code: [Select]
using SFML.Graphics;
using SFML.Window;
using SFML.System;

namespace TestSFML {
class MainClass {
public static void Main(string[] args) {
// initialize window
RenderWindow window = new RenderWindow(new VideoMode(640, 480, 32), "SFML Test", Styles.Close);
window.SetVerticalSyncEnabled(true);
window.Clear(Color.Black);
window.Display();

// create backbuffer image and sprite
RenderTexture backbuffer = new RenderTexture(640, 480);
Sprite bufferSprite = new Sprite {
Texture = backbuffer.Texture,
TextureRect = new IntRect(0, 480, 640, -480)
};
backbuffer.Clear();

double sqrX = 20, sqrY = 20;

// game loop
while (window.IsOpen) {
window.DispatchEvents();

sqrX += 0.5;
sqrY += 0.5;

backbuffer.Clear();
Color rectangleColor = new Color(255, 0, 0);
RectangleShape r = new RectangleShape {
Size = new Vector2f(200, 200),
Position = new Vector2f((float)sqrX, (float)sqrY),
FillColor = rectangleColor,
OutlineColor = rectangleColor,
OutlineThickness = 1
};
backbuffer.Draw(r);

window.Draw(bufferSprite);
window.Display();
}

backbuffer.Dispose();
bufferSprite.Dispose();
window.Close();
}
}
}

(Both programs are just rendering a red square which moves down and to the right every frame, with VSync on.)

Does anyone know why this could be happening? I'm not getting this issue with the second example on Windows.

I'm using CSFML 2.3.0 and SFML 2.3.2, with SFML.Net 2.2 (so the latest versions of everything). In addition, this is running on a Mac Mini with an Intel HD Graphics 4000 graphics card.

Thanks for your time, guys!
Sri

EDIT: Just tried using SFML 2.3.0 instead (to match CSFML's version number), nothing changed.
« Last Edit: July 09, 2016, 12:19:16 am by SriK »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Odd behavior using backbuffer on OSX
« Reply #1 on: July 09, 2016, 01:12:04 pm »
You never call display on the render texture.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SriK

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Odd behavior using backbuffer on OSX
« Reply #2 on: July 12, 2016, 03:02:27 am »
Thanks so much, that was it. I had no idea I had to do that first... I'm glad it was something this simple to fix.

What do you think was causing this code to work on Windows but not on Mac?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Odd behavior using backbuffer on OSX
« Reply #3 on: July 12, 2016, 03:09:53 am »
Probably due to different drivers and maybe also due to different OpenGL versions used. In the end it doesn't really matter. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything