Example #1
0
        public static void DrawPolygon(Point3d[] points, Point3d[] textureCoords, string textureName)
        {
            PickTexture(textureName);
            Gl.glBegin(Gl.GL_POLYGON);
            for (int i = 0; i <= points.Length - 1; i++)
            {
                if (textureCoords[i] != null)
                {
                    Gl.glTexCoord3d(textureCoords[i].X, textureCoords[i].Y, textureCoords[i].Z);
                }

                Gl.glVertex3d(points[i].X, points[i].Y, points[i].Z);
            }
            DrawingService.UnloadTexture();
            Gl.glEnd();
        }
Example #2
0
        public static void DrawRim(Point3d p1, Point3d p2, double size = 1, double radius = 1,
                                   string textureName = null)
        {
            for (int i = 360; i >= 1; i--)
            {
                if (textureName != null)
                {
                    DrawingService.PickTexture(textureName);
                }

                Gl.glBegin(Gl.GL_POLYGON);
                double x1 = Math.Cos(Angle3d.DegreeToRadian(i));
                double y1 = Math.Sin(Angle3d.DegreeToRadian(i));
                double x2 = Math.Cos(Angle3d.DegreeToRadian(i - 3));
                double y2 = Math.Sin(Angle3d.DegreeToRadian(i - 3));

                Gl.glNormal3d(x1, y1, y1);
                Gl.glTexCoord3d(x2, 0, 0);
                //Gl.glNormal3b(0, 1, 0);
                Gl.glVertex3d(x2 * size + p2.X, y2 * radius + p2.Y, y2 * radius + p2.Z);

                Gl.glNormal3d(x1, y1, y1);
                Gl.glTexCoord3d(x2, 1, 0);
                //Gl.glNormal3b(0, 1, 0);
                Gl.glVertex3d(x2 * size + p1.X, y2 * radius + p1.Y, y2 * radius + p1.Z);

                Gl.glNormal3d(x1, y1, y1);
                Gl.glTexCoord3d(x1, 1, 0);
                //Gl.glNormal3b(0, 1, 0);
                Gl.glVertex3d(x1 * size + p1.X, y1 * radius + p1.Y, y1 * radius + p1.Z);

                Gl.glNormal3d(x1, y1, y1);
                Gl.glTexCoord3d(x1, 0, 0);
                //Gl.glNormal3b(0, 1, 0);
                Gl.glVertex3d(x1 * size + p2.X, y1 * radius + p2.Y, y1 * radius + p2.Z);
                Gl.glEnd();
                DrawingService.UnloadTexture();
            }
        }
Example #3
0
        public static void Init(int width, int height)
        {
            DrawingService.Resize(width, height);
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DEPTH | Glut.GLUT_DOUBLE);

            Gl.glViewport(0, 0, width, height);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
            Gl.glClearColor(0f, 0f, 0f, 1f);

            /// TODO:
            /// Добавить включение света
            /// Добавить проверку глубины
            /// Включить (солнце)
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glEnable(Gl.GL_LIGHTING);
            //Gl.glEnable(Gl.GL_FOG);
            //Gl.glDepthFunc(Gl.GL_LEQUAL);
            Gl.glEnable(Gl.GL_NORMALIZE);
            Gl.glEnable(Gl.GL_CULL_FACE);
            //Gl.glEnable(Gl.GL_MULTISAMPLE_ARB);
            //Gl.glEnable(Gl.GL_COLOR_MATERIAL);

            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, new float[4] {
                12, 10, 6, 1
            });
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, new float[3] {
                1f, 1f, 1f
            });
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, new float[3] {
                1f, 1f, 1f
            });
            //Gl.glLightf(Gl.GL_LIGHT0, Gl.GL_LINEAR_ATTENUATION, 0.01f);
            Gl.glEnable(Gl.GL_LIGHT0);

            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_POSITION, new float[4] {
                0, 10, 0, 0
            });
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_SPOT_DIRECTION, new float[3] {
                0, 0, 0
            });
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_SPECULAR, new float[3] {
                0.7f, 0.7f, 0.7f
            });
            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_AMBIENT, new float[3] {
                0.7f, 0.7f, 0.7f
            });
            Gl.glEnable(Gl.GL_LIGHT1);

            Gl.glLightf(Gl.GL_LIGHT1, Gl.GL_LINEAR_ATTENUATION, 0.005f);

            //Gl.glLightModelf(Gl.GL_LIGHT_MODEL_TWO_SIDE, Gl.GL_TRUE);
            Gl.glLightModelfv(Gl.GL_LIGHT_MODEL_AMBIENT, new float[3] {
                0.7f, 0.7f, 0.7f
            });
            //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_SPECULAR, new float[3] { 0.2f, 0.2f, 0.2f });

            //Gl.glFogi(Gl.GL_FOG_MODE, Gl.GL_LINEAR);
            //Gl.glFogfv(Gl.GL_FOG_COLOR, new float[4] { 0.6f, 0.5f, 0.5f, 1f });
            //Gl.glFogf(Gl.GL_FOG_DENSITY, 0.35f);
            //Gl.glHint(Gl.GL_FOG_HINT, Gl.GL_FASTEST);

            DrawingService.Width  = width;
            DrawingService.Height = height;
            DrawingService.Ready  = true;

            DrawingService.Clear();
            DrawingService.LoadLevel();

            DrawingService.Textures = new Dictionary <string, Texture>();
            InitTextures();
        }