简体   繁体   English

如何在OpenGL C ++程序中获取int作为输入并投影一个double作为输出?

[英]How to get an int as input and project a double as output in an OpenGL C++ program?

I'm developing a OpenGL application in C++ however I require the user to input an int and the project to output a double plus some text. 我正在用C ++开发OpenGL应用程序,但是我要求用户输入一个int并且该项目要输出一个double加一些文本。 What would be the best way to go about this? 最好的方法是什么?

There's no text input function in OpenGL. OpenGL中没有文本输入功能。 You'll have to use an API on top of openGL, for example manage the keyboard entry with the basic GLUT keyboard functions . 您必须在openGL之上使用API​​,例如,使用基本的GLUT键盘功能管理键盘输入。

For the output, you have to draw it as part of your graphic output as explained in this SO question . 对于输出,您必须按照此SO问题中的说明将其绘制为图形输出的一部分。

Of course you don't need to reinvent the wheel from scratch and may consider more elaborate API than Glut, as discussed here . 当然,您不需要从头开始重新发明轮子,并且可以考虑比Glut更为复杂的API,如此处所述

Edit: Just seen today this tweet from Evan Todd with a link to his 160 lines of C++ implementation of in-game console on github. 编辑: 今天刚刚看到来自Evan Todd的这条推文,链接到他在github上的160行游戏控制台的C ++实现。 It's based on OpenGL/glfw. 它基于OpenGL / glfw。 His approach could interest you as well. 他的方法也会引起您的兴趣。

Your job can be split into two part 您的工作可以分为两部分

  1. Taking integer input from user 从用户获取integer输入
  2. Show double + extra text it on your window 在窗口上显示double + extra text

obviously second part is the easy part, use glutStrokeCharacter to show your double + text referred here 显然,第二部分是简单的部分,请使用glutStrokeCharacter来显示此处引用的double + text

The first part is little bit tricker, you can make a TextEdit like widget using the glutStrokeCharacter & glutKeyboardFunc . 第一部分有点棘手,您可以使用glutStrokeCharacterglutKeyboardFunc制作类似TextEdit的小部件。 The job of the TextEdit will to show the user original int input. TextEdit的工作将显示用户原始的int输入。 just register the keyboard using glutKeyboardFunc & on the call back draw the original int inside the TextEdit widget. 只需使用glutKeyboardFunc注册键盘, glutKeyboardFunc在回叫上在TextEdit小部件内绘制原始int。

glutKeyboardFunc is referrence here here glutKeyboardFunc这里 glutKeyboardFunc

suggestion, draw a nice rectangle just behind the TextEdit's to make it seems actual user input :). 建议在TextEdit的后面绘制一个漂亮的矩形,以使其看起来像实际的用户输入:)。 Happy coding 快乐编码

Just found this actually which does exactly what I'm looking for. 刚刚发现这实际上正是我想要的。 Thanks for all the responses. 感谢您的所有回复。

https://justcheckingonall.wordpress.com/2008/08/29/console-window-win32-app/ https://justcheckingonall.wordpress.com/2008/08/29/console-window-win32-app/

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

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