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.


Topics - LordNani

Pages: [1]
1
Network / UDP socket not sending packets.
« on: June 20, 2019, 11:12:48 pm »
I get error that packet ain't sent. With TCP this code worked.Things I've tried:
1)change port ::AnyPort
2)Use IP from hamachi with my friend
3)put debugging couts. After the first "while msg!=stop" loop it changes port and IP to 0 and 0000000000(Or so would seem)
4)Removing it from thread partially, *exclamation mark* partially fixed the problem, it worked 1 out of 10 times!
Help...I'll answer all questions quick.
sf::IpAddress hostIp = sf::IpAddress::getLocalAddress();
sf::UdpSocket udpSocket;
unsigned short port = 51234;
string recMsg ;
string msg;
void sendData(string msg);
sf::Thread secondThread(&sendData, msg);
int main() {
  udpSocket.bind(port);
  secondThread.launch();
while (msg != "stop") {
   
    if (udpSocket.receive(packet2, hostIp, port) != sf::Socket::Done)
      cout << "~~error receiving data" << endl;
        else {
                cout << "--data received" << endl;
                packet2 >> recMsg;
                if (recMsg != "")
                        cout << "Other user: " << recMsg << endl;
        }
  }

}
void sendData(string msg) {
  while (msg != "stop") {
    getline(cin, msg);
   
    packet << msg;

    if (udpSocket.send(packet, hostIp, port) != sf::Socket::Done)
      std::cout <<"~~Could not send data"<<endl;
}
 

2
General / Texture.update() is not working
« on: June 03, 2019, 08:00:43 pm »
It says Assertion failed: x + window.getSize().x <= m_size.x
 :-\
Size and x\y are correct
It all breaks on last line. I need it for selection and copy/paste tool
        bufferRect.width = abs(curPos.x - point1.x);
        bufferRect.height = abs(curPos.y - point1.y);
        int width = bufferRect.width;
        int height = bufferRect.height;
        int x = bufferRect.left;
        int y = bufferRect.top;
        std::cout << "width is "<< bufferRect.width << std::endl;
        std::cout << "height is " << bufferRect.height << std::endl;
        std::cout << "left and top are " << bufferRect.left << " + " << bufferRect.top << std::endl;
       
        bufferTexture.create(width, height);
        bufferTexture.update(mainWindow,x ,y );
 

3
Graphics / Why I can't setTexture?
« on: May 31, 2019, 11:11:29 pm »
How can I fix it?
  sf::Texture pencilIcon;
  sf::RectangleShape testShape;
  testShape.setTexture(pencilIcon);
I know, it says about *texture, but I don't know how to pass it(setTexture(*pencilIcon) doesn't work)

[FIXED]

4
General / Can you loadFromImage to RenderTexture?
« on: May 28, 2019, 11:54:51 am »
image.create(windowWidth, windowHeight, sf::Color::White);
sf::RenderTexture canvas;
sf::IntRect area = sf::IntRect(0, 0, image.getSize.x, image.getSize.y);
canvas.getTexture().loadFromImage(image,area);

I need it so I can open and edit images.

5
General / Dotted line instead of normal
« on: May 27, 2019, 11:54:37 pm »
Hello fellas! I am working on Paint 2.0 project which is supposed to be simple yet WORKING graphics editor, using sfml. Yesterday I have encountered the problem which I still can't fix.
I am implementing Pencil tool, but instead of creating normal smooth line it draws dotted and separated ones.
At first, I just made it with drawPixel function but right now I am using Vertices to make lines based on the previous mouseMoved register. In both cases, I get the same scenario.
Here is the function call.
while (mainWindow.pollEvent(event)) {
      if (event.type == sf::Event::Closed)
        mainWindow.close();
      else if ((event.type == sf::Event::MouseMoved) &&
               sf::Mouse::isButtonPressed(
                   sf::Mouse::Left)) // MouseMoved and leftClickHeld
      {
        switch (currentTool) {
        case 0: {
          vecLine =
              drawPencil(mainWindow, currentColor,
                         sf::Mouse::getPosition(mainWindow), thickness, 0);
          break;
        }
        }
      } else if (event.type == sf::Event::MouseButtonPressed) {
        switch (currentTool) {
        case 0: {
          vecLine =
              drawPencil(mainWindow, currentColor,
                         sf::Mouse::getPosition(mainWindow), thickness, 1);
          break;
        }
        case 1: {
          vecLine = drawLine(mainWindow, currentColor,
                             sf::Mouse::getPosition(mainWindow));
          break;
        }
        }
 
And here is the function that draws lines

std::vector<std::pair<sf::Vertex, sf::Vertex>>
drawPencil(sf::RenderWindow &mainWindow, sf::Color color,
           sf::Vector2i currentPos, unsigned int thickness, int mode) {
  if (thickness == 0) {

    if (mode == 1) {
      line[0].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
      line[1].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
      line[0].color = color;
      line[1].color = color;

    } else {
      if (firstPoint) {
        line[0].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
        line[1].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
        line[0].color = color;
        line[1].color = color;
        firstPoint = false;
      } else {
        line[1].position = sf::Vector2f(sf::Mouse::getPosition(mainWindow));
        firstPoint = true;
        vecLine.push_back(std::make_pair(line[0], line[1]));
      }
    }
    return vecLine;
  } else {
  }
}

Int mode is to deny lines that could be drawn just by clicking and not dragging.

I suspect it's connected with MouseMoved update rate

Pages: [1]