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 - jl1532

Pages: [1]
1
Graphics / Re: Getting a blank image
« on: June 07, 2021, 01:11:39 pm »
Thankfully I think I figured it out. I move win.update(win) into the outer while loop, before win.clear();

2
Graphics / Getting a blank image
« on: June 07, 2021, 01:03:14 pm »
Hi, I would like to save a screenshot of the window but end up with getting a blank image
sf::RenderWindow win(sf::VideoMode(500, 1000), "Window 1");
sf::Texture texture;
sf::Image image;
texture.create(win.getSize().x, win.getSize().y);
texture.update(win);

 while (win.isOpen()) {
    sf::Event event{};
    while (win.pollEvent(event)) {
      if (event == sf::Event::Closed) {
        win.close();
      }
    }
    win.clear();
    win.draw(SomeShape);

    image = texture.copyToImage();                         // Assign texture to image
    image.saveToFile("../Saved Image/Logo.png");     // Able to generate the image file, but it's blank...

    win.display();
  }
}

I tried to put the two lines with comments at different position, for instance before win.clear or after win.display, but I still got a blank image.

3
Window / Able To Open a New Window But Not Close it
« on: June 07, 2021, 02:25:17 am »
Hi, I create a feature that if the user clicks the menu, a window pops out. I'm able to display the pop window but not close it.
class PopWindow {
private:
    sf::RenderWindow popWin;
    sf::Color popWinColor = sf::Color(50, 50, 50);

public:
    // Default constructor
    PopWindow();

    // While pop is Open
    int winOpen();
};
#include "PopWindow.h"

PopWindow::PopWindow() {
  popWin.create(sf::VideoMode(500, 500), "Pop Window");
}

int PopWindow::winOpen() {
  sf::Event popWinEvent{};
  while (popWin.isOpen()) {
    while (popWin.pollEvent(popWinEvent)) {
      if (popWinEvent.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::F2)) {
        popWin.close();
      }
      popWin.clear(popWinColor);
      popWin.display();
    }
  }
  return 0;
}

The weird thing is if I declare a PopWindow object and call object.winOpen() in the main class, everything works fine, however, if the object is declared in one of other classes, I can only open a new window but not close it.

How to handle events for multiple windows?
Thanks for your help!

4
I'm using vscode on a Mac, everything works fine until I updated the OS last night... Still working on it...

Pages: [1]