Creating a texture from a image in DX 12 VC++ - c++

I just want know Directx 12 API to create texture from image.
For DX11 it is D3DX11CreateShaderResourceViewFromFile and for DX9 it is D3DXCreateTextureFromFileEx and for DX12 ?

Things are a little bit better by now. Microsoft rewrote their DDSTextureLoader for DX12 and released it as part of their MiniEngine on GitHub
https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/DDSTextureLoader.cpp
You also may want to take a look at my derivative work that is intended to make use of the DDSTextureLoader a bit easier outside of MiniEngine.
https://github.com/ClemensX/ShadedPath12/blob/master/ShadedPath12/ShadedPath12/DDSTextureLoader.cpp
I use this loader for all my texture files. It parses DDS (DirectDrawSurface) file format pretty well, including mipmaps.

There isn't one.
Direct3D 12 is a low-level API. A very low-level API. It doesn't have convenience functions that create textures out of whole cloth from just a filename. If you want to create a texture, you have to work for it. You have to load the file, figure out what format you want it in, allocate memory for it by asking the system how much memory it would take, then go through a complex series of steps to transfer your loaded image into that memory.

The official 'utility header' for Direct3D 12 is d3dx12.h. It's an inline header and has no DLL or static library, so the functionality provided is limited to true helpers. It has no equivalent to D3DX11CreateShaderResourceViewFromFile. It is not included as part of the Windows SDK, but instead is provided under the MIT license and you are expected to just copy it into your project--it's included in the various DirectX 12 Visual Studio templates including my Direct3D Game templates.
You can use the DDSTextureLoader and WICTextureLoader modules provided in the DirectX Tool Kit for DirectX 12 for some ready-to-use texture loader for Direct3D 12. See this tutorial lesson.
It's worth noting that D3DX9, D3DX10, and D3DX11 are all deprecated and only available as part of the legacy DirectX SDK per MSDN. In other words, you shouldn't be using D3DX11CreateShaderResourceViewFromFile for your Direct3D 11 code. See this blog post for a full list of D3DX9/10/11 replacements. TL;DR: use DDSTextureLoader and WICTextureLoader in DirectX Tool Kit for DirectX 11.

Google keeps referring to this topic for questions around DX-12 and textures, so let's update.
1. Managed
If you insist on "managed" check out the samples with the last version of SharpDX (2019)
https://github.com/discosultan/dx12-game-programming
It provides a C# interface to DX-12 native and it works, there are a lot of very nice samples, including texturing,
09-Crate loads a single DDS texture and shows it on a cube
09-TexColumns shows basic UV-coordinate actions on various shapes
.. but IMHO it's not really advisable, to keep depending on the good old SharpDX library, because that library is not maintained anymore. I can't advise good alternatives for C# atm, I'm not an expert on Unity and Vulkan.
2. Unmanaged
As mentioned earlier in this topic, DX-12 things improve. They still do. Check out Chuck Walbourn's current samples here,
https://github.com/microsoft/Xbox-ATG-Samples
For straight PC/x64, you'll find this,
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/PCSamples
For PC/UWP, you'll find this,
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/UWPSamples
These are very nice x64 unmanaged C++ 14.0 examples, using DirectXtk for DirectX-12. Last update in the Master was 3 months ago. Examples involving textures, also straight bitmap textures are
SimpleTexturePC12 loads a single .jpg texture and shows it in front view
DirectXTKSimpleSample12 loads several textures
Graphics\VideoTexturePC12 shows a dynamic texture read from an .mp4 video
These projects are configured for VS2017, but they convert out of the box when loading them in VS2019 and they compile and run ok.
Other sources
A known switchboard on DX-12 is vinjn on github, his page is
http://www.vinjn.com/awesome-d3d12/
Navigate from there to study articles and find various other samples.
There is a 3dgep.com tutorial on the subject of DX12 textures, that is
https://www.3dgep.com/learning-directx-12-4/
.. accompanied by
https://github.com/jpvanoosten/LearningDirectX12

Related

How do I render all actors in a single area using DirectX 11 in C++ efficiently and easily?

