65.9K
CodeProject 正在变化。 阅读更多。
Home

OpenGL 单窗口 6 视图(Tao 和 C#)(多视图)

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.46/5 (8投票s)

2008年2月23日

CPOL

3分钟阅读

viewsIcon

59818

downloadIcon

3041

具有 6 个不同视图的 OpenGL 窗口

OpenGLOneWindow6ViewsDemo

引言

这个项目是基于我之前的项目 "OpenGL 3D Navigation2 With Tao and CSharp"。
它展示了如何在单个窗口上创建多个视图。我创建了同一个对象(立方体)的 6 个不同的视图。它也有 Glut 字体和 glRasterPos3f() 函数的例子。

背景

这个程序的目标是在单个窗口中使用多个视图。因此,我将稍微解释一下这个主题。我还为每个视图显示了字体。所以我将解释我是如何显示字体的。我不打算解释如何在 3D 空间中导航,因为这不是这个程序的主题。

这个程序 (想法) 基本上是现有想法的一个拷贝 - 一个窗口和多个视图。您可以在具有两个或多个玩家的游戏中使用多个视图。您也可以在需要从不同角度进行模拟的模拟中使用它。

将窗口分成多个视图非常简单。我将在下面展示如何做。具有挑战性的部分是在您的程序中使用它。

使用 Scissor (裁剪测试)

首先启用 SCISSOR_TEST

   Gl.glEnable(Gl.GL_SCISSOR_TEST);           // Enables SCISSOR 

其次,设置 ViewPort (视口)、窗口大小和位置

 Gl.glViewport(0, height, width, height);       // Set the viewPort
 Gl.glScissor(0, height, width, height);        // Divide the window

现在您可以为这个窗口编写代码了。我将相同的代码重复了六次,只是参数不同,因为我将窗口分成了 6 个视图。

 Gl.glMatrixMode(Gl.GL_PROJECTION);                          // Set the Matrix mode
 Gl.glLoadIdentity();                                      
 Glu.gluPerspective(75f, (float)width / (float)height, 0.10f, 500.0f); 	// Set the 
								// perspective
 Gl.glMatrixMode(Gl.GL_MODELVIEW);
 Gl.glLoadIdentity();
 Glu.gluLookAt(0.0, 0.0, 15.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); 	// Look at the 
								// new window at
								// this position
 drawCube();                         // Draw the cube 

完成后,请确保禁用 Scissor 测试。

Gl.glDisable(Gl.GL_SCISSOR_TEST);  

使用 Font (字体)

您需要一个小方法,带有一个 for 循环来渲染一个 string (文本)。for 循环遍历 string 并为每个字符设置 Font (字体) 类型和大小。在本例中,字体类型为 Times Roman,大小为 24。

// 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_24, c[i]);
    }
} 

然后设置要显示的 string (文本) 的位置,并使用要显示的 string 调用该方法。

Gl.glRasterPos3f(-15, 19 , -15);    // Set the position for the string (text)
text("Front");                      // Display the text "Front" 

Using the Code

关于演示

我在 Demo 文件夹中包含了 Tao.OpenGL.dllTao.freeGlut.dll。通常情况下,它应该可以顺利执行。但是,我没有在不同的操作系统或计算机上测试该演示,所以我不确定它是否能在您的机器上工作。您可能需要 Vista 和 .NET Framework 2.0。

关于源码

我使用了 Visual Studio 2005 (.NET Framework 2.0) C# 和 Tao (Tao.OpenGL, Tao.freeGlut)。如果您有 VS 2005 和 .NET Framework 2.0,您应该可以从 Visual Studio 运行该程序。运行程序后,您可以使用键盘和鼠标在 3D 空间中导航。

帮助

我包含了穿过 x、y 和 z 轴的线,以便更容易可视化。虚线部分是负轴。 (x,y,z) 的交点是 (0,0,0)。

线条颜色

  • 绿色代表 x 轴
  • 红色代表 y 轴
  • 蓝色代表 z 轴

