FreeType Text Rendering under DirectX 11 - c++

At the moment i just want to render a single char with FreeType and DirectX 11.
But how can i create a "ID3D11ShaderResourceView" from FT_Bitmap?
I already tried "D3DX11CreateShaderResourceViewFromFile" and "D3DX11CreateTextureFromFile" but both doesn't work.
Has someone a good tutorial or a code snippet for me?

Since FT_Bitmap is a bitmap already loaded into memory, you can't use the functions that create a texture from a file. Instead, you'll want to use a function to create a texture from memory.
You could use D3DXCreateShaderResourceViewFromMemory, however the D3DX library is deprecated. As mentioned on that page, you might want to instead use the DirectXTK or DirectXTex library to create a texture from memory.
Alternatively, you can create a D3D texture and shader resource view manually using ID3D11Device::CreateTexture2D and ID3D11Device::CreateShaderResourceView.
The only tricky part will be to determine which DXGI_FORMAT to use. You will need to match it with the FT_Pixel_mode of the bitmap.

Related

Is there any equivalent for gluScaleImage function?

I am trying to load a texture with non-power-of-two (NPOT) sizes in my application which uses OGLPlus library. So, I use images::Image to load an image as a texture. When I call Context::Bound function to set the texture, it throws an exception. When the size of the input image is POT, it works fine.
I checked the source code of OGLPlus and it seems that it uses glTexImage2D function. I know that I can use gluScaleImage to scale my input image, but it is dated and I want to avoid it. Is there any functions in newer libraries like GLEW or OGLPLUS with the same functionality?
It has been 13 years (OpenGL 2.0) since the restriction of power-of-two on texture sizes was lifted. Just load the texture with glTexImage and, if needed, generate the mipmaps with glGenerateMipmap.
EDIT: If you truly want to scale the image prior to uploading to an OpenGL texture, I can recommend stb_image_resize.h — a one-file public domain library that does that for you.

pixel text to 3d mesh convert library

Via GDI/GDI+ get the text pixels or glyph, how to convert to 3d mesh? Does any exists library or source code can be used?
PS: I know D3DXCreateText, but Im using opengl...
If you works on OpenGL, you can try FTGL, it allows you to generate different polygon meshes from fonts, including extrudes meshes as well as render them:
http://ftgl.sourceforge.net/docs/html/ftgl-tutorial.html
but I am not sure how portable is this library specially for OpenGL ES...
Using GDI is definitely not among the best ways to go if you need to obtain glyphs for the text, you could use FreeType library instead (http://www.freetype.org), which is open-source and portable. It can produce both bitmaps and vectorized representation for the glyphs. You will have to initialize single instance of class FT_Library in your program that is later used to work with multiple fonts. After loading font form file (TrueType, OpenType, PostScript and some other formats) you'll be able to obtain geometrical parameters of specific characters and use it appropriately to create texture or build primitives using your preferred rendering API, OpenGL let it be.

Load a BMP in opengl visual cpp

I need to apply a texture in a polygon. So I searched and I found many sources but i'm most of them I had problems in include and loading BMP picture. (developing in visual cpp 10). So can anyone tell-me the easy way to load a BMP file and how to apply the texture?
An easy way is to use GDI+ class Bitmap:
http://msdn.microsoft.com/en-us/library/ms534420%28v=vs.85%29.aspx
You create an object with a constructor which takes a filename and then get a pointer to the buffer which contains the pixels using LockBits() method. That method gives you a pointer to a buffer which you can send to OpenGL texture functions.

Cinder: How to get a pointer to data\frame generated but never shown on screen?

There is that grate lib I want to use called libCinder, I looked thru its docs but do not get if it is possible and how to render something with out showing it first?
Say we want to create a simple random color 640x480 canvas with 3 red white blue circles on it, and get RGB\HSL\any char * to raw image data out of it with out ever showing any windows to user. (say we have console application project type). I want to use such feaure for server side live video stream generation and for video streaming I would prefer to use ffmpeg so that is why I want a pointer to some RGB\HSV or what ever buffer with actuall image data. How to do such thing with libCInder?
You will have to use off-screen rendering. libcinder seems to be just a wrapper for OpenGL, as far as graphics go, so you can use OpenGL code to achieve this.
Since OpenGL does not have a native mechanism for off-screen rendering, you'll have to use an extension. A tutorial for using such an extension, called Framebuffer Rendering, can be found here. You will have to modify renderer.cpp to use this extension's commands.
An alternative to using such an extension is to use Mesa 3D, which is an open-source implementation of OpenGL. Mesa has a software rendering engine which allows it to render into memory without using a video card. This means you don't need a video card, but on the other hand the rendering might be slow. Mesa has an example of rendering to a memory buffer at src/osdemos/ in the Demos zip file. This solution will probably require you to write a complete Renderer class, similar to Renderer2d and RendererGl which will use Mesa's intrusctions instead of Windows's or Mac's.

Texture Mapping C++ OpenGL

I have read around on this, including Nehe and here for solutions, but I cant find a specific answer.
I am trying to load a a photo, called stars.jpg. I want to make this my background of the scene, by mapping it using uv coordinates, doing it by
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
However I am just very confused about how to load the actual textures in, all the calls for
glActiveTexture();
glEnable(GL_TEXTURE_2d);
glBindTexture(GL_TEXTURE);
All they do is confuse me, what do all these mean/do, and in what order am I suppose to put these in, in order to get the stars.jpg to be my background?
Your number-one tool for loading textures in OpenGL is the Simple OpenGL Image Loader (SOIL) library. You just need to pass the filename and some flags and you'll get your texture ID.
Also, you're learning very old and outdated version of OpenGL now - you might want to have a google for newer tutorials or browse the specs whenever you feel ready.
Here's a step by step tutorial on loading textures
http://www.nullterminator.net/gltexture.html
Its important to remember that OpenGL is a state machine, so you have to tell it "I'm going to talk about textures now" that's where the glActiveTexture(); comes in.
Also keep in mind that you will have to load in pixel by pixel the colors from your .jpg (compressed) to your texture array, so either you will need to find a library that will give you bitmap values of your .jpg file or you will need to pre-convert it into a .ppm or a .bmp which will make reading in the values easier.