What is Direct2d command analog to OpenGl's SwapBuffers? I am using this in a VCL environment such as Delphi and CPP Builder. Thanks
d3ddev->Present(NULL, NULL, NULL, NULL);
There are a couple of ways you can do the equivalent in Direct2D. The simplest way is to create an ID2D1HwndRenderTarget. See http://msdn.microsoft.com/en-us/library/windows/desktop/dd371275(v=vs.85).aspx for details. You'll be interested in the D2D1_HWND_RENDER_TARGET_PROPERTIES parameter. This has a D2D1_PRESENT_OPTIONS field, which can be set to different values depending on the behavior you want. See http://msdn.microsoft.com/en-us/library/windows/desktop/dd368144(v=vs.85).aspx for details. With this in place, the rough equivalent of SwapBuffers is ID2D1RenderTarget::EndDraw.
The other option is using Direct3D interop. In this case you create a DXGI surface render target. (I'd post a link to the docs, but I don't have enough StackOverflow reputation to post more than two hyperlinks. Google "ID2D1Factory::CreateDxgiSurfaceRenderTarget" for the docs). This allows you to use Direct2D to issue 2D rendering commands to the surface, but then present using Direct3D/DXGI. This is more complicated but gives you more flexibility.
Related
I have previously worked on gltf 1.0 and is now trying to update my application to render gltf2.0 sample models provided by khronos. I understand that shaders(glsl) and techniques are no longer part of the core properties in gltf 2.0.
So my question is that:
Are shader information now separated from .gltf? I know there is KHR_technique_webgl extensions which consist of the technique and shader properties(exactly like how gltf1.0 represent shader), are we suppose to be use that if our material arent pbr?
How do rendering engines now grab shader information from normal .gltf now(without the extensions)? Do we do it like old school way ie loading our own shader and manually map the model attributes to shaders attribute?
The KHR_technique_webgl extension will eventually be finished, and will provide a way to include custom shaders with your glTF2.0 model. But as of this writing, the extension is not fully defined and tools cannot implement it.
The more general case (and recommended if it suits your needs) would be to use PBR or Blinn-Phong materials. These are declared abstractly in glTF, so that rendering engines can build their own shaders for these material types, and will generally integrate better with engines' own lighting and/or shadows.
So I have recently started using SharpDX, and have stumbled into a problem. I have no idea how to get SharpDX to multisample. I have found two things related; you can specify a SampleDescription when creating the SwapChainDescription, but any input other than (1, 0) throws a Wrong Parameter exception.
The other thing I found was SamplerState, which I put on my pixel shader, didn't do anything. I played around a lot with the parameters, but there was no visible change whatsoever.
I am sure I am missing something, but without any previous directX knowlegde I have no idea really what exactly to look for.
This will come in handy in your case:
int maxsamples = Device.MultisampleCountMaximum;
int res = device.CheckMultisampleQualityLevels(SharpDX.DXGI.Format.R8G8B8A8_UNorm, samplecount);
If res returns 0 then this Sample count is not supported.
Also please note that some options are not compatible, so if you create your SwapChain with:
sd.Usage = (other usages) | Usage.UnorderedAccess;
You are not allowed to use multisampling.
Another very useful technique to spot the problems for those errors:
Create your device with DeviceCreationFlags.Debug
In your startup project properties (debug section), tick "Enable native code debugging".
Any API call that fails will give you an error description in the debug output window.
I had the same problem, could not get Multisampling to work until I enabled the debugging and got a good hint (really wished I had done this hours ago and saved a whole lot of testing!).
Initially I read somewhere that the DepthStencilBuffer had the same SampleDescription as the Render texture - but I'm not so sure as it appears to work without this as a quick test just showed.
The thing for me was to create the DepthStencilView with a DepthStencilViewDescription that has "Dimension = DepthStencilViewDimension.Texture2DMultisampled".
Just a heads up on when you are doing multisampling.
When you set your rendertarget, if passing a rendertarget and depthstencil, you need to ensure they both have the same multisampling level.
So, for rendering to the backbuffer you have defined with MSAA, you will need to create a depth buffer with the same MSAA level.
BUT, if you are have a rendertarget that will be a texture that is fed back into the pipeline, you can define a non MSAA texture and a NON MSAA depth buffer, which is handy as you can use a sampler on the texture (you cant use a normal sampler for a MSAA Resource texture).
Most of this info maybe not new for you.
In 11.1 and later Microsoft removed a lot of helpers for loading textures (fromfile, fromstream etc).
I'm trying to port my code over to 11.2 and everything works fine except for this line :
var texture = Texture2D.FromFile<Texture2D>(device, #"C:\Texture.png");
Now all i could find was guidance telling me to use WIC instead but i can't seem to find anything providing me with a Texture2D that is nearly as versatile (all the samples i found require passing in the pixel format among other things).
I'm looking for a solution that would let me load files (without knowing their format or layout before hand) and get a Texture2D out of it just like FromFile allowed. Is there anything like that or even close? I'm assuming there has to be "something" as they wouldn't just deprecate such a feature if it wasn't superfluous.
Any help is most appreciated.
Edit : I'd like to avoid using the SharpDX.Toolkit too, i'm looking for a raw DirectX / WIC etc solution as i don't want to add a dependency on the Toolkit. I'm however perfectly fine on adding any .net Framework 4.0 or 4.5 assembly as a dependency.
There is no easy solution apart from writing the whole WIC interop yourself. Even if you don't want to use the Toolkit, the source code is available and the class WicHelper.cs responsible for decoding images is fairly easy to adapt.
If you want a very simple solution that doesn't handle all WIC cases (format mappings...etc.), you can have a look at TextureLoader.cs.
Provided you have both a Texture2D and a WPF BitmapImage lying around, something like this will help:
var map = device.ImmediateContext.MapSubresource(texture, 0, MapMode.WriteDiscard, MapFlags.None);
bitmap.CopyPixels(Int32Rect.Empty, map.DataPointer, bitmap.PixelWidth * bitmap.PixelHeight * 4, bitmap.PixelWidth * 4);
device.ImmediateContext.UnmapSubresource(source, 0);
The function you mention was probably something fairly similar under the hood.
If you're not sure about the bitmap being Bgra, you have to convert it first.
I have been looking through the threads at the Qualcomm Forums but no luck since I don't know exactly how to look for what I want.
I'm working with the ImageTargets Sample for iOS and I want to change the teapot to another image (a text rather) I had.
I already have the render and I got the .h using opengl library but I can't figure out what do I need to change to make this work and since this is the very basic and I haven't been able to make it work I really haven't ventured to try anything else.
Could anyone please help me out?
I would paste code here but it's a whole project so I don't know exactly what to put if needed please let me know.
If the case is still valid, here's what you have to do:
get header file for 3D object
get texture image for this object
in EAGLView.mm make this changes:
import "yourobject3d.h"
add your texture to textureFilenames array(this should be at the begining of EAGLView
eventually take care about kObjectScale (by deafult it was about 3.0f, for one object I did have to change it even up to 120.0f)
in setup3dObjects method assign proper arrays of vertices/normals/texture coords (check in "yourobject3d.h" file for proper arrays and naming) to Object3D *object
make this change in renderFrameQCAR
//glDrawElements(GL_TRIANGLES, obj3D.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)obj3D.indices);
glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices);
I believe that is all... if something take a look at Vuforia's forum, i.e. here: https://developer.vuforia.com/node/2047669
NOTE: default teapot.h does (!) have indices, which are not present in banana.h (from comment below) so take care about that too
Have a look at the EAGLView.mm file. There you'll have to load the textures (images) and 3d objects (you'll need to import your .h instead of teapot.h and modify setup3dObjects accordingly).
They are finally rendered by calling the renderFrameQCAR function.
Actually, teapot is not an image. It's a 3D model stored in .h format which includes Vertices, Normals, and Texture coordinates. You should have a good knowledge of OpenGL ES to understand those codes in sample app.
An easier way to change the 3D model to whatever you want is to use a rendering engine which facilitates the drawing and rendering stuffs and you don't need to bother OpenGL APIs. I've done it with jPCT-AE for Android platform but for iOS there is a counterpart called OpenFrameworks engine. It has some plugins to load 3Ds or MD2 files and since it's written in C++ you can easily integrate it with QCAR.
This is a short video of my result with jPCT and QCAR:
Qualcomm Vuforia + jPCT-AE test video
I have a couple of (mostly) text widgets that I would like to render to a printer through a standard "Print..." menu option. One widget is a Mono.TextEditor document, and the other is a Gtk.TextView.
I'm looking for a pretty basic print for now, which might wrap long lines, and add page numbers. Do I need to code all of this myself somehow?
If you have pointers, that would be great, especially if they were in C#.
For line wrap and justification, one can use pango Layout
options, as described for Python at pygtk/class-pangolayout or for C at pango/pango-Layout-Objects. See functions pango_layout_set_wrap() and pango_layout_set_justify().
Also see the example-code routines begin_print, do_page_setup, and do_print in file pygtk-demo/demos/print_editor.py, if you have installed pygtk on your system. (On my system, the full path to directory of Python Gtk demo files currently is /usr/share/doc/pygtk2-2.17.0/examples/pygtk-demo/demos)
For printer setup dialog, see gtk-High-level-Printing-API for C, or class-gtkprintoperation for Python.