I have searched SO and have not found one relating to the very basics, explaining step by step. We are in need of this.
Assuming that I am using only the DirectX SDK supplied by microsoft.
Also assuming that I have .fbx and .3ds models already made and in the working directory which are generic, monochrome, shapes (cube, sphere, pyramid, etc.).
Please also condense the rendering process into a function that uses the directX functions (As in, can be compiled), as an example:
//the following is a suggestion, not a guideline for those who
//want to get into 3D programming.
vector<DX3DModel>modelsToBeRendered;
void bufferFrame(vector<DX3DModel>models){
while(1){
/* something something vertexes, lets say DX3DModel only contains vertexes
and a string as a file link
(Rendering code would make it very
messy in the question, but please include it in the answer.) */
//render models.end(); here
models.pop_back();
}
}
Using a method similar to what I have above, how would I (safely) render all other actors in a single "area" while still being able to manipulate vertexes at will?
(Area is a (AxBx1) model which we will call field.fbx. This is a boundary for all actors to exist on)
The Direct3D 11 API, much like the OpenGL API, is a low-level rendering API that works in terms of resources and drawing operations on constructs containing points, lines, and triangles. It's not a high-level API that can directly load or render an model file from a 3D editor, nor does it inherently have a material/effects system.
If you are new to DirectX 11, you should consider using the DirectX Tool Kit as a good starting-point. You can't directly render from a 3DS or FBX model, but you can use either the built-in Visual Studio content pipeline for converting to a CMO or use the Samples Content Exporter to convert to SDKMESH, both of which can be loaded by DirectX Tool Kit.
Using the DirectX Tool Kit, you'd be able to use the Model class and get something basically like what you propose. See the DirectX Tool Kit tutorial, particularly the lesson Rendering a model.
For Direct3D 11 development, you should strongly consider not using the legacy DirectX SDK as it's deprecated. If you are using VS 2012 or later, you don't need it. See Where is the DirectX SDK (2015 Edition)? and The Zombie DirectX SDK.

PNG Texture OpenGL es 2.0 Android NDK

I'm developing a game, actually my first game, so I'm new in this world, I'm using OpenGL with NDK and C++ for the render part, and I call it from java with JNI. I'm stuck with the textures topic, since I need to use PNG with alpha channel and use TTF for some text.
I can include the libpng, but since I'm using the experimental gradle puglin, I don't know how to add the library and use it, I saw that the library can be precompiled and be added, but from what I saw, only for one architecture, then, I don't know if I'm wrong, but I think if I add the source code of the library and compile it with the program, I think, it will be compiled for the architectures that I need (MIPS, 64-bit ARM, x86, 64-bit x86, ARM), so that is one, I was thinking in pre-convert the png in raw RGBA and use that vector directly with opengl but again, I dont know how to do this.
and with the TTF issue, well I am in blank, if you have any advice for this I would greatly appreciate it.
Thanks for your help.
You can build the whole FreeType engine into your code, or you can just use what's already part of Android: use Canvas to render glyphs to a Bitmap. You can find an example of this in Android Breakout. The game is written in Java rather than C++, but the Java-language GLES code is just a thin wrapper around the native stuff, so it's pretty similar.
There's a pretty good blog post about GLES text on Android here.
On a similar note, you already have a copy of libpng in your app. You can call through the Bitmap API to use it.
If you have as a goal the creation of an entirely self-contained native app, then the approach of calling into Canvas/Bitmap isn't viable. I don't think that's a particularly useful goal, however. You're better off separating the "game engine" from the game logic, e.g. have platform-specific "decode PNG" and "pass this pile of RGBA pixels into glTexImage2D()" functions, and platform-agnostic "use texture N".
Taking that one step further, your best approach is to use an existing graphics engine or game engine, and focus on creating the game rather than writing the engine. Learning about engines by writing one is a worthwhile endeavor, but if your actual goal is to write a game then you should focus on the game itself.

VS2012 using 3D models dilemma

