Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Oct 2005
Offline Last Active Today, 07:33 AM

#4957083 Sluggish OpenGL performance using Win32

Posted by on 08 July 2012 - 06:10 PM

Just to simplify everything here is a copy of the source file in question:
[source lang="cpp"]/*** main.cpp*/# include <stdlib.h># include <time.h># include <windows.h># if defined(_WINDOWS_)# include <gl\gl.h># endif /* defined(_WINDOWS_) */LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);HDC hdc;PIXELFORMATDESCRIPTOR pfd;int format;HGLRC hglrc;/*** entry point*/int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){ WNDCLASS WndClass; HWND hWnd; MSG msg; WndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; WndClass.lpfnWndProc = WndProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = hInstance; WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hbrBackground = NULL; WndClass.lpszMenuName = NULL; WndClass.lpszClassName = "greyscale"; if(RegisterClass(&WndClass) == 0) { MessageBox(NULL, "Unable to register the window's class.", "", MB_OK | MB_ICONERROR); return 0; } hWnd = CreateWindow("greyscale", "greyscale", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 800, 600, NULL, NULL, hInstance, NULL); if(!hWnd) { MessageBox(NULL, "Failed to create window.", "", MB_OK | MB_ICONERROR); return 0; } hdc = GetDC(hWnd); ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; format = ChoosePixelFormat(hdc, &pfd); SetPixelFormat(hdc, format, &pfd); hglrc = wglCreateContext(hdc); if(!hglrc) { MessageBox(NULL, "Failed to create context for OpenGL.", "", MB_OK | MB_ICONERROR); return 0; } if(wglMakeCurrent(hdc, hglrc) == FALSE) { MessageBox(NULL, "Unable to change the current context.", "", MB_OK | MB_ICONERROR); return 0; } ReleaseDC(hWnd, hdc); ShowWindow(hWnd, nShowCmd); UpdateWindow(hWnd); glClearColor(0.0f, 1.0f, 0.0f, 0.0f); for(;;) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } glClear(GL_COLOR_BUFFER_BIT); glFlush(); } wglMakeCurrent(NULL, NULL); wglDeleteContext(hglrc); return msg.wParam;}/*** message handler*/LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { case WM_NULL: { return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } case WM_CLOSE: { if(MessageBox(hWnd, "Are you sure you want to exit?", "", MB_YESNO | MB_ICONQUESTION) == IDYES) DestroyWindow(hWnd); return 0; } } return DefWindowProc(hWnd, msg, wParam, lParam);}[/source]

This has been bugging me for a while so I thought I might as well see if it's happened to anyone else or see if someone can tell me how badly I'm going wrong.

I've finally managed to get OpenGL rendering within Win32 (and not through the other third party libraries like GLUT).

My issue though is that when I actually include rendering commands in the main loop the window appears to become unresponsive. I say appears because I can drag it around occasionally and it takes ages to respond.

The issue disappears with I remove the Clear and Flush commands in the loop.

I've added a timer (not shown above) to limit the speed at when the rendering runs and the issue then goes away. The only conclusion I can come to is that the OpenGL commands take to long and cause PeekMessage to miss messages in the queue (that was all I had, I only started Win32 yesterday so I'm probably wrong).

The code compiles correctly and produces no errors in Visual Studio. What exactly is causing this behaviour?

The big killer is this:

if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
						if(msg.message == WM_QUIT)



change that if to a while, otherwise you only process 1 window message per frame and the message queue will get flooded if you do anything that generates alot of messages (such as moving the window)

#4957041 Doubts and Motivations

Posted by on 08 July 2012 - 03:57 PM

I've definitly been there, allthough never with a game that i've spent more than a few days on, The key to avoid this kind of doubt really is to push out a prototype quickly.
If the prototype is fun you keep going, if its not fun you either start over with a new design or identify the flaws and fix them.

You shouldn't need more than a day or two to get a playable prototype for the key mechanics done (If its a complex game you can make multiple prototypes for different mechanics), Don't be afraid to use tools such as GameMaker to get the prototype(s) done.

#4956956 I can play sounds?:O

Posted by on 08 July 2012 - 10:34 AM

I can play sounds in C++? How do I go about doing that? It doesnt matter if its how to play a little beep or a whole entire song but how do you do it??

C++ doesn't support sounds, you need to use your OS API for that (or a third party API that your OS and/or drivers support)

For Windows you have some basic sound support in the Win32 API and better sound support with DirectX or OpenAL (OpenAL is also available on Mac and Linux)

#4956557 How to make a studio?

Posted by on 06 July 2012 - 08:33 PM

Can I own a game, be boss of it and it belongs to me without owning a studio? So the team members sign a contract that i own it and they are working for money only? I think it would be best to create the studio shortly before game is getting releasable. Or maybe don't need to create studio at all? but would look a bit unprofessionable maybe? What are adv to having a studio?

