• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Catwheel

copying back buffer not working

8 posts in this topic

I'm pretty new to direct x, if you've seen my other posts, you probably know that. I'm trying to copy the middle section of the back buffer to a different surface and then copy that back to the top half of the back buffer. My plan later on is to do this twice, copying the back buffer to 2 different surfaces, then modifying those surfaces, and finally copying them back to the back buffer in a sort of splitscreen fashion (so that one surface copies to the top half of the back buffer, and the other surface copies to the bottom half of the back buffer).

 

Here's my code, which seems pretty sound to me:

        //rendering stuff
	m_lpDX->m_lpDevice->EndScene();
        IDirect3DSurface9 * frame1 = NULL;
        IDirect3DSurface9 * pBackBuffer = NULL;
        RECT r1;
        SetRect(&r1, GetHeight()/4, 0, GetWidth(), ((GetHeight()*3)/4)-1);
        
        m_lpDX->m_lpDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
        m_lpDX->m_lpDevice->CreateOffscreenPlainSurface(GetWidth(),GetHeight()/2,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&frame1,NULL);// - CAT
        D3DLOCKED_RECT frame1Lock;
        D3DLOCKED_RECT pBackBufferLock;
        frame1->LockRect(&frame1Lock,NULL,NULL);
        pBackBuffer->LockRect(&pBackBufferLock,NULL,NULL);

        m_lpDX->m_lpDevice->UpdateSurface(pBackBuffer,&r1,frame1,NULL);
        r1.top = 0;
        r1.left = 0;
        m_lpDX->m_lpDevice->UpdateSurface(frame1,&r1,pBackBuffer,NULL);
        frame1->UnlockRect();
        pBackBuffer->UnlockRect();
        frame1->Release();
        pBackBuffer->Release();

Trouble is, nothing changes. The regular back buffer still shows. Does anyone have any trouble shooting ideas?

 

0

Share this post


Link to post
Share on other sites

First: take unbird's advice. The sequence you posted could (and probably does) have several errors.

 

1. Is the format of frame1 the same as the backbuffer?

 

 

 


SetRect(&r1, GetHeight()/4, 0, GetWidth(), ((GetHeight()*3)/4)-1);

 

2. The rectangle you specify looks strange - you set the rect left x value to the GetHeight()/4, and set the right x to GetWidth()?? If GetWidth() is the width of the backbuffer, that makes the width of the surface greater than the width of the backbuffer.

 

EDIT: Review this article. In particular:

 

       The source surface must have been created with D3DPOOL_SYSTEMMEM. (i.e., in your case, both surfaces)
        The destination surface must have been created with D3DPOOL_DEFAULT. (i.e., in your case, both surfaces)
        The source and dest rects must fit within the surface.
        The source format must match the dest format.

 

 

 

I haven't worked in DX9 for a while, but I think you're going to have to try GetRenderTargetData to start with, to get the backbuffer (video memory) into system memory. Then go from there, possibly with StretchRect, likely needing 2 or 3 surfaces overall.

Edited by Buckeye
2

Share this post


Link to post
Share on other sites

OKay so let me get this straight before I get started.

The process should look like this:

		m_lpDX->m_lpDevice->EndScene();
        IDirect3DSurface9 * frame1 = NULL;
        IDirect3DSurface9 * frame2 = NULL;
        IDirect3DSurface9 * pBackBuffer = NULL;
        IDirect3DSurface9 * pActualBackBuffer = NULL;

        RECT r1;
        SetRect(&r1, 0, GetHeight()/4, GetWidth(), ((GetHeight()*3)/4));

        //get back buffer and initialize frame surfaces
        m_lpDX->m_lpDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
        m_lpDX->m_lpDevice->GetRenderTargetData(pBackBuffer,pActualBackBuffer);
        m_lpDX->m_lpDevice->CreateOffscreenPlainSurface(GetWidth(),GetHeight()/2,D3DFMT_/*format matching back buffer*/,D3DPOOL_DEFAULT,&frame1,NULL);// - CAT
        m_lpDX->m_lpDevice->CreateOffscreenPlainSurface(GetWidth(),GetHeight()/2,D3DFMT_/*format matching back buffer*/,D3DPOOL_DEFAULT,&frame2,NULL);// - CAT

