Drawing strings in OpenGL - opengl

What's the quickest, easiest way to draw text in standard OGL ??

Text is surprisingly involved in OpenGl
Take a look at this example from NeHe

OpenGL does not support drawing text. You need to use some library to render text to bitmap and then you can use OpenGL to render the bitmap. Freetype2 and Pango are good cross-platform low level solutions. Game programming libraries such as ClanLib and GUI libraries such as Qt may also have their own ways for rendering text.

It depends on the framework you are working on like the one above me said. for example, SDL is multi-platform and one can draw text using a special lib inside SDL:
http://gameprogrammingtutorials.blogspot.com/2010/02/sdl-tutorial-series-part-6-displaying.html
If you're using glut look at the following functions:
glutStrokeString,
glutBitmapString
in glut documentation..

Use textures. Each character is a textured quad, and texture coordinates enclose the specific characters.
Then, you can affine using display lists, generating raster representing string at runtime, outlining, blending...
You can use a platform specific OpenGL API (i.e. wglUseFontOutlines), but I think it will be deprecated since OpenGL 3.2.

OpenGL does not support text rendering directly. You have a variety of options:
Some OS bindings, such as WGL and
AGL, do have limited font support
(mostly they render system fonts
into bitmaps for use in Open GL).
The GLUT toolkit (and similar
toolkits) also has some font support
(bitmap and stroke).
You can use a
library such as FreeType (mostly a
font renderer, you still may wish to
use something like Pango for text
layout).
You can use simple textured
quads (this is effectively what
Quake 1 did).

Depends on what framework you are using. One common method is to render text to an offscreen buffer and use that as a texture.

Related

Draw geometric shapes in c++ without using opengl

I'm looking for a simple library that can create and draw some geometric shapes without using openGL or directX and also have documentation.
just gdi would be enough i guess
https://learn.microsoft.com/en-gb/windows/win32/api/wingdi/nf-wingdi-ellipse?redirectedfrom=MSDN
You could use any GUI library, like Gtk, Qt, Motif, etc. ...
If you are on Linux, you could draw on screen directly with X11.
There's a lot of 2D graphics library, but under the hood most of them use OpenGL, so technically you still use OpenGL but not directly (which is probably what you meant).
Some of them:
SFML
SDL
Skia
Cairo
As frederic mentioned you can also use some GUI libraries, since most of them have something like Canvas (the name can vary) which allows to draw shapes very easily.

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.

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.

Is Cairo acelerated on Opengl backend?

By this I mean, does Cairo draw lines, shapes and everything using opengl acelerated primitives or no? and if not, a library that does this?
The OpenGL backend certainly accelerates some functions. But there are many it can't accelerate. The fact that it's written against GL 2.1 (and thus can't use more advanced features of 3.x or 4.x hardware) means that there is a lot that it simply cannot accelerate.
If you are willing to limit yourself to NVIDIA hardware, NVIDIA just came out with the NV_path_rendering extension, which provides a lot of the 2D functionality you would find with Cairo. Indeed, it's possible that you could write a Cairo backend for it. The path rendering extension is only available on GeForce 8xxx hardware and above.
It's nifty in that it's focused on the vertex pipeline. It doesn't do things like gradients or colors or whatever. That's good, because it still allows you the use of a fragment shader. Which means you get to do pretty much whatever you want ;)
Cairo is designed to have a flexible backend for rendering. It can use OpenGL for rendering, though support is still listed as "experimental" at this point. For details, see using cairo with OpenGL.
It can also output to the X Window System, Quartz, Win32, image buffers, PostScript, PDF, and SVG, and more.

DirectX Font tutorial that doesn't use GDI

Does anyone have any tutorials/info for creating and rendering fonts in native directx 9 that doesn't use GDI? (eg doesn't use ID3DXFont).
I'm reading that this isn't the best solution (due to accessing GDI) but what is the 'right' way to render fonts in dx?
ID3DXFont is a great thing for easy to use, early, debug output. However, it does use the GDI for font rasterization (not hardware accelerated) and there is a significant performance hit (try it, its actually very noticable). As of DirectX 11, though, fonts will be rendered with Direct2D and be hardware accelerated.
The fastest way to render text is using what's called "Bitmap Fonts". I would explain how to do this, except that there is a lot of different ways to do implement this technique, each differing in complexity and capability. It can be as simple as a system that loads a pre-created texture and draws the letters from that, or a system that silently registers a font with Windows and creates a texture in memory at load-time (The engine I developed with a friend did this, it was very slick). Either way, you should see a very noticable performance increase with bitmap fonts.
Why this isn't a good solution?
Mixing GDI rendering and D3D rendering into the same window is a bad idea.
However, ID3DXFont does not use that. It uses GDI to rasterize the glyphs into a texture. And uses that texture to render the actual text.
About the only alternative would be using another library (e.g. FreeType) to rasterize glyphs into a texture, but I'm not sure if that would result in any substantial benefits.
Of course, for simple (e.g. non-Asian) fonts you could rasterize all glyphs into a texture beforehand, then use that texture to draw text at runtime. This way runtime does not need to use any font rendering library, it just draws quads using the texture. This approach does not scale well with large font sizes or fonts with lots of characters. Also would not handle complex typography very well (e.g. where letters have to be joined etc.)
With DirectX, the correct way to render standard fonts is with GDI.
However, IF
You want to support cross platform font rendering
with proper support for internationalization - including far eastern languages where maintaining a glyph for every character in a font is impractical
and/or You want to distribute your own fonts and render them without "installing" them...
Then libfreetype might be what you are looking for. I don't claim its easy: Its a lot more complex than using the native font api.
Personally I think that ID3DXFont is the way to go.
If you really wanted to make your own font routines, I suggest you look at:
http://creators.xna.com/en-us/utilities/bitmapfontmaker
You can use this to create a bitmap with all the characters printed on it. Then its just a matter or loading the texture and blitting the relevant chars onto the screen at the right place. (This is what XNA uses for its font drawing)
Its a lot more work, but you don't need the font to be installed on the target PC, and you have the advantage to being able to go into photoshop and edit the font appearance there.