简体   繁体   English

用c ++制作一个3d文本编辑器

[英]Making a 3d text editor in c++

Currently I am looking to write a text editor for linux systems that does some particular text/font highlighting that involves opengl rendering. 目前我正在为linux系统编写一个文本编辑器,它可以执行一些涉及opengl渲染的特定文本/字体突出显示。 Does anyone have suggestions for a c++ graphics rendering library that works well with linux (ubuntu in particular for now)? 有没有人有一个c ++图形渲染库的建议,适用于linux(特别是现在的ubuntu)?

And advice for where to start with rendering 3d text is greatly appreciated! 并建议从哪里开始渲染3D文本非常感谢!

EDIT: Just to clarify rendering 3d text is a strict requirement of the project. 编辑:只是为了澄清渲染3d文本是项目的严格要求。

There are basically only three ways to do this at the OpenGL level: 在OpenGL级别基本上只有三种方法:

Raster Fonts. 光栅字体。

Use glBitmap or glDrawPixels to draw a rectangular bunch of pixels onto the screen. 使用glBitmap或glDrawPixels在屏幕上绘制一组矩形像素。 The disadvantages of doing this are many: The data describing each character is sent from your CPU to the graphics card every frame - and for every character in the frame. 这样做的缺点很多:描述每个字符的数据每帧都从CPU发送到图形卡 - 以及帧中的每个字符。 This can amount to significant bandwidth. 这可能相当于显着的带宽。
The underlying OpenGL implementation will almost certainly have to 'swizzle' the image data in some manner on it's way between CPU and frame-buffer. 底层的OpenGL实现几乎肯定必须以某种方式在CPU和帧缓冲区之间“混合”图像数据。
Many 3D graphics chips are not designed to draw bitmaps at all. 许多3D图形芯片根本不是为了绘制位图而设计的。 In this case, the OpenGL software driver must wait until the 3D hardware has completely finished drawing before it can get in to splat the pixels directly into the frame buffer. 在这种情况下,OpenGL软件驱动程序必须等到3D硬件完全完成绘制,然后才能将像素直接溅入帧缓冲区。 Until the software has finished doing that, the hardware is sitting idle. 在软件完成之前,硬件处于空闲状态。
Bitmaps and Drawpixels have to be aligned parallel to the edges of the screen, so rotated text is not possible. 位图和Drawpixels必须平行于屏幕边缘对齐,因此无法旋转文本。
Scaling of Bitmaps and Drawpixels is not possible. 缩放位图和Drawpixels是不可能的。
There is one significant advantage to Raster fonts - and that is that on Software-only OpenGL implementations, they are likely to be FASTER than the other approaches...the reverse of the situation on 3D hardware. Raster字体有一个显着的优点 - 那就是在纯软件OpenGL实现上,它们可能比其他方法更快......与3D硬件情况相反。

Geometric Fonts. 几何字体。 Draw the characters of the font using geometric primitives - lines, triangles, whatever. 使用几何图元(线条,三角形等)绘制字体的字符。 The disadvantages of this are: 这样做的缺点是:
The number of triangles it takes to draw some characters can be very large - especially if you want them to look good. 绘制一些字符所需的三角形数量可能非常大 - 特别是如果您希望它们看起来很好。 This can be bad for performance. 这可能对性能不利。
Designing fonts is both difficult and costly. 设计字体既困难又昂贵。
Doing fonts with coloured borders, drop-shadows, etc exacerbates the other two problems significantly. 使用彩色边框,阴影等进行字体处理会显着加剧其他两个问题。

The advantages are: Geometric fonts can be scaled, rotated, twisted, morphed, extruded. 优点是:几何字体可以缩放,旋转,扭曲,变形,挤压。
You can use fancy lighting models, environment mapping, texturing, etc. 您可以使用精美的灯光模型,环境贴图,纹理等。
If used in a 3D world, you can perform collision detection with them. 如果在3D世界中使用,您可以使用它们执行碰撞检测。
Geometric fonts scale nicely. 几何字体很好地缩放。 They don't exhibit bad aliasing artifacts and they don't get 'fuzzy' as they are enlarged. 它们没有表现出错误的锯齿伪影,并且它们在扩大时不会变得“模糊”。

