Thread: WM_PAINT and OpenGL

  1. #1
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195

    WM_PAINT and OpenGL

    Ever since I started using OpenGL inside my program, I started getting a ton of WM_PAINT messages. Is there a way to limit the amount of paint messages that are sent to my application? Im trying to limit the amount of CPU cycles that my application takes up and currently, its eating up a nice chunk.

    In about 5 seconds, my program recieved about 100,000 paint messages.

    Before it was only a few hundred.

    For the purpose of this project, I need to have the openGL render calls inside the message loop in the WM_PAINT portion. Im NOT going for the best fps here, only selective rendering.

    Here is my Main Loop code:

    Code:
    while (GetMessage(&uMsg, NULL, 0, 0)) 
    {
    	TranslateMessage(&uMsg);
    	DispatchMessage(&uMsg);
    }
    And then the WndProc picks up any messages.
    Last edited by Mastadex; 02-17-2006 at 02:24 PM.

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    First its not the best idea to use openGL calls in WM_PAINT messages. Second, I suggest you go to http://nehe.gamedev.net and check out his openGL tutorials to see how to write a rendering loop without relying on paint messages.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  3. #3
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    thats the thing. Im not writing a rendering engine. I actually want openGL to render when windows refreshes the window. I want as few FPS as possible. (i know how strange that sounds).

    This program is a utility, and I dont want to bogging down the CPU.

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Using WM_PAINT will bog down the CPU, if you implement the rendering sepretly it will not use the cpu (as long as you have a 3d card capable of accelerating the basic gl calls) very much at all.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  5. #5
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    well heres the thing. even tho i commented out ALL my opengl code. the app still takes up 50% of the cpu power. its recieving a TON of pain calls.

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Call ValidateRect(Window, NULL); when WM_PAINT is sent.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed