如何使用OpenGL在窗口上绘制字符串? [英] How to draw a String to the window with OpenGL?

查看:38
本文介绍了如何使用OpenGL在窗口上绘制字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建游戏,但我有一个问题:我如何在屏幕上绘制文本,因为我想在玩家每次捡起东西或受伤时都打印一些东西.我已经知道Graphics的drawString()函数,但是如果使用OpenGL,我不确定是否可以.OpenGL有没有一种方法可以让我轻松地将文本打印到屏幕上?

I'm creating a game but I have one problem: how can I draw text to the screen, as I want to print something every time the player picks up something or gets hurt. I already know the drawString() function for Graphics, but I am not sure if that is OK if I am using OpenGL. Is there a method from OpenGL that lets me easily print text to the screen?

推荐答案

在OpenGL中,没有可以调用的用于将文本呈现到屏幕的函数/方法.

In OpenGL there is no function / method you can call to render text to the screen.

您有两个选择:1)使用图书馆; 2)选择图书馆.或2)自己滚动,创建自己的调用以将文本呈现到显示器.

You have two choices: either 1) use a library; or 2) roll your own, creating your own calls to render text to the display.

1)您可以使用许多不同的库将文本呈现到显示器上;但是,最明显和最容易使用的是GLUT.您可以使用两个呼叫:

1) There are a number of different libraries out there that you could use to render text to the display; however the most obvious and accessible to you is within GLUT. There are two calls within that you could use:

glutBitmapString() and glutStrokeString()

其中的第一个将以我认为可以称为2d的方式(看起来像是粘贴在显示器的右侧)将文本呈现到显示器.后者带有显示3D文本.

The first of these will render text to the display in what I guess could be referred to as a 2d manner (looking like it's pasted right of the display). The latter with display 3d text.

您可以参考

http://freeglut.sourceforge.net/docs/api.php

有关API参考.

2)您可以使用标准的OpenGL函数创建一个将字符纹理呈现到显示器的函数/方法,或者可以通过调用glDrawPixels()来使用字符缓冲区来生成字符.

2) You could create a function / method that renders character textures to the display using the standard OpenGL functions, or you could potentially use stencil buffers using calls to glDrawPixels() to generate the characters.

我还没有尝试过这些:我只是想过要顶一下,所以你的里程可能会有所不同.祝你好运.

I haven't tried these: I'm just thinking off the top of my head so you're mileage may vary. Good luck.

这篇关于如何使用OpenGL在窗口上绘制字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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