Thread: opengl and networking on win32

  1. #1
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246

    opengl and networking on win32

    I'm making a OpenGL game and i want to add some networking code to it. For example i have a rotating cube. if i block in read() it cannot rotate, right? So how can i have my app talking over the net and drawing GL at the same time?
    :wq

  2. #2
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    ohh, and another quick question. If i add a menu (but no net code) will my app freeze when i click a menu item?
    :wq

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Well, first off you must understand that you cannot have your application communicating on the network and drawing at exactly the same time. It's virtually the same time, and there will most likely be some hiccups.

    Second of all, there are some functions that will assist you in pushing your drawing routine down the graphics pipeline faster (since you're depending on a socket here). If I remember correctly, one of them is glFlush().

    Needless to say, all of this depends on your network code. If you code it right, everything should work just fine (even if you don't use glFlush or similar functions to stop the wait time). So unless I can see some code...I can't determine why your GL routine isn't drawing.

    As for your menu question, most likely your GL drawing routine will freeze up when it recieves that message (since it will be stuck looping through that menu code). That's how all of my apps have been like. However, there are probably ways for you to counter this effect. How to do it though...I'm not entirely sure. I've always just created my own UI that I render with OpenGL ontop of the rest of my rendering routine. Creating your own menus can counteract the issue of your menus freezing up your rendering routine.
    Last edited by Tronic; 01-10-2006 at 12:54 PM.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  4. #4
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    Hi and thanks for the reply.
    Well, the networking code is ok i think, but from what i understand everything will heavily depend on how fast the reply from the server comes in. If there's no data, i'm blocked in read() and the loop with drawing doesn't spin. I've just remembered there's a net function select() which has a timeout, i suppose i can use that. i'll also look up glFlush() and see if i can use it.
    About the menu...Making my own would be quite difficult especially since i'm new to GL, so using win32 menu wold be better for me i think.
    :wq

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Ahh, then I strongly suggest sticking to Win32 menus until the remainder of your OpenGL knowledge (Until you get to things like double buffers, transparency and possibly tesselation).

    As for the timeout issue, yeah that's always a problem. There's a couple of options you could do here, and I think the first is the best and most common: 1) Let the animation pause until the function recieves the data off of the network. 2) Continue the motion of your triangle while you wait for the function to recieve the data off of the network.

    The second option is of course a little bit more tricky, but if the movement is predictable enough, then you can get away with this fairly easily. Depending on your expected network load though, this might be a very worthwhile option to investigate. It sort of..tricks the user into thinking nothing is lagging for a short time.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    from what i understand everything will heavily depend on how fast the reply from the server comes in. If there's no data, i'm blocked in read()
    You can use select() as you mentioned, another thread, or use asychronous sockets. With async sockets, you will receive a message when there is data to be read. This way you never have to block. If I remember correctly, just make a call to WSAAsyncSelect to make your socket asynchronous.

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    WSAAsyncSelect() sounds right. I'm not completely sure though x.x. I'm actually just starting to use Windows Sockets myself. I found a really good tutorial if anyone wants it. Beej's guide annoyed me to no end x.x.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  8. #8
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    yeah, i'm new to winsock myself, but not bsd sockets.
    As i remember select() can have a timeout and if it's 0, it just checks if there's data to be read and if not it doesn't block. I dont' know what WSAAsyncSelect() does though, i'll look it up
    :wq

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New in Networking (Chess?)
    By m3rk in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2009, 10:02 AM