• 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
noatom

Render directx in only a portion of a window

11 posts in this topic

So if I want to make a windowed app that has directx in a portion of it, how would I do that? Usually directx just takes the whole window.

0

Share this post


Link to post
Share on other sites

In OpenGL, it is done with glViewport.  Searching the net, I see that DirectX equivalent is SetViewport.

2

Share this post


Link to post
Share on other sites

Your best results will be to render to the full buffer and set a rectangular area of the client window in the Present function.

RECT vRect;
GetClientRect(hwnd,&vRect);

... render your scene up to device->EndScene();
// present the buffer to the upper right corner of the window
RECT pRect;
pRect.left = vRect.right/2;
pRect.right = vRect.right;
pRect.top = 0;
pRect.bottom = vRect.bottom/2;
device->Present(0,&pRect, 0, 0);

Be sure to present the buffer with the same aspect ratio of the buffer, otherwise the presentation will be stretched or squashed.

Edited by Buckeye
1

Share this post


Link to post
Share on other sites

Actually, andur's suggestion will probably work better for you. Just create a child window of the main window. You can resize and position the child wherever you'd like within the client area. Build the viewport and projection matrix using the child's client size and aspect ratio. In the render routine:

RECT cRect;
GetClientRect(hChildWindow,&cRect);

... do your rendering

device->Present( &cRect, &cRect, hChildWindow, 0 ); // assumes viewport set to child client size
Edited by Buckeye
0

Share this post


Link to post
Share on other sites

but isn't there any way to set the backbuffer height and width? i tried setting them but they just occupy the whole window. And without manually setting them, my aspect ratio will be hard to estimate.

 

 

EDIT: Just used a viewport.

Edited by noatom
0

Share this post


Link to post
Share on other sites

without manually setting them, my aspect ratio will be hard to estimate

As long as the backbuffer width/height is larger than the child window's client width/height you'll be fine. Just don't render to the entire backbuffer.

 

They are a couple approaches but the simplest would be:

Get the child's client rect.

 

RECT cRect;

GetClientRect(hChildWnd,&cRect);

 

Set the viewport to the child's rect size. // sets the portion of the backbuffer to render to.

 

Set the view to whatever you want.

 

Set the projection with the aspect ratio of the child. aspect = (float)cRect.width/(float)cRect.height.

 

Draw the scene

 

device->Present( &cRect, &cRect, hChildWnd, 0 ); // present the cRect area of the backbuffer to the cRect area of the child window

 

EDIT: Yes, setting the viewport properly is the key.

Edited by Buckeye
0

Share this post


Link to post
Share on other sites

Reading the other comments here, I will retract my answer, assuming you won't be rendering in the other parts of the screen as well - then it stands.  In retrospect, it seem the solution you are seeking is the answer given by andur.

0

Share this post


Link to post
Share on other sites
D3DVIEWPORT9 Viewport;
 
Viewport.X = 0;
Viewport.Y = 0;
Viewport.Width  = 200;
Viewport.Height = 200;
Viewport.MinZ   = 0.0f;
Viewport.MaxZ   = 1.0f;
 
d3ddev->SetViewport(&Viewport);
0

Share this post


Link to post
Share on other sites

Yea apparently using a viewport won't work since the backbuffer will still be created by default to fill the entire window. You simply cannot specify a custom buffer size. So,by using a viewport you will have all the space that is nonrendered black, and if you decide to put buttons or other controls in that space, there will be problems with rendering.

 

The only solution is to actually render in a control like a tab.

1

Share this post


Link to post
Share on other sites

Yea apparently using a viewport won't work since the backbuffer will still be created by default to fill the entire window. You simply cannot specify a custom buffer size. So,by using a viewport you will have all the space that is nonrendered black, and if you decide to put buttons or other controls in that space, there will be problems with rendering.

 

The only solution is to actually render in a control like a tab.

Not true at all.

the backbuffer will still be created by default to fill the entire window

It may be the size of the client area, but it doesn't have to fill it.

by using a viewport you will have all the space that is nonrendered black

Irrelevant. Don't present the non-rendered area.

if you decide to put buttons or other controls in that space

Just for clarity, child windows aren't put in the backbuffer. They're drawn to the client area.

 

EDIT: Now you've got me confused. The first rectangle in the Present parameter is set the same as the viewport rectangle. See the correction below.

 

Keep the backbuffer the size of the mainwindow's client area (the default) and set the viewport to the size of the rendering area desired (the size you want to appear in the client area.) For the Present call, set the first rectangle (source rect) to [0 <--EDIT: no] same rectangle as the viewport to present only the viewport area. Set the second rectangle parameter (destination rect) to the position and size in the client area where you want the scene to appear, e.g., the source rectangle with an offset relative to the client area.

 

Note: you can't use the DirectX presentation area in the client for anything else, but the rest of the client is yours to use.

 

client_area_text.png

 

EDIT2: If you want to use the entire backbuffer for rendering, you can also do that. Use the default viewport or set the viewport to the backbuffer size. Set the first Present parameter to 0 (present the entire backbuffer) and the second parameter as mentioned above. The entire backbuffer image will be resized (resampled, probably to your disliking) to the destination rectangle.

Edited by Buckeye
1

Share this post


Link to post
Share on other sites

@Buckeye well thanks,however right now I made it work by just using a win32 control. For future readers: use the one you think it's easier(the one specified by Buckeye gives you more control over size and aspect ratio,but I guess you can resize win32 controls too so...your choice)

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