//copy middle of back buffer to the two surfaces
        m_lpDX->m_lpDevice->StretchRect(pActualBackBuffer,&r1,frame1,NULL,D3DTEXF_NONE);
        m_lpDX->m_lpDevice->StretchRect(pActualBackBuffer,&r1,frame2,NULL,D3DTEXF_NONE);

//some operations would go here later to modify the surfaces for a left and right eye view

//copy frame surfaces back to the back buffer to be presented later.
        RECT d1;
        SetRect(&d1, 0, 0, GetWidth(), GetHeight()/2);
        m_lpDX->m_lpDevice->StretchRect(frame1,NULL,pActualBackBuffer,&d1,D3DTEXF_NONE);
        RECT d2;
        SetRect(&d2, 0, GetHeight()/2, GetWidth(), GetHeight());
        m_lpDX->m_lpDevice->StretchRect(frame2,NULL,pActualBackBuffer,&d2,D3DTEXF_NONE);

//release pointers
        frame1->Release();
        frame2->Release();
        pBackBuffer->Release();
        pActualBackBuffer->Release();

You'll notice that I did not check for the HResults, that is because I have a different question having to do with those before I write them in.

 

So I checked out the article that Unbird linked. I opened up the directx control panel and set it up for debug mode, however nothing came out. After googling I found that I needed to declare     #define D3D_DEBUG_INFO  so I did that, in this fashion:

//#ifdef _DEBUG
    #define D3D_DEBUG_INFO  // declare this before including d3d9.h
//#endif

#include <d3d9.h>
#include <d3dx9.h>

I'm not really sure where I'm supposed to retrieve the debug info though. Alternatively, I would settle for just being able to output some info, like with println(); but the program I am altering simply becomes a plugin for another piece of software. Therefore, i don't know where to find the output. I don't have a lot of experience with the command line, but I am wondering "Is there something there I could do?"

EDIT: This has to do with my question about HRESULT, which is essentially, "How can I make some custom text output that I can reference, while in this plugin?"

 

Lastly, I just wanted to say, I'm a senior college student with no prior graphics programming experience. Is this project too demanding for someone from my position? Further, do you have any general advice for someone in my position?

Edited by Catwheel
0

Share this post


Link to post
Share on other sites

For the sake of thoroughness, your header should have:

#if defined(DEBUG) | defined(_DEBUG)
#ifndef D3D_DEBUG_INFO
#define D3D_DEBUG_INFO
#endif

Just FYI, I don't know if the code you posted is correct or not.

 

As mentioned in unbird's referenced article, debugview may serve your purpose with regard to debug output if you're not using Visual Studio.

 

 

 


This has to do with my question about HRESULT, which is essentially, "How can I make some custom text output that I can reference, while in this plugin?"

 

If the app has a console window (which it should, if it doesn't), std::cout ( or printf() ) would work. Or launch the app from a cmd window. Otherwise, take a look at OutputDebugString(). The latter outputs c-strings, which requires you to format your output string if you want to output numbers. Again, if you're not launching it from Visual Studio, you'll have to find a debug message monitor like debugview.

 

 

 


I'm a senior college student with no prior graphics programming experience. Is this project too demanding for someone from my position? Further, do you have any general advice for someone in my position?

 

With regard to graphics programming experience - you're getting some now, huh?!

 

Too demanding? If you're not working from within Visual Studio, you may have a long row to hoe. But you seem to be willing to give things a try, and you've got gamedev. Go for it! I would suggest, however, that you read the documentation for each function you use, if you're not familiar with it and/or not positive of the input/output requirements. And you can google for example code in a lot of cases. Or, at worst, find out what won't work.

 

EDIT: an alternative, depending on how much time you have to work on your project - download Visual Studio (you can get a free version, maybe even a full-blown version being a college student). Create a version of your plugin as a standalone, test it thoroughly there and create another version as the plugin. Actually, you may save time overall by doing that. At worst, you appear to be interested in that type of programming so get into Visual Studio.

Edited by Buckeye
2

Share this post


Link to post
Share on other sites

With regard to graphics programming experience - you're getting some now, huh?!

 

I'm not exactly sure what the inflection is here. Are you saying this is too early for a programmer to learn graphics programming or too late, or are you stated that I am currently getting experience? I don't mean to sound condescending I'm just wondering what you meant and where that means I am now (I.E. ahead of the curve, behind, doesn't matter where)

 

 

