Jump to content
  • Advertisement
Sign in to follow this  
Andy1979

GDI Programming problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writing a program using GDI (not GDI+) to simulate a human model walking / running accross the screen. To avoid the window locking up while moving the human model I have used threads which does solve the problem of the screen locking up. However it seems to prevent anything from being displayed whilst running a model update function within a thread by using InvalidateRect. Without InvalidateRect I get trails when the model is moved. See code fragment below: DWORD WINAPI StartThread1(LPVOID iValue) { for(i = 0; i != 10; i++) { DrawHumanModel(); BodyPoint[0]++; BodyPoint[2]++; InvalidateRect(mainWindow, &rec1, TRUE); Sleep(60); } return 0; } I've only put the for loop in as a temp measure until problem is fixed. Please replay with any suggestions or tips please. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
And what about trying UpdateWindow instead of InvalidateRect ?

Share this post


Link to post
Share on other sites
No, that's not what LessBread is saying. He's saying instead of drawing directly to the screen draw to a an offscreen bitmap instead. Then whenever you complete a frame just blt the offscreen bitmap to the screen. You can still use GDI for everything.

It's probably the threading that's causing you problems. Having multiple threads touching a window (or any thread but the one that created it really) tends to get you into problems. By doing everything offscreen those problems go away. Look up CreateCompatibleDC and CreateCompatibleBitmap for info about creating the offscreen stuff.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
It's probably the threading that's causing you problems. Having multiple threads touching a window (or any thread but the one that created it really) tends to get you into problems.


Not to mention putting that touch into a for loop ...

Share this post


Link to post
Share on other sites
Hi

I'm not using bitmaps in my program. I'm just using simple GDI calls like MoveToEx and LineTo to draw a human model and just using an array to store the points for the human model. To make the human model walk I'm just incrementing certain values - e.g BodyPoint[0]++, BodyPoint[2]++, etc..

I've gone back to the original program where I have not used threads and no trails are left but I still have the original problem of the screen locking up until the condition is TRUE for the human model to stop moving.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!