Yes you can, you still have to register with skatteverket though (Atleast once you start making money)

If you don't register a proper business (and only register with skatteverket) then anyone working for you will have to do the same (they'll effectivly be contractors, not employees) and it really gets kinda messy.

If you plan on having people work for you then you really should register a business to simplify things for your employees. (and get an office, they're pretty darn cheap unless you want to have it in stockholm and it is far easier to work effectivly when everyone is at the same location)

#4956484 3 different clients.. Which is father and child?

Posted by on 06 July 2012 - 03:34 PM

Head over to the multiplayer forum
There's a FAQ there you should read.

In general (since I have no idea what language, API's or tools you will be using) there will be 1 client, that's the one the user is on. he will initially connect to the login machine which houses the lobby, etc. Then, when he plays the game, the login machine will direct the client to connect to the game server.

But, you've got a long way to go before you get to that point if this is your 1st time writing network code.

Thanks, But I was wondering about those 3 different aps I mentioned..
So when I go to login screen/launcher... and should that app shut down and then the lobby launches?
And when you start a game from the lobby, The lobby runs in the background?

Should game be child to lobby?
And is lobby father to launcher or child to launcher?

Just make it one application with multiple states instead, if you have a launcher its best to keep it simple and only use it to update the actual game (it shouldn't deal with things like logging in etc, just have it check that the game is up to date and then start the game)

#4956480 How to make a studio?

Posted by on 06 July 2012 - 03:25 PM

I want to be boss of a studio that I make.
What are responsibilties of a studio boss?

And how do i make it legal?
I mean I cant just say my studio name is AWESOM STUDIO and then think I own this studio I just made up..
Do I have to register it somewhere? Is there any fees?

and when is a good time to start the studio when you are making a game?
Should I make it before i recruit someone onto a team?

IIRC you were from sweden so...


Those two links should help you, for a single owner business you don't have to register your business, you must however report to skatteverket that you have a business since you will have to pay taxes.

Other businessforms you have to register with bolagsverket and in the case of aktiebolag you have to push in 50.000 SEK in own capital aswell. (aktiebolag has some pretty big tax advantages though as money payed out to shareholders are taxed far less than salary payed out to employees)

a game studio is no different from other businesses, you run it the same way and pay salaries to your employees the same way. (If you plan on not paying people you're far better off making them co-owners of the business)

#4956108 how do i save levels in a basic platformer game using c++ and SDL?

Posted by on 05 July 2012 - 03:21 PM

If you're just starting out a plain text format will probably be the easiest to handle, just decide on a way to represent the level as text and push it to a file using ofstream.

If you want to move to a binary representation instead just change things so that you represent your level as a series of numbers instead.

#4955880 Seperating game logic from game loop?

Posted by on 05 July 2012 - 01:42 AM

On a slow PC, the game won't be able to render as fast, so since it's trying to render as fast as possible, the time taken for each frame fluctuates, even if ever so slightly, which causes the update in the game/physics step to look jumpy. So if one frame takes a few milliseconds longer, the character moves more than in the other frames and this is very noticeable.

How do other people deal with this problem?

i mentioned this in my post earlier, store two (or three can be a good idea for multithreaded engines) copies of the game state, the old state and the "current" state , then interpolate between them based on the exact time when you render (Thus you will let rendering lag slightly behind instead). (so if logic frame 2 is at 605.02 and logic frame 3 is at 605.04 and you have frame1(from 605.0 and frame2 stored), the loop comes around, you grab the current time and it says 605.035 now rather than rendering frame 2 (The last logic frame) we interpolate between frame1 and frame2 (we're 75% of the way to the next logic frame (timestep 0.02 and we've done 0.015, 0.015/0.02 = 0.75)
Thus, for linear movement we just take the positions(as vectors) in frame 1 and scale them by 0.75 and add the positions from frame2(scaled by 0.25) and voila, we get smooth movement. (For rotations its probably easiest to slerp quaternions (you could just get a library for that).

#4955808 100k, some good ideas, and a burning desire to start a game company.

Posted by on 04 July 2012 - 06:43 PM

Investors require that you inject 25% of the startup capital. So you can start with $400,000 when you show an impressive business plan.
Problem is, a game like Braid or Limbo can't be made for that little. You'll need much closer to a million, since you don't want to go for the cheaper platforms.

Not sure where you came up with a million. Braid was made for 200k.


Using my model in my original post I could make it +/- 100k. So making a game like Braid is definately doable.

The question then still remains. Is my model a good model or not? Are my numbers good or not?

There is a huge difference between playing games and designing games and an even bigger difference between designing games and producing a game, Anyone can come up with ideas for games that appear fun, most people can also get the design done reasonably well, designing fun games that can actually be produced with the talent and time available is far more difficult.

The best route when starting any business on a tight budget is to do the heavy lifting yourself, make sure you have the skills required to do so. (With a 4 person team (you + 3) and the compensation plan you suggested i would expect you to do atleast 30% of the work (Which, in a 4 person team means that you have to do alot more than just design), (if the game is a smash hit you're taking up to 70% of the net profit, and you get the money you invested in salaries back before the team gets a dime for their investment so you will have to show the investors(i'm not going to call them employees when they work for peanuts and promises) that you will deliver the goods)

#4955226 I want to be a game programmer. I have been trying for last 1 month in android.

Posted by on 03 July 2012 - 04:13 AM

I'd strongly recommend starting with Java on the PC (Win, Mac or Linux doesn't really matter) , mobile development is an unnecessary distraction that you really shouldn't worry about until you're ready.

1. Learn how to program, (in any language really)
2. Learn how to make games,
3. Learn how to make applications for <insert non desktop platform here>

#4955055 Android - Partial Transparency

Posted by on 02 July 2012 - 03:26 PM

There are a few ways you can do this.

You can first render the wall normally, then render the character without depthtesting (fairly simple but probably not quite the effect you're looking for)

you coukld also Render the wall twice, first at X% opacity without depthwrites, then render the character, then render the wall again at 100-X% opacity and additive blending.

Those two effects basically just make the character visible through the wall and might not be what you want.

You could also project the character onto the wall (in black or grey) (or the walls position rather) (towards the camera) and write that to a separate otherwise white texture, apply blur to the texture, render the character normally and finally render the wall using the greyscale characteroutline texture as the alpha channel. (There are probably faster ways to do this aswell).

Another option could be to render a scaled up version of the character to the stencil buffer and use that for a stencil test when you render the wall (works with fixed function), or render to a texture and process in the pixel shader (to get fancy edges for example), (With ES 1.1 the options are a bit limited, but with 2.0 you can do pretty much anything)

#4954845 What engine/language/platform to use?

Posted by on 02 July 2012 - 03:57 AM

there are quite a few languages that are notorious for not being able to develop with

such as?

Hello World

Good luck making something that is actually useful with it Posted Image (Its not even the worst language out there, some such as "whitespace" are even worse). (When it comes to mainstream languages however its quite hard to find one that is really awful, some are quite a bit worse than others though)

#4954842 Unreal and AI

Posted by on 02 July 2012 - 03:45 AM

Considering that:

  • "figuring out the player position" is a world data query,
  • movement to that position is somewhere between a "rotate to face" and a pathfind, and
  • "melee attack them" is an animation change based on proximity (which is also simply world data),
I'm going to say that your requirements list is likely satisfied in any engine.

Since you seem a bit new (I might be wrong), you might want to consider simply going with Unity instead like all the cool kids are doing these days (including me for many things).

I would try Unity but everything i have seen of it just looks too cartoony. i like the real look you get from unreal and cryengine

The look of the final product has nothing to do with the engine really, (some effects might be easier to create in some engines than in others though), The main reason alot of Unity games look "bad" is that they use the free version (Which doesn't support dynamic shadows or render to texture, thus preventing some effects from being used) and are using amateur artists(Who don't produce the high quality assets you need for a good looking game) professional games made with Unity can look really impressive (These are harder to identify though as the pro version allows you to remove the Unity splashscreen making it virtually impossible for the end user to identify the engine used)

#4954788 Viability of GLUT in commercial products

Posted by on 01 July 2012 - 11:48 PM

I wanted to know if it was a good idea to use freeGlut in a commercial quality product or if I should go with something like SFML or SDL.
Any explanation would also be nice.


If it works for you then its fine to use commercially as well, it is however worth remembering that glut was only intended as a support library for the OpenGL Redbook examples, it lacks alot of things that you will need in a game (sound, proper input, etc). and it does steal your mainloop which gets quite annoying after a while. (You can solve sound and input using additional libraries such as OpenAL)

#4954506 How many average number of threads does a game needs, regardless of simplicity?

Posted by on 01 July 2012 - 05:48 AM

If a basic game requires to be able to do multitasking stuff, how many threads does a game requires? Thanks in advance.

You only need 1 thread (computers are fast and multiple tasks executed after eachother will appear to run at the same time (The vast majority of games on the market are singlethreaded)).

I'd strongly recommend against writing multithreaded code if you are just starting out, it adds quite a bit of complexity.

If you are going to go the multithreaded route anyway i'd recommend looking at thread pools, don't split the game in one physics, one ai, one renderer thread etc (it doesn't help much at all), instead split for example the AI into multiple smaller units that can be processed independently and have a pool of worker threads that processes these work units for you(You can vary the number of worker threads based on the hardware it runs on more easily aswell). (a semi functional approach to your state updates will make it easier to avoid excessive synchronization (just write to an old state object/structure rather than returning a new one to avoid unnecessary allocations).