旋转键 (glRotatef())

  • x - 绕 x 轴旋转
  • X - 向相反方向旋转
  • y - 绕 y 轴旋转
  • Y - 向相反方向旋转
  • z - 绕 z 轴旋转
  • Z - 向相反方向旋转
  • b,B 在 x 轴上旋转 (+/-)90 度
  • n,N 在 y 轴上旋转 (+/-)90 度
  • m,M 在 z 轴上旋转 (+/-)90 度

平移键 (glTranslatef())

  • left_key - 向左平移 (x 轴)
  • right_key - 向右平移 (x 轴)
  • up_key - 向上平移 (y 轴)
  • down_key - 向下平移 (y 轴)
  • page_up - 在 z 轴上平移 (放大)
  • page_down - 在 z 轴上平移 (缩小)

其他键

  • o,O 将所有内容恢复到起始位置
  • F1 - 移除/显示线条
  • F2 - 在 x、y、z 方向旋转/停止立方体

鼠标

  • LeftMouseDown - 在 x 和 y 方向平移立方体 (上/下, 左/右)
  • 鼠标滚轮 - 在 +/- z 方向平移立方体 (放大/缩小)

代码

using System;
using System.Collections.Generic;
using System.Text;
using Tao.OpenGl;
using Tao.FreeGlut;

namespace OpenGLOneWindow6Views
{
    sealed partial class OpenGLOneWindow6Views
    {
        // Declared static (no need for object reference)
        static float X = 0.0f;        // Translate screen to x direction (left or right)
        static float Y = 0.0f;        // Translate screen to y direction (up or down)
        static float Z = 0.0f;        // Translate screen to z direction (zoom in or out)
        static float rotX = 0.0f;    // Rotate screen on x axis 
        static float rotY = 0.0f;    // Rotate screen on y axis
        static float rotZ = 0.0f;    // Rotate screen on z axis

        static float rotLx = 0.0f;   // Translate screen by using  
				// the glulookAt function (left or right)
        static float rotLy = 0.0f;   // Translate screen by using  
				// the glulookAt function (up or down)
        static float rotLz = 0.0f;   // Translate screen by using  
				// the glulookAt function (zoom in or out)

        static bool lines = true;       // Display x,y,z lines (coordinate lines)
        static bool rotation = false;   // Rotate if F2 is pressed   
        static int old_x, old_y;        // Used for mouse event
        static int mousePressed;        // Check which botton is pressed

