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

DirectX in WS_OVERLAPPED window vs WS_CHILD window - shader renders differently

7 posts in this topic

Problem: Shader rendered meshes and ID3DXFont differ in WS_OVERLAPPED (top-level) window (okay) vs. WS_CHILD window (strangely scaled).

 

I have a windowed app (main window WS_OVERLAPPED style) which renders (to the client area) static and animated (skinned) meshes well. For the animated meshes I use Multianimation.fx and shader.vsh "borrowed" from the DX9 sample Multianimation. Static meshes are rendered via the device pipeline.

 

Wanting to add some other windows in the client area (properties and other editing aids), I moved the DirectX code to a WS_CHILD of the main window. To start with, the child window is sized to the main window's client area (no other children). Other than creating the child window with a parent in CreateWindow, I changed little in the code (storing the parent's HWND, etc.) and nothing in the DX related stuff. With the child being the same size as the main window client, buffer widths and heights remain the same (client-sized).

 

Static meshes rendered through the pipeline via mesh->DrawSubset(), DrawPrimitive, etc., are fine. However, the animated meshes rendered by the shader are rendered strangely scaled, differently along different axes, my own character meshes and even tiny.x (Microsoft's own). The only time anything appears scaled correctly is when the aspect ratio is 1:1, and even then, it seems to be only along one (Z) axis.

 

Trying to find clues, I found that text drawn to the scene using ID3DXFont also exhibits squashing and stretching as the window size changes. However, differing from the shader-draw meshes, the screen text (seems to) appear correct only at the original aspect ratio AND the original window size. Even at the original aspect ratio, the text is distorted at other than the original window size.

 

I've tried various combinations of things:

- Creating the device (with swapeffect COPY) with the main window's handle and presenting to the child; no change in behavior.

 

- Defaulting the backbuffer width/height to constant values, whatever the main window size. No joy there, EXCEPT...

 

- Defaulted the backbuffer width/height for an aspect of 1:1 (e.g., both width and height = 800) and presenting to the child's window handle with the destination rectangle { 0, 0, 800, 800 }. That exhibited the same behavior as any at an aspect of 1:1. Shader-rendered meshes appeared to be scaled correctly only along one axis. The ID3DXFont display was correct (the backbuffer size never changed). Again, stuff rendered via the pipeline was fine.

 

Again, please note, the static and shader meshes, and the screen text appear fine when renders in the client area of a WS_OVERLAPPED window.

 

Anyone have any ideas? Has anyone successfully used a WS_CHILD style window for rendering with shaders and/or ID3DXFont text?

 

0

Share this post


Link to post
Share on other sites

device->GetBackBuffer(...., pSurface);

pSurface->GetDesc(pDesc)

 

Check if pDesc->Width and pDesc->Height is the same as the client area of the window.

Edited by Tispe
2

Share this post


Link to post
Share on other sites

@Tispe - Thanks for the tip! I added a test routine before my render-scene routine to test surface dimensions against present-parameters and the window client. That revealed a logic problem in my window procedure for WM_SIZE (which I have to fix). That test routine resets the device if there's a mismatch and the render scene is skipped that cycle.

 

That solved the ID3DXFont problem - thanks for that! The screen text appears as-advertised after a window resize.

 

However, the strange scaling apparently caused in the shader is still there. (Pipeline stuff still appears okay) I checked that the effect is called on device-lost and device-reset. There's some more double-checking I'll do, but, for the moment, that problem persists.

 

Any more excellent suggestions?

0

Share this post


Link to post
Share on other sites

Do you happen to have multiple passes with multiple surfaces? If you are trying to fit one surface on to another it may get squashed depending on difference in surface dimentions.

0

Share this post


Link to post
Share on other sites

Sounds like a good question. However. it's a very simple app with regard to drawing - just pipeline calls and a single effect shader for the skinned meshes.

0

Share this post


Link to post
Share on other sites

MY PROBLEM FOUND - due to error checking that Tispe suggested above, I found an additional error in the WM_SIZE routines in both the MainWindow and ChildWindow window procedures. The response to SW_MAXIMIZE and SW_MINIMIZE were incorrect. The problem with ID3DXFont was NOT fixed previously. I just hadn't tried all combinations of resizing the main window - e.g., maximized-to-minimized, minimized-to-restore, etc.

 

If anyone cares, in summary, here's the general flow I have for maintaining DirectX in a child window:

 

For each WM_SIZE msg received by the main window, the child windows are resized in a main window routine using SetWindowPos for each child with the appropriate sizes. Lots of bookkeeping to keep track of the child windows sizes.

 

For the non-DirectX windows, nothing special is done. I let them take care of themselves as they're GDI.

 

The DirectX routines are paused (a flag set) by the Main Window when a sizing move starts (user dragging the main window frame) starts (WM_ENTERSIZINGMOVE). dxChild->EnterSizingMove method is called to pause the app and set a "sizing-in-progress" flag. The app is unpaused on WM_EXITSIZINGMOVE and an dxChild->ExitSizingMove method is called which unpauses the app and resets the device with the updated buffer size. This is done to prevent hundreds of device resets while the user drags the window.

 

When the dx child window receives a WM_SIZE, the backbuffer is resized. The device is reset with the new buffer size UNLESS a sizing move is in progress. When the sizing move ends (see above), the device is reset.

 

When the main window is minimized, the app is paused. When the main window is restored from a minimized state, the app is unpaused.

 

There may be a couple more subtleties, but that's the gist.

 

Again, @Tispe - thanks!

 

Is there a way to revise the topic to add RESOLVED or similar? EDIT: See unbird's comment below. Changed RESOLVED to MY PROBLEM FOUND.

Edited by Buckeye
0

Share this post


Link to post
Share on other sites
Welcome back Buckeye ... long time no see wink.png
 

Is there a way to revise the topic to add RESOLVED or similar?


You're not supposed to according to forum rules in order to not prevent further discussion. And I actually have to say something here.

First: Congrats. I've never seen this approach working (rerouting the output to other HWND with Present), so nice to know it's possible.

Usually when rendering to different windows one is supposed to create additional swapchains, one for each window. Doing so has one big advantage: You can omit the obnoxious D3D9 device reset when changing resolution. Though I nowadays mainly play with D3D11 I used this approach even for the main window: Create a (small) dummy backbuffer and use a custom swapchain instead. One can then even e.g. flip v-sync without a device reset wink.png

Your approach still has an advantage I think: I guess each swapchain will reserve device memory, so when you got a bloody lot of child windows you're "wasting" precious memory. Maybe you could combine both approaches, meaning: Use a central swapchain for all your child windows.
1

Share this post


Link to post
Share on other sites

Hey, unbird. Good to be back.

 

The forum rules with regard to labeling problems RESOLVED are, indeed, correct. I'm an old fart and my memory's fading - there have been discussions on the subject.

 

WRT various Present parameters - thanks for the credit but that was pure hacking. After a couple hours of trying to find my sizing problem, I just read the Present docs and tried a bunch of stuff. After (eventually) correcting the problem, my correctly working code has the "standard" stuff - the device window is the child window, backbuffer sized to the client area, Present(0,0,0,0), etc.

 

@unbird - thanks for the link to "additional swapchains." At present, I have (as mentioned) only a single DX window, but multiple swapchains may be just the thing to render multiple views in my editor. That should be an adventure! The bookkeeping for setting up swapchains in one window for other windows with differing views which may or may not be visible (or created) at the moment! I've never messed with multiple swapchains. However, the mental and learning challenge is why I program anyhow.

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