Jump to content
  • Advertisement
Sign in to follow this  
mayonaise

help getting started, bitmap animation

This topic is 5450 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'm a total beginner to DirectX programming, AND windows programming in general, so bear with me. I just graduated from college, where I didn't write a single line of windows code (MFC, stuff like that). The stuff's pretty confusing... All i'm trying to do is write a simple directx program that will display two bitmaps - background and foreground. The foreground moves accross the screen while the background is stationary. I've found some decent examples and gotten it to work in concept, but I'm not sure of if i'm doing it right. In particular, I used this example - I added another bitmap and made it scroll instead of animate like a sprite (easy enough): http://www.codeproject.com/directx/basicdd.asp?df=100&forumid=4011&exp=0&select=595354 The software is being written to test some graphics hardware a friend of mine is working on. The program needs to test whether or not the hardware is accurately refreshing at 60 frames per second. So first of all I need to lock the framerate at 60 FPS. Second, I'm not sure if the way this sample program is coded will work for this setup. I think I'm creating two surfaces, one for each bitmap, and re-drawing them every time the foreground moves. Can anyone help me figure this out? I did a search and found some code to lock the framerate, but how do I know it's doing what I want it to? I can post the entire project (visual studio .NET 2003 project) zipped up if you would like. thanks!

Share this post


Link to post
Share on other sites
Advertisement
here's the function that does the animation and drawing. it's called from inside a while(TRUE) loop that loops forever until a quit message is received. Draw() is a function of the class cSurface supplied in the demo link i posted in my first post. it calls BltFast(). foreground and background are cSurface objects.

based on this code, should my program be scrolling the image at the proper frame rate?



#define FPS 60
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600

cSurface foreground;
cSurface background;

int fgWidth = 400;
int fgHeight = 400;

void ProcessIdle()
{
HRESULT hRet;
static int iLastBlit;
static int xPos = 0;
static int tick = GetTickCount();
static int increment = 10;

if(GetTickCount() - iLastBlit < FPS / 1000)
{
return;
}

if (GetTickCount() - tick > FPS / 1000)
{
tick = GetTickCount();
background.Draw(g_pDDSBack, 0, 0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
foreground.Draw(g_pDDSBack, xPos, 10, 0, 0, fgWidth, fgHeight);
if (xPos + increment + fgWidth > SCREEN_WIDTH || xPos + increment < 0)
{
increment = 0 - increment;
}

xPos += increment;
}

while( 1 )
{
hRet = g_pDDSFront->Flip(NULL, 0 );
if( hRet == DD_OK )
{
break;
}
if( hRet == DDERR_SURFACELOST )
{
g_pDDSFront->Restore();
}
if( hRet != DDERR_WASSTILLDRAWING )
{
break;
}
}

iLastBlit = GetTickCount();
}

Share this post


Link to post
Share on other sites
Without looking at your code, and from what I know, you can just do time requsts of the system to make sure no more than 60 frames are drawn per second (ie: If you've drawn 60frames, and its only taken 0.9 seconds, you can just drop into a loop that does nothing for 0.01 seconds until the full second is up, then once thats the case, jump back into your main loop). Fames per second is just (correct me if I'm wrong) how many times the main game loop is excecuted per second. You could just have a counter that is augmented ever gameloop iteration, check against the time for excecution, then just printed out. Does that make sense? Or am I completly missing your question?

Sigma

[edit]
Just looked at your code, and I *think* thats what your doing, but i'm crap at looking at other peoples code. Hell, I have a hard time figuring out what my code does!

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!