C#,OpenGL,CsGL,跪求哦!!回答有加分
请问各位大大,怎么用C#写OpenGL(CsGL)显视文字,用V++写OpenGL显视文字与C#写的有什么区别?能否给个在C#下写的OpenGL文字显视的例子,只英显视英文的也可,谢谢!! --------------------编程问答-------------------- 这个我也想知道,帮你顶上去 --------------------编程问答-------------------- 不懂C#的OPENGL.不过我想方法应该是一样的吧.显示中文你得转换好象 --------------------编程问答-------------------- 推荐nehe opengl教程 --------------------编程问答-------------------- C# 的OpenGL控件CsGL基本用法 --------------------编程问答-------------------- C#怎么会去用OpenGL,当然DirectX,显示文字超简单,用DrawText就可以了,直接有这个功能了,指定区域后,文字还会自动换行,可以设定颜色,字体,还有取到某个字占用的宽度。 --------------------编程问答-------------------- /// <summary>
/// 将指定 字体格式 的文本输出为 实际显示的 像素 字节流
/// </summary>
/// <param name="text">显示文本</param>
/// <param name="pixBuffer">输出的像素缓冲</param>
/// <param name="font">字体格式</param>
private void BuildFont(string text,out byte[] pixBuffer,Font font)
{
if(font==null)
font = new Font("宋体", 9F);
Color m_color = Color.White;
Graphics g_ctrl = this.CreateGraphics();
m_size = g_ctrl.MeasureString(text, font).ToSize() + new Size(1, 0);
g_ctrl.Dispose();
pixBuffer = new byte[m_size.Width * m_size.Height * 4];
Bitmap bitmap = new Bitmap(m_size.Width, m_size.Height);
Graphics g_bmp = Graphics.FromImage(bitmap);
Brush brush = new SolidBrush(m_color);
g_bmp.Clear(System.Drawing.Color.FromArgb(0, 0, 0, 0));
g_bmp.DrawString(text, font, brush, new Rectangle(0, 0, m_size.Width, m_size.Height));
MemoryStream stream = new MemoryStream();
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
Array.Copy(stream.ToArray(), 54, pixBuffer, 0, pixBuffer.Length);
stream.Dispose();
brush.Dispose();
g_bmp.Dispose();
bitmap.Dispose();
}
/// <summary>
/// 在显示区指定位置显示文本(左下角为0,0 显示区高度为view.Height-15(15为标题栏高度))
/// </summary>
/// <param name="x">横坐标</param>
/// <param name="y">纵坐标</param>
/// <param name="m_text">显示文本</param>
private void glPrint(int x, int y, string text)
{
Font font = new Font("宋体", 9F);
this.BuildFont(text,out m_pixBuffer,font);
GL.glBindTexture(GL.GL_TEXTURE_2D,0); // 取消材质绑定
GL.glPushMatrix();
GL.glLoadIdentity();
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glPushMatrix();
GL.glLoadIdentity();
GL.gluOrtho2D(0.0, (double)this.Width, 0.0, (double)this.Height);
GL.glRasterPos2i(x, y);
GL.glEnable(GL.GL_BLEND); // 让绘制的文字透明
//GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
GL.glDrawPixels(m_size.Width, m_size.Height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, m_pixBuffer);
GL.glDisable(GL.GL_BLEND);
GL.glPopMatrix();
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glPopMatrix();
}
从别处粘贴的,研究一下!
补充:.NET技术 , C#