Jump to content
  • Advertisement
Sign in to follow this  
Apu

OpenGL How do I use OpenGL without a window?

This topic is 4809 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, is it possible to use OpenGL without having a window to draw into? The reason I need this: For my first attempt with OpenGL, I made a 3D game. It's working rather nicely. Now I want to make it Multiplayer (network) capable. For this, I programmed a server application. (The game connects as a client and draws the 3D). The server performs the same 3D calculations as the client, to keep track of 3D objects (for collision detection, etc.). But it doesn't need a window! I just like to use stuff like glRotate in the server, to obtain transformation matrices. But i don't need it to draw. However, glRotate doesn't seem to be working, without properly initialising OpenGL first, with an hDC and hRC and so on... Any help on this? thanks, Apu

Share this post


Link to post
Share on other sites
Advertisement
You can't use any OpenGL procedures until you have a valid rendering context--which means you'll have to have a correctly setup window and OpenGL context.

Share this post


Link to post
Share on other sites
why would you want all of the rotations done on the server? all you really need to do is send the position and rotation to the clients. the client should do all of the translations and rotations

Share this post


Link to post
Share on other sites
that's what I am doing! The reasons why I still need some rotations on the server:

(1) I prefer to do collision detection on the server. Otherwise, it would be hard to decide which collision should be checked by which client. Plus, due to network lag, one client could detect a collision when another doesn't. For collision detection, I need to have each object's modelview matrix. Therefore I need OpenGL functions.
(2) I have some models that are controlled by the computer. This computer should be the server (otherwise which client should be picked to do this?). When a model moves along a curve path, I do glRotate to compute the path. (This has nothing to do with actually DRAWING the model.)

Share this post


Link to post
Share on other sites
that's right, you can use a matrix class made by yourself. Or you can make a window on server, get all the stuff (in fact, you can even draw in a button, which is a window too) you need to setup opengl, then hide the window. But the computations will still be there.

Share this post


Link to post
Share on other sites
... or let the window show, and don't do any framebuffer operations....

I think it's better that you use the GL functions and not your own, perhaps some of the GL calls can use hardware for computations.

Share this post


Link to post
Share on other sites
Okay, I also like the GL functions better: If I used my own matrix class, I would have to do extensive changes to the server's code. With OpenGL, I can just re-use the client code for the server.

Now, here is the function that I use to init OpenGL on the client. I copied it from somewhere. I don't understand some of the settings.
Can someone please tell me how much of this is needed on the server, to create a minimalistic window? To barely support OpenGL, though I will never do any framebuffer ops at all? i want it to take as few resources as possible.


void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;

/* get the device context (DC) */
*hDC = GetDC (hWnd);

/* set the pixel format for the DC */
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);

/* create and enable the render context (RC) */
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}



Also: Is there a disadvantage involved if I run server and client on the same machine? I mean... does the graphics hardware (or OpenGL) become slower only because I have two OpenGL windows set up (even if one doesn't display anything) ?

Share this post


Link to post
Share on other sites
I'd say you should just use an OpenGL library so you don't have to mess with all that Windows API. I'd suggest GLFW. That way you can easily, not to mention cleanly perform all of the stuff you are needing to do. Take a look at this page for a example of a complete program. It will be a lot easier for you to work with as well as understand, since all the underlying details are already taken care of. The license is zlib, so you have nothing to worry about when using it out of the box.

Quote:
Also: Is there a disadvantage involved if I run server and client on the same machine? I mean... does the graphics hardware (or OpenGL) become slower only because I have two OpenGL windows set up (even if one doesn't display anything) ?


Of course! Just in general, the more you run on the computer, the less performance you will be getting out of each program. It's not the fact that you are just running a client/server, it's just more resources are being used by the computer. For example, if you restart your computer and run your client, I bet it will have a higher framerate then after you have used your computer for a full day and are running several programs at once. However, for the most part, you should not see any program threating problems by running the client and server, just a few insignificant performance hits. Now if you ran a server and multiple clients on the same computer, then you might run into some troubles...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!