我正在使用 C# Windows 窗体中的 VS 2013 社区,我正在试用 Tao 框架。我的问题是我不能用它创建文本,它只是出现一个带有红十字的白色表面。谁能告诉我出了什么问题或我该如何处理?
这里是示例代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tao.OpenGl;
using Tao.Platform;
using Tao.FreeGlut;
namespace TaoOpenGLTest
{
public partial class Form1 : Form
{
int w = 500;
int h = 500;
public Form1()
{
InitializeComponent();
this.simpleOpenGlControl1.InitializeContexts();
Gl.glClearDepth(1.0);
Gl.glClearColor(0, 0, 0, 0);
Gl.glEnable(Gl.GL_DEPTH_TEST);
Gl.glDepthMask(Gl.GL_TRUE);
Gl.glViewport(0, 0, w, h);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(45.0f, (double)w / (double)h, 0.01f, 5000.0f);
Gl.glEnable(Gl.GL_CULL_FACE);
Gl.glCullFace(Gl.GL_BACK);
}
private void timer1_Tick(object sender, EventArgs e)
{
this.simpleOpenGlControl1.Invalidate();
}
private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Gl.glTranslated(0, 0, -10);
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glVertex3d(-1, 1, 0);
Gl.glVertex3d(-1, -1, 0);
Gl.glVertex3d(1, -1, 0);
Gl.glVertex3d(1, 1, 0);
Gl.glEnd();
Gl.glRasterPos3f(0, 0, 0); // Set the position for the string (text)
text("Text"); // Display the text "Front"
}
// Used for the font that will be displayed
static void text(string c)
{
for (int i = 0; i < c.Length; i++)
{
// Render bitmap character
Glut.glutBitmapCharacter(Glut.GLUT_BITMAP_TIMES_ROMAN_10, c[i]);
}
}
}
}