【发布时间】:2017-02-18 18:01:19
【问题描述】:
我的代码看起来像这样对此代码的修改将不胜感激。我试过了,只有矩形没有出现文字。
#include <GL/glut.h>
#include<bits/stdc++.h>
using namespace std;
void init2D(float r, float g, float b)
{
glClearColor(r, g, b, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 600.0, 0.0, 600.0);
}
void RenderToDisplay()
{
int l,lenghOfQuote, i;
char str[80];
strcpy(str,"Have courage and be kind");
cout<<str;
lenghOfQuote = (int)strlen(str);
for (i = 0; i < lenghOfQuote; i++)
{
glColor3f(1.0, 0.0, 0.0);
glutStrokeCharacter(GLUT_STROKE_ROMAN, str[i]);
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex3f(150.0f, 200.0f, 0.0f);
glColor3f(0.940, 0.37, 0.47);
glVertex3f(450.0f, 200.0f, 0.0f);
glColor3f(0.940, 0.37, 0.47);
glVertex3f(450.0f, 400.0f, 0.0f);
glColor3f(0.69, 0.27, 0.57);
glVertex3f(150.0f, 400.0f, 0.0f);
glColor3f(0.69, 0.27, 0.57);
glEnd();
RenderToDisplay();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0,0);
glLineWidth(3);
glutCreateWindow("Assignment Q2");
init2D(0.0, 0.0, 0.0);
glutDisplayFunc(display);
glutMainLoop();
}
如果您需要问其他任何问题,可以告诉我这些 cmets。我使用代码块来测试这个程序。
【问题讨论】:
-
Using GLUT to simply print text 可能会有所帮助。
-
@KaushikNP 我还是做不到,我在 OpenGL 中有点菜鸟,如果你能在程序中提出建议就好了。
-
@АлексейНеудачин 我没明白。如果您想在第二个问题中发送拉取请求,请在 github.com/heysadboy/Advanced-Graphics-and-Animation 处发送请求。谢谢。