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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - PGco

Pages: [1]
1
General / Re: GPU usage jumping to 100% after changing resolution
« on: January 18, 2024, 05:45:02 pm »
Oh thanks! That makes sense, I don't know why I assumed it would vsync would stay enabled after closing and reopening the window.

2
General / GPU usage jumping to 100% after changing resolution
« on: January 17, 2024, 11:20:25 pm »
My game is just a black background with white text, but, when the user changes resolution the GPU jumps to 100% and stays there. This issue happens on Windows, Linux, and Wine on Linux. It happens every time. I don't understand if I'm doing something wrong, or if SFML is.

The code for when the game starts up is this:
void TextInit()
{
  font.loadFromFile("TextFont (FreeMono).otf");
  font2.loadFromFile("UserInputFont (FreeMono).otf");

  text = sf::Text();
  text.setFont(font);
  text.setPosition(0,0);
  text.setFillColor(sf::Color(255,255,255,255));
  text.setCharacterSize(20);

  userInput = sf::Text(UserInputPre(), font2);
  userInput.setPosition(0,1000);
  userInput.setFillColor(sf::Color(255,255,255,255));

  videoMode = sf::VideoMode(width, height);
 
  if(doFullscreen)
    window.create(videoMode, "Total Control", sf::Style::Fullscreen);
  else
    window.create(videoMode, "Total Control");

  window.setMouseCursorVisible(true);
  window.setMouseCursorGrabbed(false);
 
  camera = sf::View(sf::FloatRect(0,0,width,height));

  //window.setFramerateLimit(30);
  window.setVerticalSyncEnabled(true);

  window.setView(camera);

  texture.loadFromFile("Background.png");
  bg = sf::Sprite(texture);
  bg.setPosition(0,1005);
  bg.setScale(60, 5);
  uiBoxHeight = bg.getPosition().y;
 
}
The code to change resolution is this:
void ChangeResolution(int size)
{
  std::vector<sf::VideoMode> vms = sf::VideoMode::getFullscreenModes();

  width = vms[size].width;
  height = vms[size].height;

  videoMode = sf::VideoMode(width, height, vms[size].bitsPerPixel);
 
  if(doFullscreen)
    window.create(videoMode, "Total Control", sf::Style::Fullscreen);
  else
    window.create(videoMode, "Total Control");

  camera = sf::View(sf::FloatRect(0,0,width,height));

  userInput.setPosition(0,height-userInput.getCharacterSize()-55);
  bg.setPosition(0,height-userInput.getCharacterSize()-55);

}

Here is the draw code:
void TextManager()
{
  bg.setColor(colours[inputBackgroundCol]);
 
  window.clear(colours[backgroundCol]);
  window.draw(text);
  window.draw(bg);
  window.draw(userInput);
  window.display();
}

Pages: [1]