码迷,mamicode.com
首页 > 其他好文 > 详细

17、事例十七:立体文字和平面文字

时间:2019-08-15 21:13:40      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:sid   enable   mode   sla   sha   nta   sphere   use   ide   

namespace sharpGLTest17
{
    public partial class Form1 : Form
    {
        private float rotation = 0.0f;

        public Form1()
        {
            InitializeComponent();
        }

        private void openGLControl_OpenGLInitialized(object sender, EventArgs e)
        {
            OpenGL gl = openGLControl.OpenGL;

            float[] global_ambient = new float[] { 0.5f, 0.5f, 0.5f, 1.0f };
            float[] light0pos = new float[] { 0.0f, 0.0f, 10.0f, 1.0f };    //光源位置
            float[] light0ambient = new float[] { 0.2f, 0.2f, 0.2f, 1.0f }; //环境光参数
            float[] light0diffuse = new float[] { 0.9f, 0.9f, 0.3f, 1.0f }; //漫射光参数
            float[] light0specular = new float[] { 0.8f, 0.8f, 0.8f, 1.0f };//镜面反射

            float[] lmodel_ambient = new float[] { 0.2f, 0.2f, 0.2f, 1.0f };
            gl.LightModel(OpenGL.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

            gl.LightModel(OpenGL.GL_LIGHT_MODEL_AMBIENT, global_ambient);

            gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, light0pos);
            gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_AMBIENT, light0ambient);
            gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_DIFFUSE, light0diffuse);
            gl.Light(OpenGL.GL_LIGHT0, OpenGL.GL_SPECULAR, light0specular);

            gl.Enable(OpenGL.GL_LIGHTING);
            gl.Enable(OpenGL.GL_LIGHT0);

            gl.ShadeModel(OpenGL.GL_SMOOTH);
            gl.ClearColor(0, 0, 0, 0);
        }

        private void openGLControl_Resized(object sender, EventArgs e)
        {
            OpenGL gl = openGLControl.OpenGL;
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Perspective(60.0f, (double)Width / (double)Height, 0.01, 100.0);
            gl.LookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }

        private void openGLControl_OpenGLDraw(object sender, PaintEventArgs e)
        {
            OpenGL gl = openGLControl.OpenGL;
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();

            gl.Translate(-1f, 0.0f, 0f);
            gl.Rotate(rotation, 1f, 0f, 0.0f);

            gl.DrawText3D("Arial", 32, 0, 0.3f, "Hello!");

            rotation -= 3.0f;

            gl.DrawText(20, 20, 1,
                1, 1, "Courier New", 12,
                "this is a test text.");
            gl.Flush();
        }

    }
}


void drawSphere(OpenGL gl,double radius,int segx,int segy,bool isLines)
{
    gl.PushMatrix();
    gl.Translate(2f, 1f, 2f);
    var sphere = gl.NewQuadric();
    if (isLines)
        gl.QuadricDrawStyle(sphere, OpenGL.GL_LINES);
    else
        gl.QuadricDrawStyle(sphere, OpenGL.GL_QUADS);
    
    gl.QuadricNormals(sphere, OpenGL.GLU_SMOOTH);
    gl.QuadricOrientation(sphere, (int)OpenGL.GLU_OUTSIDE);
    gl.QuadricTexture(sphere, (int)OpenGL.GLU_FALSE);
    gl.Sphere(sphere, radius, segx, segy);
    gl.DeleteQuadric(sphere);
    gl.PopMatrix();
}

 

17、事例十七:立体文字和平面文字

标签:sid   enable   mode   sla   sha   nta   sphere   use   ide   

原文地址:https://www.cnblogs.com/lotuses/p/11360343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!