I'm having problems understanding the the usage of VS2012's 3D features in a project. I'm current building a 3D project using DirectX (Direct3D) and want display a simple 3D object (teapot) for starters. I understand the usage of the shadergraph which is of great help, but when it comes to loading an FBX model, is there an alternative to using the Autodesk FBX SDK built in or am I just stuck with it (FBXSDK)?
Generally, is there anything in VS2012 for C++ similar in nature to how XNA uses it's content pipeline to simplify loading and working with models?
You will definitely need to manage the translation from the format of your model files to the typical D3D mesh/meshpart arrangement. You can get sometimes find models in the old .x format, which corresponds to a Direct3D model. This page has some good reference for loading .x files and also links to exporters for maya and max.
OTOH If your source data is in fbx, use the fbx sdk; it's just simpler than any alternative way to get fbx data. You'll need some library for importing 3d models and although they're all limited in different ways FBX has the advantage of being supported by the widest variety of DCC apps. There are text and binary versions of the FBX format, so if you're interested in manual debugging you can use the text based version to make it easier to crosscheck your results. This sample discusses using the FBX SDK with DirectX 11 - although it is in the context of vs 2010, there may be issues moving to VS 2012.
If you go with another intermediate format you should look for one supported by the 3d tool you'll be using or the model vendor you are buying from. Collada is the most widely available interchange format, and it's based on XML so you could probably implement your own loader -- however it's also notorious for complexity and inconsistent standards so I'd avoid it unless you have a compelling reason or a big trove f Collada format files.
If your needs are very simple and don't include animation, the OBJ format is widely available and easy to implement on your own -- however it does not support animation.
is there anything in VS2012 for C++ similar in nature to how XNA uses
it's content pipeline
As far as I know, there is no such thing. You will need your own solution, as always in native C++ world =). Probably, you can make use some of the modern rendering engines: Unity, OGRE, Irrlicht, Torque, etc.
when it comes to loading an FBX model, is there an alternative to
using the Autodesk FBX SDK built in or am I just stuck with it
(FBXSDK)
As far as I know, FBX is a closed proprietary format, so you stick with FBX SDK.
Another ways (from gamedev view)
FBX format is a terribly complicated and multifunctional. Typically, you don't need FBX to draw teapot. You don't even need FBX to create a good game.
to just draw teapot you, probably, better take another simple (or not so simple) format, such as .obj, .dae or .3ds. You can load it using 3rd party library, such as assimp (which is just few lines of code) or roll out your own loader (which is not so hard either).
to draw some meaningful interactive "teapots world" you will also need to wrap them into some kind of scene: scenegraph is a common solution.
mid-size game labels typically crate their own format, converter and loader for it:
artists create models in their favorite 3D editor
then they convert it using converter: convert to custom binary .mesh format. This can be done via plugin for 3D editor or in small standalone app
in C++ app, programmers just load .mesh, deserialize to structs and classes and use it.
serious game labels develop their own content pipelines: it can include multiple custom formats (static mesh, animated mesh, etc.), loaders (to load and stream content into app), 3ds max/Maya/Blender plugins, visual scene/level editors (to make artists happy). All content is created and managed by artists, so programmers don't need any integration of content to their IDEs.
Visual studio 2012 actually has it's own model processor now.
You can add different meshes to your project(I think that it natively supports .dae, .fbx, and .obj) and it'll spit out a ".cmo" model that's simple to parse.
The directX Toolkit also has pretty good support for loading the format, so if you're already using the DXTK, then I recommend seeing if the model loader meets your requirements.

Any good C++ library for displaying large bitmaps

I'm currently using MFC/GDI and Stingray to display bitmaps in my application and am looking for a better solution. Specifically;
Faster drawing speed - My current solution is slow, based on StretchDIBits
Better rendering quality - StretchDIBits rendering quality is awful when scaling a bitmap
Support for rotated bitmaps
Support for loading / saving in all popular formats
Support for large bitmaps - I'm regularly using aerial photographs that are ~64mb as 12,000x12,000 jpegs. GeoTIFF support would also be useful
Compatible with MFC document/view, including printing (e.g. must be able render to a CDC)
Access to source code is good but not necessary
Easy to use / port existing GDI code
While free is always nice, I don't mind spending a reasonable amount on a decent library, though no run time royalty costs. Googling suggests the following;
CImg
Graphics Magick
Lead Tools imaging SDK
Anyone got experience of these or can recommend an good alternative?
GDI+ is available on any Windows machine since early XP. It has codecs for all popular image formats, JPEG is included. Very nice filters for high-quality image rescaling. Unrestricted image rotation. Draws to a CDC through the Graphics class. Source code for the C++ wrappers are available in the SDK gdiplusXxx.h header files. Speed is likely to be equivalent however, rendering is software based to ensure compatibility.
You can #include <gdiplus.h> and use the C++ wrappers directly. The SDK docs are here. The CImage class is available in MFC, it doesn't expose all capabilities however.
I think it's unlikely you'll find something that performs faster than GDI on windows since it has kernel-level support which is something open source solutions will not have.
You might want to also look into OpenGL or Direct2D/Direct3D since these too have direct access to the frame buffer. With 3D APIs, texture size would probably be an issue since most standards limit to something like 4096x4096.
I have used CxImage in the past which is one to add to your evaluation list.

3D scene file format & viewer

I am looking for a cross-platform solution for saving and viewing 3D scenes (visualizations of engineering simulation models and results) but there (still) doesn't seem to be much out there.
I looked into this almost 10 years ago and settled on VRML then (and started the project that eventually turned in OpenVRML). Unfortunately, VRML/X3D has not become anywhere near ubiquitous in the past decade.
Ideally a solution would offer a C++ library that could be plugged in to a 3D rendering pipeline at some level to capture the 3D scene to a file; and a freely redistributable viewer that allowed view manipulation, part hiding, annotation, dimensioning, etc. At least linux, mac, and windows should be supported.
3D PDFs would seem to meet most of the viewer requirements, but the Adobe sdk is apparently only available on Windows.
Any suggestions ?
The closest thing that I'm aware of is Collada.
Many 3D engines can read it, and most 3D design tools can read and write it.
I believe the Ogre engine has pretty good support.
If you are using OpenGL, GLIntercept will save all OpenGL calls (with the data they were called with) to a XML file. It's only half the solution, though, but it shouldn't be hard to parse it and recreate the scene yourself.
Take a look at Ogre3d.org. Its just an engine, you must program with it. But OGRE is probably the better (free/open) platform to develop 3D right now.