PDA

View Full Version : Problems in animating openGL



Goldie
01-24-2005, 01:52 PM
Hi,

I am writing an openGL program where I have created 25-30 objects that are randomly moving on the screen. My problem is that after the objects move for sometime, the screen goes haywire. I think my program is affecting the graphics card. Lines appear on the screen of different colors (mainly green) and the whole display of my computer goes crazy. This does not stop even after I close my program. To get my screen to normal, I have to restart the computer.

Please help!!..

dvm
01-24-2005, 06:04 PM
Wow really strange behavior. Maybe a memory leak or something? Also try checking out if every glPush(something) has a corresponding glPop. But making the whole os go crazy?

MMMovania
01-24-2005, 07:39 PM
Hello there,
If you are using double buffering, then see that the swapping of the buffers is ok. Also do check out that you release the DC and RC before you exit from the program. Thanx

01-25-2005, 01:30 AM
Is it limited to your application or does this occur with other OpenGL applications, too?

In the first case fix your app or try updating the drivers.

If this happens with any heavy 3D application (also after updating drivers) this sounds more like a hardware issue.
- Check the temperature of the graphics chip, if your display control panel offers such.
- Try if it works better with an opened computer case.
- Check the graphics chip cooling fan.
- Check if all power inlets are correctly attached.
- If your graphics is overclocked, downclock it.
- If this is a laptop, increase the cooling settings.

If nothing helps, go to your dealer for a replacement.

Goldie
01-25-2005, 07:47 AM
Hi,

I havent released anything before exiting my program. What is RC and DC?? Could you please tell me how I can release RC and DC??

Thanks a million...


Originally posted by MMMovania:
Hello there,
If you are using double buffering, then see that the swapping of the buffers is ok. Also do check out that you release the DC and RC before you exit from the program. Thanx

Aeluned
01-25-2005, 09:58 AM
these are your Device and Rendering Contexts.

The OS should automatically trash them for you when your app ends. So I'm willing to bet that that's not what's responsible for your crazy video output problem. It's good practice to delete them when you're done with them though.

If, however you are attempting to acquire a new DC each frame, then you had better be deleting at the end of the draw frame, otherwise you're chewing up memory fast...again, eventually you'd just run out of heap space and your app would crash.

Blub may be onto something, sounds like some funky hardware going on.

MMMovania
01-25-2005, 04:51 PM
Hello there,
As for the releasing of DC (Device Context) and RC (Resource Context). Do following.
1) Set the current rendering context to null by calling wglMakeCurrent(hDC,NULL);
2) Make a call to wglDeleteContext(hRC);
3) Make a call to ReleaseDC(hDC);
Thats about it. I hope this will solve your problem.Thanx

Goldie
02-09-2005, 10:07 AM
Hi,

Thanks for the advice. I have another question though. What if my program is running without a RC or DC? I have not previously declared or used RC or DC anywhere in my program.

Goldie..


Originally posted by MMMovania:
Hello there,
As for the releasing of DC (Device Context) and RC (Resource Context). Do following.
1) Set the current rendering context to null by calling wglMakeCurrent(hDC,NULL);
2) Make a call to wglDeleteContext(hRC);
3) Make a call to ReleaseDC(hDC);
Thats about it. I hope this will solve your problem.Thanx

MMMovania
02-10-2005, 05:13 AM
Hello there,
Well you can't draw anything unless you have the device and resource contexts. Think of them as canvases on which you do your drawing. So if you don't have anything to draw on how would you draw?

02-10-2005, 09:51 AM
How can you see your objects for some time then, without a DC or RC.

Check WM_CREATE in your event driven WndProc function. They're probably initialized and made current there.

But, delete them on the way out also.

You might want to look at Nehe's lesson number one
to get an idea on openeing a window for GL.

Then , after you understand how it's done you can experiment with your own App.

02-10-2005, 09:58 AM
These are the basic steps for opening a window for OpenGL in the Windoze OS

0. Declare variables
1. Create and register the window class
2. Switch resolution if FULLSCREEN flag is used
3. Create the window (WM_CREATE message occurs at this point)
4. Get window device context
5. Select pixel format description
6. Create the OpenGL rendering context
7. Make the OpenGL rendering context current rc
8. Call Resize to initialize the view and perspective
9. Call InitOpenGL to initialize rendering style and misc. stuff
10. Show the window
11. Enter the main message loop
12. Render a frame
13. Swap video buffers
14. See if a WM_SIZE message is received (the window has been resized), if so call Resize.

Goldie
02-10-2005, 02:12 PM
Hi,

Ok. Here is my main function. I really do not see RC or DC anywhere here.

The animation works, but I am not doing anything fancy. I am just incrementing/decrementing the coods of the objects I am drawing in the scene, I have put this in the idle function, so everytime the scene refreshes it places the object in the new positions and this is giving the illusion of movement.

So what should I do now? How do I get RC and DC?

Thanks.

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize(WINDOW_WIDTH,WINDOW_HEIGHT);
glutInitWindowPosition(100,0);
glutCreateWindow("Experiment");

//initialize program variables.nothing to do with opengl.
init_variables();

glutDisplayFunc(display_scene);
// glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard_movement);
glutMouseFunc(mouse_movement);
glutIdleFunc(NULL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glutMainLoop();

return 0;
}

02-10-2005, 04:30 PM
Okay, I see now. Your'e using GLUT, which is a third party interface to OpenGL. It should take care of window opening, ect. for you.

MMMovania
02-10-2005, 09:38 PM
Yeah if you are using glut or any such library, the device context and resource context handling is done by the library itself. You don't have to work with these yourself.
As far as your code goes, there is one thing missing, you have not specified the idle function where as you say you are changing variable values in it. In the code, you have passed null to the glutIdleFunc. Rectify this by providing the function name to glutIdleFunc(yourIdleFuncName) and see if you still get errors.

Goldie
02-11-2005, 09:16 AM
Hi,

Well I set idle function to NULL there 'cause I want to trigger it only on some key stroke. So later on I do specify the idle function.

So now that I am using glut, I dont need to worry about RC or DC right?

Also I was using an ATI Radeon 7500 64MB card so far, now I am using an ATI Radeon 9550 256MB card, and the problem is no longer there. Do you think this might have been the problem all along?

Thanks a lot for your help.


Originally posted by MMMovania:
Yeah if you are using glut or any such library, the device context and resource context handling is done by the library itself. You don't have to work with these yourself.
As far as your code goes, there is one thing missing, you have not specified the idle function where as you say you are changing variable values in it. In the code, you have passed null to the glutIdleFunc. Rectify this by providing the function name to glutIdleFunc(yourIdleFuncName) and see if you still get errors.