I need to make sure my machine can create a D3D window before even trying to open it. How can I do so?
I've found the equivalent of glxinfo for directX -- it's called dxdiag and is provided by Microsoft. This lets you output an xml file with a D3dStatus field (which says "not available" in my case).
You probably want to take a look at DeviceCaps. It should be able to tell you the capabilities of the device so that you don't try to create a window that it doesn't support.
Actually glxinfo does create a OpenGL window and creates a OpenGL context, but never maps it to the screen. One must create a OpenGL context to get all the information, like glxinfo does.
If you use Direct3D11 you can use this code
// Determines feature level without creating a device.
D3D_FEATURE_LEVEL determineHighestSupportedFeatureLevel()
{
HRESULT hr = E_FAIL;
D3D_FEATURE_LEVEL FeatureLevel;
hr = D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
0,
nullptr,
0,
D3D11_SDK_VERSION,
nullptr,
&FeatureLevel,
nullptr );
if(FAILED(hr))
{
throw std::runtime_exception("Determine the highest supported Direct3D11 feature level failed.");
}
return FeatureLevel;
}
Related
I want to create a GUI toolkit for my desktop environment (because neither gtk nor qt don't fit to my needs) but I don't know how to start. I don't want a cross-platform or display-server independent library, theming options, configurable icons etc. just a few basic widgets for making wayland clients. (widgets like button, entry, label, window and images... and I want to use CSD if it's important)
My problem is that I can't understand how graphics work in wayland (in X you only need to create a window and use XDrawLine etc. right?) also I don't know how to write a graphical toolkit. Can you give me some articles or recommendations on how can I do this?
The easiest way to create a wayland client is to use the wayland-client library. Basically, it abstracts the wire format.
example:
#include <stdio.h>
#include <wayland-client.h>
int main(void)
{
struct wl_display *display = wl_display_connect(NULL);
if (display) {
printf("Connected!\n");
} else {
printf("Error connecting ;(\n");
return 1;
}
wl_display_disconnect(display);
return 0;
}
I am struggling to adapt some code that has printing support to DCs (Device Contexts) and having it print to a Bitmap that can then be saved to disk.
I have tried the following code:
// The include files needed for my code
#include "atlimage.h"
#include "afxglobals.h"
// My attempt to get a DC which allows me to draw onto a CBitmap of A4 size
// (21.0x29.7 cm) in 300dpi, or 2480x3508 pixels in 24bit
HBITMAP BMP = CreateBitmap(2480,3508,1,24,NULL);
CBitmap* BitMap = CBitmap::FromHandle(BMP);
CMemDC A4(*CDC::FromHandle(CreateCompatibleDC(NULL)),CRect(0,0,1,1));
// This is where it fails. The SelectObject returns NULL, which means "failed"
// It may be caused by earlier code, but this is where I can detect the problem
// for the first time.
CBitmap* bmp = A4.GetDC().SelectObject(BitMap);
if (bmp == NULL)
TRACE("Error=%08X\n",GetLastError());
//
// The actual code that does the printing:
//
Graphs[0]->Print(A4.GetDC(),CRect(0,20,75,75));
Graphs[1]->Print(A4.GetDC(),CRect(75,20,100,75));
// And the saving to disk
CImage IMG;
IMG.Attach(*BitMap);
HRESULT res = IMG.Save("D:\\AUDIO.BMP");
IMG.Detach();
// Cleanup
DeleteObject(BMP);
DeleteDC(A4.GetDC());
TRACE("Result=%d\n",res);
The first TRACE prints out 00000000 as the error code, so I cannot tell (from this) why it fails.
I'd prefer not to use GDI+ if possible, but if GDI+ (which I don't have experience with) makes it much easier, I won't refuse it. I am using Visual Studio 2008 and cannot update to a newer version (it is part of a much bigger project that will take more time to upgrade to a newer version than I have time right now).
The caveat is that I only have printing routines that take a DC, and am not able to change this, so it must be done via a DC.
Any help would be appreciated...
Assuming that the error you refer to happens when you attempt to select the bitmap into the memory DC, the most likely explanation is that they are not compatible.
You have created a memory DC that is compatible with your desktop and that's most likely a 32bpp bitmap. Then you create a 24bpp bitmap, which I think is the problem.
To make sure everything is compatible, try this instead:
HDC hDC = CreateCompatibleDC(NULL);
HBITMAP BMP = CreateCompatibleBitmap(hDC, 2480,3508);
CBitmap* BitMap = CBitmap::FromHandle(BMP);
CMemDC A4(*CDC::FromHandle(hDC),CRect(0,0,1,1));
So, you create a bitmap and a DC that are compatible with the same original DC. Then the SelectObject should not fail.
Maybe update your question or comment on this answer if you don't get further.
I have an MDI Visual C++ 2008 application based on MFC. I am trying to find a way to use an image as background for the child window (child frame). I have been looking on various sites but I can't seem to find a solution. Does anyone know how to implement this?
It is always the same way when you want to change the background of a window.
Handle the WM_ERASEBKGND (OnEraseBkGnd). Draw the bitmap on the given DC and return TRUE
Either use StretchBlt or use it as a brush.
BOOL CMyClientWnd::OnEraseBkgnd(CDC* pDC)
{
CBrush* pbrushOld = pDC->SelectObject(&m_brush);
CRect rect;
pDC->GetClipBox(&rect);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(pbrushOld);
return TRUE;
}
My code looks roughly like this:
GLenum glewStatus = glewInit();
if (glewStatus != GLEW_OK)
exit(1);
if (!GLEW_ARB_framebuffer_object)
exit(1);
printf("%p\n", glFramebufferTexture);
This prints 0, so that explains why calling glFramebufferTexture() immediately segfaults.
However, why is it 0? A lot of the other framebuffer functions are working just fine (e.g. glBindFramebuffer, glFramebufferRenderbuffer, and glBindFramebuffer).
Do I need to initialise GLEW or the extension differently?
glFramebufferTexture() is a newer entry point than glBindFramebuffer() and other FBO related entry points. In the core OpenGL spec, glFramebufferTexture() was added in 3.2, while the rest of the FBO functionality was part of 3.0. glFramebufferTexture() was also not part of ARB_framebuffer_object.
You can use glFramebufferTexture2D() in most cases, which is part of the original FBO functionality. glFramebufferTexture() is only different for things like texture arrays, cube maps, etc.
I need to port some C++ application to Windows Phone 8 (it is already on Android, iOS, WinCE and Win32). Currently I need to solving how to display graphic. I can get rendered bitmap from core application and I after succesfully initialize DirectXTK I'm able to render some DDS texture (DirectXTK::SpriteBatch). Now I need to transform my bitmap to texture and then render it. Can you help me with this out? Or is there some way to put bitmap directly to backbuffer and show it on display without SpriteBatch?
Thank you very much
Tomas
DirectX toolkit has WICTextureLoader. You can use it instead of DDSTextureLoader for loading .bmp(bitmap) file. Hope this help!
http://directxtk.codeplex.com/wikipage?title=WICTextureLoader&referringTitle=DirectXTK
Since WICTextureLoader is not supported on Windows Phone 8 the only way to render a bitmap to a texture is by mapping the texture to the CPU and copy your bitmap resource onto the mapped texture's resource.
ID3D11DeviceContext::Map()
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx
D3D11_MAPPED_SUBRESOURCE mappedBuffer;
HRESULT hr = pContext->Map(pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedBuffer);
if(hr == S_OK)
{
// copy your bitmap onto mappedBuffer.pData
...
pContext->Unmap(pTex, 0);
}