Sign in to follow this  

Some ideas about page flipping?

This topic is 1116 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 have searched and cant really find anything about page flipping. I have over 100 images that make a animation and I want to put it on a cube playing frame by frame. What are the steps of doing this? What apis of directx 11? I put the pictures in a atlas to. This can be done in the shader right?

Edited by terryeverlast

Share this post


Link to post
Share on other sites

"Page flipping" is done using the IDXGISwapChain function Present. The Present call displays the newly rendered backbuffer to the window client area, that backbuffer becomes the "front" buffer, and the previous "front" buffer becomes the backbuffer to be rendered to next.

 

Assuming by "cube," you intend to do this in 3D (versus 2D), the cube could be comprised of a vertex buffer of vertices comprised of positions and texture coordinates for frame 1 of the atlas. The texture coordinates would be changed in the shader to animate the texture.

 

A simple approach (there are more complex ways) would be to create your texture atlas offline in Photoshop, Gimp or similar image editor, as a "long" texture the height of a single image, copying/pasting your images sequentially side-by-side. In your app, create a ID3D11Texture2D object, load the texture atlas image data into it, and create a shader resource view with the texture (to be bound as a shader resource.)

 

Animating the texture can be done several ways, one of which is simply pass a time value (in seconds) to the shader which renders the cube, perhaps in a cbuffer, and calculate the appropriate texture coordinates offsets for sampling the texture based on that time value and the input tex coords. E.g., for a 100 image atlas, to be animated at 1 frame per second, truncate the time value to an integer (say intTime), and add 0.01 * intTime to each tex coord x value. If you use a wrap sampler, the animation will loop.

 

If you're not familiar with it, you may want to look into the DirectX Toolkit for handy helper functions to create an ID3D11Texture2D and load a DDS or WIC (png, jpg, etc.) texture (given a filename) in one call.

 

EDIT: Particularly if you're new to texturing, this process provides you with a simple approach to learning the various interfaces and processes for rendering textured objects.

Edited by Buckeye

Share this post


Link to post
Share on other sites

For the vertex shader I got this part of the code

vout.Tex = float2((vin.Tex.x*0.10)+0.10*tframe,vin.Tex.y); // 0.10 is one image of 10 of the texel ..and tframe is the time function below
return vout;


//and the time function in the main part of the code
float t_base = 0.0f;


if( (mTimer.TotalTime() - t_base) >= 0.05f )
{
t_base += 0.05f;

timetime = timetime + 1;
if(timetime >= 10) 
{
timetime = 0;
}


}

timetime is sent to a cbuffer in the .fx file

 

I know I said I had over 100 image..which it should be .01..but I just put 10 together in the texel
 

Edited by terryeverlast

Share this post


Link to post
Share on other sites

This topic is 1116 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this