Texture-Mapped Fonts. 纹理映射字体。 Typically, the entire font is stored in one or two large texture maps and each letter is drawn as a single quadrilateral. 通常,整个字体存储在一个或两个大纹理贴图中,每个字母绘制为单个四边形。 The disadvantages are: 缺点是:
The size of the texture map you need may have to be quite large - especially if you need both upper and lower case - and/or if you want to make the font look nice at large point sizes. 您需要的纹理贴图的大小可能必须非常大 - 特别是如果您需要大写和小写 - 和/或如果您想使字体在大点大小时看起来很好。 This is especially a problem on hardware that only supports limited texture map sizes (eg 3Dfx Voodoo's can only render maps up to 256x256) 这对于仅支持有限纹理贴图大小的硬件尤其是一个问题(例如3Dfx Voodoo只能渲染高达256x256的地图)
If you use MIPmapping, then scaling the font makes it look a litte fuzzy. 如果使用MIPmapping,则缩放字体会使其看起来模糊不清。 If you don't use MIPmapping, it'll look horribly aliasy. 如果你不使用MIPmapping,它看起来会很可怕。

The advantages are: 优点是:
Generality - you can use an arbitary full colour image for each letter of the font. 一般性 - 您可以为字体的每个字母使用任意全彩色图像。 Texture fonts can be rotated and scaled - although they always look 'flat'. 纹理字体可以旋转和缩放 - 尽管它们看起来总是“平坦”。
It's easy to convert other kinds of fonts into texture maps. 将其他类型的字体转换为纹理贴图很容易。
You can draw them in the 3D scene and they will be illuminated correctly. 您可以在3D场景中绘制它们,它们将被正确照亮。
SPEED! 速度! Textured fonts require just one quadrilateral to be sent to the hardware for each letter. 纹理字体只需要将一个四边形发送到每个字母的硬件。 That's probably an order of magnitude faster than either Raster or Geometric fonts. 这可能比Raster或Geometric字体快一个数量级。 Since low-end 3D hardware is highly optimised to drawing simple textured polygons, speed is also enhanced because you are 'on the fast path' through the renderer. 由于低端3D硬件已经过高度优化以绘制简单的纹理多边形,因此速度也得到提升,因为您通过渲染器“处于快速路径”。 (CAVEAT: On software-only OpenGL's, textured fonts will be SLOW. (CAVEAT:在仅限软件的OpenGL上,纹理字体将是SLOW。

Links to some Free Font Libraries: 一些免费字体库的链接:

I use FTGL , which builds on top of freetype . 我使用FTGL ,它建立在freetype之上。 To create 3D, extruded text, I make these calls: 要创建3D,挤压文本,我进行以下调用:

#include <FTGL/ftgl.h>
#include <FTGL/FTFont.h>
...
FTFont* font = new FTExtrudeFont("path_to_Fonts/COOPBL.ttf");
font->Depth(.5);    // Text is half as 'deep' as it is tall
font->FaceSize(1);  // GL unit sized text
...
FTBBox bounds = font->BBox("Text");
glEnable(GL_NORMALIZE); // Because we're scaling
glPushMatrix();
glScaled(.02,.02,.02);
glTranslated(-(bounds.Upper().X() - bounds.Lower().X())/2.0,yy,zz); // Center the text
font->Render("Text");
glPopMatrix();
glDisable(GL_NORMALIZE);

I recomend you QT wich is foundation of KDE or GTk+ for GNOME. 我建议你QT是GNDE的KDE或GTk +的基础。 Both of them have support for OPENGL and text. 他们都支持OPENGL和文本。 With QT you can do advanced graphics(QGraphicsView) , including animation... Take a look at QT Demo Application . 使用QT,您可以执行高级图形(QGraphicsView),包括动画......看看QT演示应用程序。

A good start would be NeHe's OpenGL Lesson 14. 一个好的开始是NeHe的OpenGL第14课。

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=14 http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=14

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM