Problems in animating openGL

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!!..

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?

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

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.

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

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.

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

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:
[b]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[/b]

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?

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.

These are the basic steps for opening a window for OpenGL in the Windoze OS

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

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;

}

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.

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.

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.