如何在C ++中使用glutBitmapString()来绘制文本到屏幕? [英] How do I use glutBitmapString() in C++ to draw text to the screen?

查看:1624
本文介绍了如何在C ++中使用glutBitmapString()来绘制文本到屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在2d中使用GLUT在屏幕上绘制文本。

I'm attempting to draw text to the screen using GLUT in 2d.

我想使用glutBitmapString(),有人可以告诉我一个简单的例子你必须在C ++中设置和正确使用这个方法,这样我可以在(X,Y)位置绘制一个任意的字符串?

I want to use glutBitmapString(), can someone show me a simple example of what you have to do to setup and properly use this method in C++ so I can draw an arbitrary string at an (X,Y) position?

glutBitmapString(void *font, const unsigned char *string);

我使用linux,我知道我需要创建一个Font对象,不知道怎么和我可以提供它与字符串作为第二个争论。但是,我如何指定x / y位置呢?

I'm using linux, and I know I need to create a Font object, although I'm not sure exactly how and I can supply it with the string as the second arguement. However, how do I also specify the x/y position?

这样的一个快速示例会大大帮助我。

A quick example of this would help me greatly. If you can show me from creating the font, to calling the method that would be best.

推荐答案

您必须使用 glRasterPos 在调用 glutBitmapString()。注意,每次调用 glutBitmapString()会提高光栅位置,因此几个连续的调用会一个接一个地打印出这些字符串。您也可以使用 glColor()此处列出了一组可用的字体。

You have to use glRasterPos to set the raster position before calling glutBitmapString(). Note that each call to glutBitmapString() advances the raster position, so several consecutive calls will print out the strings one after another. You can also set the text color by using glColor(). The set of available fonts are listed here.

// Draw blue text at screen coordinates (100, 120), where (0, 0) is the top-left of the
// screen in an 18-point Helvetica font
glRasterPos2i(100, 120);
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, "text to render");

这篇关于如何在C ++中使用glutBitmapString()来绘制文本到屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