        // 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_24, c[i]);
            }
        }

          // Draw the lines (x,y,z)
        static void draw()
        {
            int width = Glut.glutGet(Glut.GLUT_WINDOW_WIDTH);  	// Get the windows width
            int height = Glut.glutGet(Glut.GLUT_WINDOW_HEIGHT);	// Get the windows height
            width = (width + 1) / 3;                           	// 3 OpenGL windows side 
							// by side
            height = (height + 1) / 2;                         	// 2 OpenGl windows up 
							// and down

            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); // Clear Color 
							// and Depth Buffer
           
            Gl.glEnable(Gl.GL_SCISSOR_TEST);     // Enable Scissor Test for multiple view
           
            // First window (Front view)
            Gl.glViewport(0, height, width, height);                  // Set the viewPort
            Gl.glScissor(0, height, width, height);                   // Divide the window
            setWindow(width, height);
            Glu.gluLookAt(0.0f , 0.0f , 15.0f , 0.0f, 0.0f, 
		0.0f, 0.0f, 1.0f, 0.0f);  // Look at the new window at this position  
            drawCube();        // Draw the cube
            Gl.glRasterPos3f(-15, 19, -15);    // Set the position for the string (text)
            text("Front");  // Display the text "Front"
           
            // Second Window (Back View)
            Gl.glViewport(0, 0, width, height);
            Gl.glScissor(0, 0, width, height);
            setWindow(width, height);
            Glu.gluLookAt(0.0f, 0.0f , -15.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            drawCube();
            Gl.glRasterPos3f(15.0f , 19.0f , 15.0f);
            text("Back");       

            // Third window (Right View)
            Gl.glViewport(width, height, width, height);
            Gl.glScissor(width, height, width, height);
            setWindow(width, height);
            Glu.gluLookAt(15.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            drawCube();
            Gl.glRasterPos3f(-15.0f, 19.0f, 15.0f);
            text("Right");

            // Forth Window (Left View)
            Gl.glViewport(width, 0, width, height);
            Gl.glScissor(width, 0, width, height);
            setWindow(width, height);
            Glu.gluLookAt(-15.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            drawCube();
            Gl.glRasterPos3f(15.0f, 19.0f, -15.0f);
            text("Left");

            // Fifth window (Upside down view)
            Gl.glViewport(2 * width, height, width, height);
            Gl.glScissor(2 * width, height, width, height);
            setWindow(width, height);
            Glu.gluLookAt(0.0f , 15.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f);
            drawCube();
            Gl.glRasterPos3f(-15.0f, -15.0f, -19.0f);
            text("Up");

            // Sixth window bottom up view
            Gl.glViewport(2 * width, 0, width, height);
            Gl.glScissor(2 * width, 0, width, height);
            setWindow(width, height);
            Glu.gluLookAt(0.0f, -15.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f);
            drawCube();
            Gl.glRasterPos3f(15.0f, 15.0f, -19.0f);
            text("Bottom");
         
            Gl.glDisable(Gl.GL_SCISSOR_TEST);
            Glut.glutSwapBuffers();
        }

        static void setWindow(float width, float height)
        {
            Gl.glMatrixMode(Gl.GL_PROJECTION); 	// Set the Matrix mode
            Gl.glLoadIdentity();
            Glu.gluPerspective(75.0f, (float)width / 
		(float)height, 0.10f, 500.0f);   // Set the perspective
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
        }
        static void drawCube()
        {
            // Clear the Color Buffer and Depth Buffer
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            Gl.glPushMatrix(); 	// It is important to push the Matrix 
				// before calling glRotatef and glTranslatef
            Gl.glRotatef(rotX, 1.0f, 0.0f, 0.0f);            // Rotate on x
            Gl.glRotatef(rotY, 0.0f, 1.0f, 0.0f);            // Rotate on y
            Gl.glRotatef(rotZ, 0.0f, 0.0f, 1.0f);            // Rotate on z

            if (rotation) // If F2 is pressed update x,y,z for rotation of the cube
            {
                rotX += 0.2f;
                rotY += 0.2f;
                rotZ += 0.2f;
            }

            Gl.glTranslatef(X, Y, Z);        	// Translates the screen left or right, 
					// up or down or zoom in zoom out

            if (lines)  // If F1 is pressed don't draw the lines
            {
                // Draw the positive side of the lines x,y,z
                Gl.glBegin(Gl.GL_LINES);
                Gl.glColor3f(0.0f, 1.0f, 0.0f);                // Green for x axis
                Gl.glVertex3f(0f, 0f, 0f);
                Gl.glVertex3f(10f, 0f, 0f);
                Gl.glColor3f(1.0f, 0.0f, 0.0f);                // Red for y axis
                Gl.glVertex3f(0f, 0f, 0f);
                Gl.glVertex3f(0f, 10f, 0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);                // Blue for z axis
                Gl.glVertex3f(0f, 0f, 0f);
                Gl.glVertex3f(0f, 0f, 10f);
                Gl.glEnd();

                // Dotted lines for the negative sides of x,y,z coordinates
                Gl.glEnable(Gl.GL_LINE_STIPPLE);	// Enable line stipple to use 
						// a dotted pattern for the lines
                Gl.glLineStipple(1, 0x0101);     // Dotted stipple pattern for the lines
                Gl.glBegin(Gl.GL_LINES);
                Gl.glColor3f(0.0f, 1.0f, 0.0f);                    // Green for x axis
                Gl.glVertex3f(-10f, 0f, 0f);
                Gl.glVertex3f(0f, 0f, 0f);
                Gl.glColor3f(1.0f, 0.0f, 0.0f);                    // Red for y axis
                Gl.glVertex3f(0f, 0f, 0f);
                Gl.glVertex3f(0f, -10f, 0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);                    // Blue for z axis
                Gl.glVertex3f(0f, 0f, 0f);
                Gl.glVertex3f(0f, 0f, -10f);
                Gl.glEnd();
                Gl.glDisable(Gl.GL_LINE_STIPPLE);             // Disable the line stipple
            }

                // Drawing 3D cube
                // Front side 
                Gl.glBegin(Gl.GL_POLYGON);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);             // Set color to blue
                Gl.glVertex3f(3.0f, 3.0f, 3.0f);
                Gl.glColor3f(1.0f, 0.0f, 0.0f);             // Set color to red
                Gl.glVertex3f(3.0f, -3.0f, 3.0f);
                Gl.glColor3f(0.0f,0.0f, 1.0f);           
                Gl.glVertex3f(-3.0f, -3.0f, 3.0f);
                Gl.glColor3f(1.0f, 0.0f, 0.0f);             
                Gl.glVertex3f(-3.0f, 3.0f, 3.0f);
                Gl.glEnd();

                // Back side
                Gl.glBegin(Gl.GL_POLYGON);
                Gl.glColor3f(0.5f, 0.0f, .0f);            
                Gl.glVertex3f(3.0f, 3.0f, -3.0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(3.0f, -3.0f, -3.0f);
                Gl.glColor3f(0.5f, 0.0f, 0.0f);
                Gl.glVertex3f(-3.0f, -3.0f, -3.0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(-3.0f, 3.0f, -3.0f);
                Gl.glEnd();

                // Right side
                Gl.glBegin(Gl.GL_POLYGON);
                Gl.glColor3f(0.0f, 1.0f, 0.0f);        
                Gl.glVertex3f(3.0f, 3.0f, 3.0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f); 
                Gl.glVertex3f(3.0f, 3.0f, -3.0f);
                Gl.glColor3f(0.0f, 1.0f, 0.0f);
                Gl.glVertex3f(3.0f, -3.0f, -3.0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(3.0f, -3.0f, 3.0f);
                Gl.glEnd();
                
                // Left Side
                Gl.glBegin(Gl.GL_POLYGON);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(-3.0f, 3.0f, 3.0f);
                Gl.glColor3f(0.0f, 1.0f, 0.0f);
                Gl.glVertex3f(-3.0f, -3.0f, 3.0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(-3.0f, -3.0f, -3.0f);
                Gl.glColor3f(0.0f, 1.0f, 0.0f);
                Gl.glVertex3f(-3.0f, 3.0f, -3.0f);
                Gl.glEnd();
                
                // Upside
                Gl.glBegin(Gl.GL_POLYGON);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(3.0f, 3.0f, 3.0f);
                Gl.glColor3f(1.0f, 1.0f, 0.0f);
                Gl.glVertex3f(3.0f, 3.0f, -3.0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(-3.0f, 3.0f, -3.0f);
                Gl.glColor3f(1.0f, 1.0f, 0.0f);
                Gl.glVertex3f(-3.0f, 3.0f, 3.0f);
                Gl.glEnd();

                // Bottom
                Gl.glBegin(Gl.GL_POLYGON);
                Gl.glColor3f(1.0f, 1.0f, 0.0f);
                Gl.glVertex3f(3.0f, -3.0f, 3.0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(3.0f, -3.0f, -3.0f);
                Gl.glColor3f(1.0f, 1.0f, 0.0f);
                Gl.glVertex3f(-3.0f, -3.0f, -3.0f);
                Gl.glColor3f(0.0f, 0.0f, 1.0f);
                Gl.glVertex3f(-3.0f, -3.0f, 3.0f);
                Gl.glEnd();
                Gl.glColor3f(1.0f, 0.5f, 0.5f);    
           
                Glut.glutPostRedisplay();   	// Redraw the scene
                Gl.glPopMatrix();            	// Don't forget to pop the Matrix
        }
// This function is used for the navigation keys
        public static void keyboard(byte key, int x, int y)
        {
            switch (key)
            {
                // x,X,y,Y,z,Z uses the glRotatef() function
                case 120:    // x           	// Rotates screen on x axis 
                    rotX -= 2.0f;
                    break;
                case 88:    // X            	// Opposite way 
                    rotX += 2.0f;
                    break;
                case 121:    // y            	// Rotates screen on y axis
                    rotY -= 2.0f;
                    break;
                case 89:    // Y           	// Opposite way
                    rotY += 2.0f;
                    break;
                case 122:    // z            	// Rotates screen on z axis
                    rotZ -= 2.0f;
                    break;
                case 90:    // Z            	// Opposite way
                    rotZ += 2.0f;
                    break;

                // j,J,k,K,l,L uses the gluLookAt function for navigation
                case 106:   // j
                    rotLx -= 2.0f;
                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glLoadIdentity();
                    Glu.gluLookAt(rotLx, rotLy, 15.0 + rotLz, 
				0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
                    break;
                case 74:    // J
                    rotLx += 2.0f;
                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glLoadIdentity();
                    Glu.gluLookAt(rotLx, rotLy, 15.0 + rotLz, 0.0, 
				0.0, 0.0, 0.0, 1.0, 0.0);
                    break;
                case 107:   // k
                    rotLy -= 2.0f;
                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glLoadIdentity();
                    Glu.gluLookAt(rotLx, rotLy, 15.0 + rotLz, 0.0, 
				0.0, 0.0, 0.0, 1.0, 0.0);
                    break;
                case 75:    // K
                    rotLy += 2.0f;
                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glLoadIdentity();
                    Glu.gluLookAt(rotLx, rotLy, 15.0 + rotLz, 0.0, 
				0.0, 0.0, 0.0, 1.0, 0.0);
                    break;
                case 108: 	// (l) It has a special case when the rotLZ becames less 
			// than -15 the screen is viewed from the opposite side
                    	// therefore this if statement below does not allow 
			// rotLz be less than -15
                    if (rotLz + 14 >= 0)
                        rotLz -= 2.0f;
                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glLoadIdentity();
                    Glu.gluLookAt(rotLx, rotLy, 15.0 + rotLz, 0.0, 
				0.0, 0.0, 0.0, 1.0, 0.0);
                    break;
                case 76:    // L
                    rotLz += 2.0f;
                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glLoadIdentity();
                    Glu.gluLookAt(rotLx, rotLy, 15.0 + rotLz, 
				0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
                    break;
                case 98:    // b        // Rotates on x axis by -90 degree
                    rotX -= 90.0f;
                    break;
                case 66:    // B        // Rotates on y axis by 90 degree
                    rotX += 90.0f;
                    break;
                case 110:    // n       // Rotates on y axis by -90 degree
                    rotY -= 90.0f;
                    break;
                case 78:    // N        // Rotates on y axis by 90 degree
                    rotY += 90.0f;
                    break;
                case 109:    // m       // Rotates on z axis by -90 degree
                    rotZ -= 90.0f;
                    break;
                case 77:    // M        // Rotates on z axis by 90 degree
                    rotZ += 90.0f;
                    break;
                case 111:    // o       // Resets all parameters
                case 80:    // O        // Displays the cube in the starting position
                    rotation = false;
                    X = Y = 0.0f;
                    Z = 0.0f;
                    rotX = 0.0f;
                    rotY = 0.0f;
                    rotZ = 0.0f;
                    rotLx = 0.0f;
                    rotLy = 0.0f;
                    rotLz = 0.0f;
                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glLoadIdentity();
                    Glu.gluLookAt(rotLx, rotLy, 15.0f + rotLz, 0.0f, 0.0f, 
				0.0f, 0.0f, 1.0f, 0.0f);
                    break;
            }
            Glut.glutPostRedisplay();    	// Redraw the scene
        }

        // Called on special key pressed
        private static void specialKey(int key, int x, int y)
        {
            // Check which key is pressed
            switch (key)
            {
                case Glut.GLUT_KEY_LEFT:    	// Rotate on x axis
                    X -= 2.0f;
                    break;
                case Glut.GLUT_KEY_RIGHT:    	// Rotate on x axis (opposite)
                    X += 2.0f;
                    break;
                case Glut.GLUT_KEY_UP:       	// Rotate on y axis 
                    Y += 2.0f;
                    break;
                case Glut.GLUT_KEY_DOWN:    	// Rotate on y axis (opposite)
                    Y -= 2.0f;
                    break;
                case Glut.GLUT_KEY_PAGE_UP:  	// Rotate on z axis
                    Z -= 2.0f;
                    break;
                case Glut.GLUT_KEY_PAGE_DOWN:	// Rotate on z axis (opposite)
                    Z += 2.0f;
                    break;
                case Glut.GLUT_KEY_F1:      	// Enable/Disable coordinate lines
                    lines = !lines;
                    break;
                case Glut.GLUT_KEY_F2:      	// Enable/Disable automatic rotation
                    rotation = !rotation;
                    break;
                default:
                    break;
            }
            Glut.glutPostRedisplay();        	// Redraw the scene
        }

        // Capture the mouse click event 
        static void processMouseActiveMotion(int button, int state, int x, int y)
        {
            mousePressed = button;          	// Capture which mouse button is down
            old_x = x;                      	// Capture the x value
            old_y = y;                      	// Capture the y value
        }

        // Translate the x,y windows coordinates to OpenGL coordinates
        static void processMouse(int x, int y)
        {
            if ((mousePressed == 0))    	// If left mouse button is pressed
            {
                X = (x - old_x) / 15;     	// I did divide by 15 to adjust for a 
					// nice translation 
                Y = -(y - old_y) / 15;
            }

            Glut.glutPostRedisplay();
        }

        // Get the mouse wheel direction
        static void processMouseWheel(int wheel, int direction, int x, int y)
        {
            Z += direction;  // Adjust the Z value 

            Glut.glutPostRedisplay();
        }
        // Initialize the OpenGL window
        static void init()
        {
            Gl.glShadeModel(Gl.GL_SMOOTH);      	// Set the shading model to smooth 
            Gl.glClearColor(0, 0, 0, 1.0f);     	// Clear the Color
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);    // Clear the 
							// Color and Depth Buffer
            Gl.glClearDepth(1.0f);          	// Set the Depth buffer value (ranges[0,1])
            Gl.glEnable(Gl.GL_DEPTH_TEST);  	// Enable Depth test
            Gl.glDepthFunc(Gl.GL_LEQUAL);   	// If two objects on the same 
					// coordinate show the first drawn
            Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);
            Gl.glDisable(Gl.GL_CULL_FACE);
        }

        // This function is called whenever the window size is changed
        static void reshape(int w, int h)
        {
            Gl.glClearColor(0, 0, 0, 0.0f);
            Gl.glViewport(0, 0, w, h);                // Set the viewport
            Gl.glMatrixMode(Gl.GL_PROJECTION);        // Set the Matrix mode
            Gl.glLoadIdentity();
            Glu.gluPerspective(75f, (float)w / (float)h, 0.10f, 500.0f);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
            Glu.gluLookAt(rotLx, rotLy, 15.0f + rotLz, 
			0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
        }  
        // Main Starts
        static void Main(string[] args)
        {
            Glut.glutInit();           			// Initialize glut
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB); // Setup display 
					// mode to double buffer and RGB color
            Glut.glutInitWindowSize(600, 600);		// Set the screen size
            Glut.glutCreateWindow("OpenGL Multiple View"); 	// Windows capture
            init();     // Call init()
            Glut.glutReshapeFunc(reshape);
            Glut.glutDisplayFunc(draw);
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(keyboard)); 	// Set windows 
								// key callback     
            Glut.glutSpecialFunc(new Glut.SpecialCallback(specialKey));  // Set windows 
							// to specialKey callback
            Glut.glutMouseFunc(new Glut.MouseCallback
		(processMouseActiveMotion));   // Set window's to Mouse callback
            Glut.glutMotionFunc(new Glut.MotionCallback
			(processMouse)); 	// Set window's to motion callback
            Glut.glutMouseWheelFunc(new Glut.MouseWheelCallback
			(processMouseWheel));// Set window's to mouse motion callback
          
            Glut.glutMainLoop();
        }
   }
}
© . All rights reserved.