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

Pages: [1]
1
Network / Problems sending multiple messages
« on: July 04, 2012, 07:02:33 am »
Hi, I have some really simple code that sends 10 consecutive numbers.

Sender:
int main()
{
        std::cout << "Sending\n";
        sf::UdpSocket socket;
        socket.bind(8041);
        socket.setBlocking(true);
       
        sf::IpAddress loopback("127.0.0.1");
        for(int i = 0; i < 100; i++)
        {
                sf::Packet packet;
                packet << sf::Int32(i);
                socket.send(packet, loopback, 8040);
        }
        std::cout << "Done sending\n";
}

Receiver:
int main()
{
        std::cout << "Ready\n";
        sf::UdpSocket socket;
        socket.setBlocking(true);
        socket.bind(8040);
        while(1)
        {
                sf::Packet packet;
                sf::IpAddress address;
                unsigned short port;
                socket.receive(packet, address, port);
                std::cout << "Packet received from " << address.toString() << " port: " << port << "\n";
                sf::Int32 i;
                packet >> i;
                std::cout << "Message: " << i << "\n";
        }
}

When I turn on the receiver, then run my sender, I get this output on the receiver's console:
Ready
Packet received from 127.0.0.1 port: 8041
Message: 0
instead of 100 messages from 0 to 99, which is what I expect.

When I add this line of code to add a slight delay in the sender
sf::sleep(sf::Time(sf::milliseconds(1)));
right after this line:
socket.send(packet, loopback, 8040);

I get every message, except the 2nd message ("Message: 1"), gets mysteriously lost most, but not all of the time. Why do I need this delay here? And any clues on why only the second message keeps getting lost consistently?

2
Network / UDP fragmentation and reassembly
« on: July 01, 2012, 11:09:32 pm »
Hi, I'm using SFML 2.0 release candidate, but I am learning how to use the Network package with the SFML 1.6 tutorial for now.

In this tutorial: http://www.sfml-dev.org/tutorials/1.6/network-packets.php
Quote
The third problem is more network related. Data transfers through TCP and UDP protocols must follow some rules defined by the lower levels of implementation. In particular, a chunk of data can be split and received in several parts ; the receiver must then find a way to recompose the chunk and return data as if it was received in once.
This seems to imply that SFML will handle fragmentation and reassembly of packets if you send too large packets. If you send a large packet with UDP, and it is split up into a number of smaller packets, if even one of those packets fails to send, will the entire message be lost?

3
I am pretty sure this is the case (why else would SFML offer threading if locking was not reliable), but I just wanted some confirmation since there is no guarantee that these operations are atomic in the documentation. I'm looking at Windows, OS X, and Linux.

4
Window / Enabling the depth buffer
« on: March 10, 2012, 08:15:41 am »
I'm using SFML 2.0, on Windows 7 Ultimate.

I want to create an OpenGL context that enables the depth buffer. Here is how I'm currently going about it:
Code: [Select]
sf::ContextSettings context(24, 8, 2, 3, 3);
sf::Window window(sf::VideoMode(500, 500, 32), "SFML Window", 7U, context);
{ //Loads OpenGL functions
glewExperimental=TRUE;

GLenum err = glewInit();
if (GLEW_OK != err)
{
 /* Problem: glewInit failed, something is seriously wrong. */
 fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
}
fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
}
sf::ContextSettings windowSettings = window.GetSettings();
std::cout
<< "windowSettings.DepthBits: " << windowSettings.DepthBits << "\n"
<<  "windowSettings.StencilBits: " << windowSettings.StencilBits << "\n"
<< "windowSettings.AntialiasingLevel: " << windowSettings.AntialiasingLevel << "\n"
<< "windowSettings.MajorVersion: " << windowSettings.MajorVersion << "\n"
<< "windowSettings.MinorVersion: " << windowSettings.MinorVersion << "\n";
window.SetActive();


The output is what I expect:
Code: [Select]
Status: Using GLEW 1.7.0
windowSettings.DepthBits: 24
windowSettings.StencilBits: 8
windowSettings.AntialiasingLevel: 2
windowSettings.MajorVersion: 3
windowSettings.MinorVersion: 3


I thought creating a window with an sf::ContextSettings that has some number of bits for DepthBits automatically enables the depth buffer. But it seems writing/reading from the depth buffer does not work. When I wrap my exact same OpenGL code around a freeglut framework, rather than an SFML framework, depth testing appears to work.

5
Window / Sending OpenGL commands after window is closed?
« on: March 03, 2012, 02:04:54 am »
Hi, my question is this: Is it safe to send OpenGL commands when a window has been set as the active window, then closed?

Hopefully that is a yes or no question. If not, here is a more detailed description of my problem.

I have been using OpenGL with SFML for some time now. I am running Windows 7 Ultimate, with SFML 2.0, with static linking. This problem occurs both when I create a context with OpenGL 3.3 and 4.1.

In my main loop, the window polls for input, does its OpenGL commands, then calls Display() on the active window. If during the polling for events, sf::Event::Closed is detected, Close() is called active window immediately.

What this means is that for at least one iteration of the main loop, OpenGL commands are being sent despite the active window being closed.

It looks something like this:

Code: [Select]

 sf::Window window(sf::VideoMode(800, 600), "SFML window");
//initialize OpenGL (set up shaders, etc.)

while (window.isOpen())
{
sf::Event anEvent;
while (window.PollEvent(anEvent))
{
if (anEvent.Type == sf::Event::Closed)
window.Close();
}

//OpenGL commands...
window.Display();
}


After the window is closed, the main loop exits, and the program quits.

This works fine, but I made some additions to my OpenGL code to use Vertex Array Objects and Depth Buffering, without changing any SFML-related code and now when I close the window, instead of exiting smoothly, the program crashes. Debugging this shows that sending a draw command then modifying a uniform variable causes the program to crash. This is kind of unusual, since OpenGL commands themselves do not generally cause a program to crash.

To workaround this I have had to modify the main loop a little bit.

Code: [Select]

while (window.isOpen())
{
sf::Event anEvent;
bool isOpen = true;
while (window.PollEvent(anEvent))
{
if (anEvent.Type == sf::Event::Closed)
isOpen = false;
}

//OpenGL commands...
window.Display();
if (!isOpen)
window.Close();
}


Now, OpenGL commands are never being sent to a closed window.

6
General discussions / Need GLEW for SFML?
« on: February 20, 2012, 07:06:06 pm »
I believe SFML can be used to create OpenGL contexts, but does it load the OpenGL functions, or will I need to use a separate OpenGL loading library?

Basically, does SFML do this?
http://www.opengl.org/wiki/OpenGL_Loading_Library

Edit:
I ask this because after I include SFML's OpenGL header like this:
Code: [Select]
#include <SFML/OpenGL.hpp>

I still get compiler errors like this:
Code: [Select]
1>Main.cpp(16): error C3861: 'glCreateShader': identifier not found
1>Main.cpp(18): error C3861: 'glShaderSource': identifier not found


Edit 2:
I tried to boil down my question to the essential issue, but if I should provide more information, I will gladly do so.

Edit 3: I am using SFML 2.0, linking everything statically.

7
General / Linking OpenGL to SFML projects
« on: February 13, 2012, 08:40:52 am »
I am using Visual Studio 2010 on Windows 7 Ultimate and I installed the latest snapshot of SFML 2.0 using CMake.

I did not use CMake to build the example projects, to see if I can do this myself. Pong compiles fine, but when I try building the OpenGL example, the linker complains:

1>Source.obj : error LNK2001: unresolved external symbol _gluPerspective@32
1>Source.obj : error LNK2001: unresolved external symbol _gluBuild2DMipmaps@28

Do I need to have GLUT or freeglut installed in order to use OpenGL with SFML? I was under the impression that SFML eliminate the need for those utilities. But if not, are both compatible with SFML?

8
General / SFML1.6:VS 2010, static linking, release works but not debug
« on: February 12, 2012, 02:27:49 am »
Hello,

I installed SFML to Visual Studio 2010 following the instructions here:

http://www.sfml-dev.org/tutorials/1.6/start-vc.php

I am using static linking, so I included sfml-system-s.lib in the Release configuration and sfml-system-s-d.lib in the Debug configuration. I have also defined SFML_STATIC in the preprocessor definitions for both configurations. (Not too entirely sure if this step is necessary or not)

I am pretty sure I have followed the instructions precisely and correctly, as when I copy that example program into VS2010 in the Release configuration, compile it, and run the .exe, it works fine with problems.

However, when I try the same with the Debug configuration, with everything the same except I include sfml-system-s-d.lib rather than sfml-system-s.lib, the program compiles, but the program does not run.

When clicking the little green Start Debugging button, I get this error:

http://i.imgur.com/fh16m.png

When I go to the Project location and try running the .exe from there, I get this error:

http://i.imgur.com/CwEUN.png

I solved the problem by including sfml-system-s.lib rather than sfml-system-s-d.lib for the Debug configuration as well. Then the program and .exe runs fine.

However the Getting Started - SFML and Visual Studio tutorial that I linked above states that:

Quote
Important: for the Debug configuration, you have to link with the debug versions of the libraries, which have the "-d" suffix (sfml-system-d.lib in this case). If you don't, you may get undefined behaviours and crashes.


I've only fiddled around with the debugger after including sfml-system-s.lib and seems to be working OK, but is there some other thing that I should do?

Edit: I tried using dynamic linking this time. Similar issues. I get the same error message whether running the program through VS2010's debugger, or through the .exe directly:

http://i.imgur.com/0FFVj.png

Edit 2: I am using Windows 7 Ultimate if that makes any difference. If I'm missing any other information, I will be glad to give it.

Pages: [1]