Archived

This topic is now archived and is closed to further replies.

Where must i put the Render() funtion?

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

Recommended Posts

In the main program... where i must put the Render() function? in the WM_PAINT section? in the Message loop? where?

Share on other sites
somewhere...in the middle....or...yea, in the middle, y''know?

Share on other sites
LOL...

you could put the render function in the wm_paint section and call it from there, or set up a timer and call it in the wm_timer, or call it up in the peek message/translate message thing, again using a custom timer/function call.

kind of paracoded below, the if peek might need to be while peek..

while(1) {
qtimer = diffTime; (current_time - last time called)
if (peekmessage(..)) {
"" ""
"" ""
else
if qtimer>==n_intervals (interval you want render to be called at)
Render();
}
}
return 0;
}

hope that helps..

I fseek, therefore I fam.

Share on other sites
i had trouble with WM_PAINT, but WM_ERASEBCKGND worked perfectly, like WM_PAINT is supposed to i think.

Share on other sites
i did This... is it correct???

while(msg.message != WM_QUIT)
{
bGotMessage = PeekMessage(&msg,NULL,0U,0U,PM_REMOVE);
if(bGotMessage)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
Render();
}
else
{
Render();
}
}

Share on other sites
you are calling Render() twice..

    /* Run the message loop. It will run until GetMessage() returns 0 */    while (bRun) {     if (PeekMessage (&messages, NULL, 0, 0, PM_REMOVE))     {        if (messages.message == WM_QUIT)  break;        /* Translate virtual-key messages into character messages */        TranslateMessage(&messages);        /* Send message to WindowProcedure */        DispatchMessage(&messages);     }     else     { while (!list.event());                Render();               }    }    COMMAND.CleanUp();    /* The program return-value is 0 - The value that PostQuitMessage() gave */    return messages.wParam;}

list.event() loops until timer interval is met

Share on other sites
it renders also when i have an input... is that bad?

Whend i tried to use the WM_PAIN it works only when i resize the window or i move it, when the window is stopped it doesn''t go to the WM_PAIN section

Share on other sites
You could also try

InvalidateRect(hwnd, NULL, NULL)

which will tell your window to invalidate itself, and will have windows schedule a WM_PAINT message in your queue, then you can render within the WM_PAINT handler. You call InvalidateRect whenever something will change on your screen. (For instance in your WM_CHAR handler, or maybe when some timer fires).

Share on other sites
Can you make me an example of the WinMain and MsgProg functions?

Share on other sites
The SDK has many code examples, maybe you should check them out.

Share on other sites
Yes that's right, SDK samples/tutorials are the best way to
start. But just in case you want it, I'm showin' you some of
the stuff I do in my loop after creatin' a window for renderin':
(Note that this, however, is a very simplified way of doin' it,
there are still things like check for device lost in between.
Check CD3DApplication::Run() for more sophisticated way of
doin' things)

while(TRUE){    bGotMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);	// Error condition.	if(bGotMessage == -1)		break;    if(bGotMessage != FALSE)    {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    else        Render();}

That's to say, when there's any message in the message queue,
it's best to give them a chance to get processed. If there
isn't any message to be processed, then carry on with the
renderin' by callin' Render().

For the WM_PAINT part... I think it's comparatively lower
priority message in Windows, so it's likely to get sent down to
your application slower even if it's in the queue. So don't do
it there.

[edited by - HaywireGuy on June 5, 2003 1:36:50 PM]

Thank you a lot.

• Forum Statistics

• Total Topics
628767
• Total Posts
2984590

• 13
• 10
• 25
• 12
• 9