flat assembler
Message board for the users of flat assembler.

Index > Windows > So... how does ValidateRect/InvalidateRect work, exactly?

Author
Thread Post new topic Reply to topic
Fred



Joined: 22 Oct 2010
Posts: 39
Fred 01 Sep 2013, 16:40
I obviously have no idea how these two works... haha!
When I have filled my rendering buffer with pixel data, I invoke InvalidateRect so a WM_PAINT gets run. In there I do some openGL stuff, swapbuffers, and invoke ValidateRect. Now by doing this, I do indeed get expected output in my window. However... every *other* program that is running starts to flicker violently. For the longest time I've let it be because I could never find anything that made a difference. On a whim today, I replaced InvalidateRect with ValidateRect, and voila! Still getting to WM_PAINT and no more flickering!

How does this work? I have a very bad grasp of how WM_PAINT and the likes work, if you couldn't tell already, haha. Does ValidateRect queue up a WM_PAINT?
Post 01 Sep 2013, 16:40
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 01 Sep 2013, 17:08
InvalidateRect tells the window that a region must be redrawn (schedule a WM_PAINT), while ValidateRect tells the window that a region must not be redrawn (de-schedule a WM_PAINT, regardless of whether it was drawn or not).

It sounds like your call to InvalidateRect is forcing a window redraw when it is not needed - in fact I believe this probably conflicts with normal openGL drawing loop. [The only openGL code I have shows a thread doing "while (1) { /*draw objects here*/ glFlush(); /* event handling code */ }" without any mention of window messages.]
Post 01 Sep 2013, 17:08
View user's profile Send private message Reply with quote
Fred



Joined: 22 Oct 2010
Posts: 39
Fred 01 Sep 2013, 18:20
Hmm, not quite sure what this means. I shouldn't be using InvalidateRect? Do my GL stuff outside of WM_PAINT, somehow get there and only swapbuffers in there? Invalidate after the openGL stuff? I've tried to move the GL code i have in the WM_PAINT (glClear, glTexSubImage2D, glVertexPointer, glTexCoordPointer, glDrawArrays) to where my InvalidateRect is, but that just crashes the program.

But yes - "It sounds like your call to InvalidateRect is forcing a window redraw when it is not needed" is probably what happens... maybe™.


Edit: I'm trying to read up on the subject, and the openGL wiki suggests to not use WM_PAINT. I guess I shall figure out how this works.
Post 01 Sep 2013, 18:20
View user's profile Send private message Reply with quote
Fred



Joined: 22 Oct 2010
Posts: 39
Fred 04 Sep 2013, 12:13
Looked over NeHe's openGL tutorials and a openGL fps example written by someone here on the forums (forgot who), and it seems to work pretty good so far. It crashes on exit, but that's probably me doing something stupid.

I moved all openGL invokes to right before InvalidateRect in my main loop, and only did ValidateRect in WM_PAINT. I also skipped WM_CREATE, but dunno how much that matters.
Post 04 Sep 2013, 12:13
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 04 Sep 2013, 13:30
BitRake made the fps demo Smile

BitRake: have you finally used a sphere for the sky box or is it still a cube?
Post 04 Sep 2013, 13:30
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4046
Location: vpcmpistri
bitRAKE 04 Sep 2013, 14:40
Post 04 Sep 2013, 14:40
View user's profile Send private message Visit poster's website Reply with quote
Fred



Joined: 22 Oct 2010
Posts: 39
Fred 05 Sep 2013, 07:50
Yeah, that's it. Good guy bitshifter!

I noticed now that the call to InvalidateRect was unnecessary, btw. Now that all that works, I'm going to see if I can get this VBO thing to work. The wglGetProcAddress in this one is strong.

Edit: It lives! (the window title is wrong by now, didn't bother to fix)
Image
Post 05 Sep 2013, 07:50
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.