EDIT: an alternative, depending on how much time you have to work on your project - download Visual Studio (you can get a free version, maybe even a full-blown version being a college student). Create a version of your plugin as a standalone, test it thoroughly there and create another version as the plugin. Actually, you may save time overall by doing that. At worst, you appear to be interested in that type of programming so get into Visual Studio.

I have been using visual c++ 2008 express edition. It was recommended by my client, because it can compile the byte code within 1KB. I do have Visual studio somewhere on this computer and I think that it is a full version (because I'm a student). I guess I should be giving that a try? I will try it.

 

 


This has to do with my question about HRESULT, which is essentially, "How can I make some custom text output that I can reference, while in this plugin?"

 

If the app has a console window (which it should, if it doesn't), std::cout ( or printf() ) would work. Or launch the app from a cmd window. Otherwise, take a look at OutputDebugString(). The latter outputs c-strings, which requires you to format your output string if you want to output numbers. Again, if you're not launching it from Visual Studio, you'll have to find a debug message monitor like debugview.

For clarity's sake let me say that back as I understood it to make sure I have it right. If I use Visual Studio it should give me a debug message monitor. How do I access this monitor? Do I need to do anything special with my .dll file? I really have no idea how to test it, except to build it and launch the main app, and then use the plugin to see what happens. An alternative quicker or more custom-message-friendly testing method would be showered with my love.

 

EDIT: What did you think of my process I outlined in my previous post? Did it look appropriate?

Edited by Catwheel
0

Share this post


Link to post
Share on other sites

are you stat[ing] that I am currently getting experience?

 

That's pretty much it. Just sayin' you've jumped into some relatively deep water and appear to still be breathing. With no programming experience, you're making some pretty good guesses in your coding. They don't work, but they're good guesses. wink.png

 

 

 


I guess I should be giving that a try? I will try it.

 

Definitely. With intellisense and on-board help (click on some word in your code and hit F1) it'll make life a bit easier. And, as suggested, you may want to write a basic DX9 engine and test your routines that way. I'm guessing you have the June 2010 SDK and you could steal a DX9 base engine from one of the examples. If you do that, the debug output goes to the Visual Studio output window automatically when you run your app from VS. With regard to other running apps, I'm afraid I don't know if VS monitors other debug output.

 

I don't know, but suspect, that debugview or the like will monitor messages to a debug output from a DLL. Also, I've never tried it, but I would think if you launch the main app from a command prompt window that std::cout << "some message\n" or printf("debug message %d", msgNum) could provide you info.

 

 

 


What did you think of my process I outlined? Did it look appropriate?

 

Without doing a lot of DX9 review and lookups of the docs, I couldn't say. As mentioned, review the docs for functions. A quick look at GetRenderTargetData indicates that what you've got won't work. You don't create the surface before you use it to receive the data. Dx9 (and 10 and 11, for that matter) have requirements for function arguments listed. Don't guess at them, read the docs. Or, as we use to say at work, RTFM!

 

Just scanning the code without looking anything up, you get the render target data (which, though you call it that, is not the "actual" backbuffer). That's just copied data. You do some manipulations with it, but nothing goes back to the backbuffer.

Edited by Buckeye
1

Share this post


Link to post
Share on other sites

You can implement split screen without doing any copying of render targets.

 

The way you to that is to use viewports - the default viewport you get when you set a render target is a full size one, but you can change that to cover a different portion of the render target to do things like split screen.

 

The main advantage of that approach is that it will perform better than copying. Especially if your copies go back and forth to system memory instead of staying on the GPU.

 

If you really need to copy bits of render target around, I'd suggest using StretchRect() with the help of GetSurfaceLevel(). That will avoid the copying to and from system memory.

1

Share this post


Link to post
Share on other sites

render targets are a prety plentyfull resources, don't play with them too bad

 

(it is a writing of gpu station, forget about storing them over cpu, issuing back driver ordered commands)

 

in stead, only thing you can do-- has to be issued to gpu toward gpu memory objects.

0

Share this post


Link to post
Share on other sites

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  
Followers 0