Bridge class to the wgl functions
Example #1
0
        public void Draw()
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            GL.glLoadIdentity();
            GL.glTranslatef(-1.0f, -1.0f, -6.0f);

            drawAxises();
            updateTimer();

            GL.glTranslated(0.5f, 0.0f, 0.5f);

            GL.glRotatef(m_RotateAngle, 0, 1.0f, 0); // y axis rotate
            GL.glRotatef(m_FallAngle, 1, 0, 0);      // x axis rotate

            GL.glTranslated(-0.5f, 0.0f, -0.5f);
            GL.glEnable(GL.GL_TEXTURE_2D);
            GL.glBindTexture(GL.GL_TEXTURE_2D, m_Texture[0]);

            drawDreidel();
            GL.glDisable(GL.GL_TEXTURE_2D);
            GL.glFlush();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #2
0
        protected virtual void InitializeGL()
        {
            m_uint_HWND = (uint)p.Handle.ToInt32();
            m_uint_DC   = WGL.GetDC(m_uint_HWND);

            // Not doing the following WGL.wglSwapBuffers() on the DC will
            // result in a failure to subsequently create the RC.
            WGL.wglSwapBuffers(m_uint_DC);

            WGL.PIXELFORMATDESCRIPTOR pfd = new WGL.PIXELFORMATDESCRIPTOR();
            WGL.ZeroPixelDescriptor(ref pfd);
            pfd.nVersion   = 1;
            pfd.dwFlags    = (WGL.PFD_DRAW_TO_WINDOW | WGL.PFD_SUPPORT_OPENGL | WGL.PFD_DOUBLEBUFFER);
            pfd.iPixelType = (byte)(WGL.PFD_TYPE_RGBA);
            pfd.cColorBits = 32;
            pfd.cDepthBits = 32;
            pfd.iLayerType = (byte)(WGL.PFD_MAIN_PLANE);

            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            //for Stencil support

            pfd.cStencilBits = 32;

            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            int pixelFormatIndex = 0;

            pixelFormatIndex = WGL.ChoosePixelFormat(m_uint_DC, ref pfd);
            if (pixelFormatIndex == 0)
            {
                MessageBox.Show("Unable to retrieve pixel format");
                return;
            }

            if (WGL.SetPixelFormat(m_uint_DC, pixelFormatIndex, ref pfd) == 0)
            {
                MessageBox.Show("Unable to set pixel format");
                return;
            }
            //Create rendering context
            m_uint_RC = WGL.wglCreateContext(m_uint_DC);
            if (m_uint_RC == 0)
            {
                MessageBox.Show("Unable to get rendering context");
                return;
            }
            if (WGL.wglMakeCurrent(m_uint_DC, m_uint_RC) == 0)
            {
                MessageBox.Show("Unable to make rendering context current");
                return;
            }



            initRenderingGL();
        }
Example #3
0
        /// <summary>
        ///	Event handler called when the form is loaded.  It retrieves the controls
        ///	window handle and device context and creates the rendering context.
        /// </summary>
        protected virtual void InitializeGL(object sender, EventArgs e)
        {
            m_uint_HWND = (uint)this.Handle.ToInt32();
            m_uint_DC   = WGL.GetDC(m_uint_HWND);
            // CAUTION: Not doing the following WGL.wglSwapBuffers() on the DC will
            // result in a failure to subsequently create the RC.
            WGL.wglSwapBuffers(m_uint_DC);

            //Get the pixel format
            WGL.PIXELFORMATDESCRIPTOR pfd = new WGL.PIXELFORMATDESCRIPTOR();
            WGL.ZeroPixelDescriptor(ref pfd);
            pfd.nVersion   = 1;
            pfd.dwFlags    = (WGL.PFD_DRAW_TO_WINDOW | WGL.PFD_SUPPORT_OPENGL | WGL.PFD_DOUBLEBUFFER);
            pfd.iPixelType = (byte)(WGL.PFD_TYPE_RGBA);
            pfd.cColorBits = 32;
            pfd.cDepthBits = 32;
            pfd.iLayerType = (byte)(WGL.PFD_MAIN_PLANE);

            int pixelFormatIndex = 0;

            pixelFormatIndex = WGL.ChoosePixelFormat(m_uint_DC, ref pfd);
            if (pixelFormatIndex == 0)
            {
                MessageBox.Show("Unable to retrieve pixel format");
                return;
            }

            if (WGL.SetPixelFormat(m_uint_DC, pixelFormatIndex, ref pfd) == 0)
            {
                MessageBox.Show("Unable to set pixel format");
                return;
            }
            //Create rendering context
            m_uint_RC = WGL.wglCreateContext(m_uint_DC);
            if (m_uint_RC == 0)
            {
                MessageBox.Show("Unable to get rendering context");
                return;
            }
            if (WGL.wglMakeCurrent(m_uint_DC, m_uint_RC) == 0)
            {
                MessageBox.Show("Unable to make rendering context current");
                return;
            }
            //Set up OpenGL related characteristics
            ResizeGL(null, null);
            GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.glEnable(GL.GL_DEPTH_TEST);
            GL.glDepthFunc(GL.GL_LEQUAL);
            //GL.glEnable(GL.GL_CULL_FACE);
            GL.glCullFace(GL.GL_BACK);
        }
Example #4
0
        /// <summary>
        /// OnPaint is called when the control needs to be refreshed.  OpenGL
        /// specific drawing should be done by overriding this method.
        /// </summary>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            //Just clear the screen
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            GL.glLoadIdentity();
            GL.glFlush();

            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #5
0
        public void Draw()
        {
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
            GL.glMatrixMode(GL.GL_MODELVIEW);
            GL.glLoadIdentity();

            GL.glTranslatef(0.0f, -1.5f, -6.0f);
            GL.glRotatef(10, 1.0f, 0.0f, 0.0f);
            GL.glRotatef(-tank.rotation, 0.0f, 1.0f, 0.0f);
            GL.glRotatef(-tank.turretRotation, 0.0f, 1.0f, 0.0f);
            GL.glTranslatef(-tank.posX, 0.0f, -tank.posZ);

            //DrawAxes();
            DrawAll();

            //LIGHT - before transforms
            //  hence it is in const position
            GL.glPushMatrix();
            GL.glEnable(GL.GL_LIGHTING);
            GL.glEnable(GL.GL_LIGHT0);
            GL.glTranslatef(0, 11, -35);
            float[] ambient = { 0, 0, 0.3f, 1 };

            ambient[0] = 0.2f;

            float[] diffuse  = { 1, 1, 1, 1 };
            float[] specular = { 0.5f, 0.5f, 0.5f, 1f };
            float[] pos      = { 0, 1f, -0.5f, 0 };
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, ambient);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, diffuse);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specular);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos);

            GL.glPopMatrix();

            tank.drawSelf();

            DrawBullets();
            //REFLECTION e

            if (networkconnected)
            {
                enemytank.drawSelf();
            }

            update();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #6
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (m_uint_RC != 0)
         {
             WGL.wglDeleteContext(m_uint_RC);
             m_uint_RC = 0;
             //Don't release DC!! don't know why, but bad!
         }
         if (components != null)
         {
             components.Dispose();
         }
     }
     base.Dispose(disposing);
 }
Example #7
0
        /// <summary>
        /// Event handler called when the control is resized.
        /// </summary>
        protected virtual void ResizeGL(object sender, EventArgs e)
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }
            if (this.Width == 0 || this.Height == 0)
            {
                return;
            }
            WGL.wglMakeCurrent(m_uint_DC, m_uint_RC);
            GL.glViewport(0, 0, this.Width, this.Height);

            GL.glMatrixMode(GL.GL_PROJECTION);
            GL.glLoadIdentity();
            GLU.gluPerspective(60.0, ((double)(this.Width) / (double)(this.Height)), 1.0, 1000.0);
            GL.glMatrixMode(GL.GL_MODELVIEW);
            GL.glLoadIdentity();
        }
// ############################################################################
// ############################################################################
// ############################################################################
// ############################################################################

// ============================================================================
// The following can be used as an example of how to initialize OpenGL
// rendering.  A System.Windows.Forms object can use a window handle acquired
// from (uint)((this.Handle).ToInt32()) as the "HWND" parameter.
//
// Here is a crude illustration of the use of WGL.DemoInitOpenGL() by a Form:
//
//    // ----------------------------------------------------------------------
//    public static uint            m_uint_HWND = 0;
//    public static uint            m_uint_DC   = 0;
//    public static uint            m_uint_RC   = 0;
//
//    protected override void OnPaintBackground( PaintEventArgs e )
//    {
//    // This overrides the System.Windows.Forms.Control protected method
//    // "OnPaintBackground()" so that we don't clear the client area of
//    // this form window -- so the OpenGL doesn't flicker on each frame.
//    }
//
//    protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
//    {
//    if (0 == m_uint_RC)
//      {
//      m_uint_HWND = (uint)((this.Handle).ToInt32());
//      WGL.DemoInitOpenGL( m_uint_HWND, ref m_uint_DC, ref m_uint_RC );
//      }
//    if (0 != m_uint_RC)
//      {
//      WGL.DemoOpenGLDraw( this.Size.Width, this.Size.Height,  m_uint_DC );
//      }
//    System.Threading.Thread.Sleep( 10 ); // 10 msec --> 100 frames per second, max.
//    Invalidate(false); // Force OnPaint() to get called again.
//    }
//    // ----------------------------------------------------------------------
//
// ============================================================================
        public static void DemoInitOpenGL
        (
            uint uint_HWND,       // in
            ref uint ref_uint_DC, // out
            ref uint ref_uint_RC  // out
        )
        {
            ref_uint_DC = WGL.GetDC(uint_HWND);

            // CAUTION: Not doing the following WGL.wglSwapBuffers() on the DC will
            // result in a failure to subsequently create the RC.
            WGL.wglSwapBuffers(ref_uint_DC);

            WGL.DemoCreateRenderingContext(ref ref_uint_DC, ref ref_uint_RC);

            if (0 == ref_uint_RC)
            {
                WGL.MessageBox(0, "Failed to create OpenGL Rendering Context (RC)",
                               "WGL.DemoInitOpenGL() : ERROR", MB_OK);
                return;
            }
        }
Example #9
0
        public void Draw()
        {
            // MAIN FUNCTION
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                MessageBox.Show("No screen dimension. Drawing canceled");
                return;
            }

            // GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            GL.glLoadIdentity();

            GL.glTranslatef(0.0f, 0.0f, -6.0f);

            GL.glRotatef(90.0f - GlobalProperties.CurrentVerticalViewAngle, -1.0f, 0.0f, 0.0f);
            GL.glRotatef(GlobalProperties.CurrentHorizontalViewAngle, 0.0f, 0.0f, 1.0f);

            GL.glEnable(GL.GL_LIGHTING);
            if (GlobalProperties.LightBeamOn)
            {
                GL.glEnable(GL.GL_LIGHT0);
            }
            else
            {
                GL.glDisable(GL.GL_LIGHT0);
            }

            // DrawAxes();
            DrawAll();
            GL.glDisable(GL.GL_LIGHTING);

            GL.glFlush();

            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #10
0
        public void Draw()
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            GL.glLoadIdentity();
            GLU.gluLookAt(ScrollValue[1], 1, 10, 0, 0, 0, 0, 1, 0);
            GL.glTranslated(0, 0, -6);
            GL.glRotated(20, 1, 0, 0);

            //DrawAxes(Color.Red, Color.Green, Color.Blue);

            UpdateScrollInput();
            DrawLights();
            DrawMirrors();
            DrawFigures();

            GL.glFlush();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #11
0
        public void Draw()
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            GL.glLoadIdentity();

            GL.glTranslatef(0.0f, 0.0f, -3.0f); // Translate 3 Units Into The Screen

            createLightning();

            switch (m_gyroState)
            {
            case eGyroState.Rotating:
                gyroRotatingTransform();
                break;

            case eGyroState.Slowing:
                gyroSlowingTransform();
                break;

            case eGyroState.Stoping:
                gyroStopingTransform();
                break;
            }

            //drawAxes();
            drawGyro();

            GL.glFlush();

            WGL.wglSwapBuffers(m_uint_DC);
        }
        public void Draw()
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            //TRIVIAL
            GL.glViewport(0, 0, Width, Height);
            GL.glLoadIdentity();
            GL.glEnable(GL.GL_NORMALIZE);

            GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2],
                          ScrollValue[3], ScrollValue[4], ScrollValue[5],
                          ScrollValue[6], ScrollValue[7], ScrollValue[8]);



            pos[0] = light_position[0] = ScrollValue[9];
            pos[1] = light_position[1] = ScrollValue[10];
            pos[2] = light_position[2] = ScrollValue[11];
            pos[3] = light_position[3] = 0;

            light_position_reflected[0] = -ScrollValue[9];
            light_position_reflected[1] = -ScrollValue[10];
            light_position_reflected[2] = -ScrollValue[11];
            light_position[3]           = 0;

            GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position);
            GL.glEnable(GL.GL_LIGHT0);

            GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, light_position);
            GL.glEnable(GL.GL_LIGHT1);

            //beascender look angle
            GL.glTranslatef(0.0f, -50.0f, -340.0f); //how far from the lake
            GL.glTranslatef(0.0f, 1.0f, 0.0f);      //height from the lake
            GL.glRotatef(25, 1.0f, 0, 0);           //look at lake angle

            GL.glRotatef(xAngle, 1.0f, 0.0f, 0.0f);
            if (checkBox)
            {
                GL.glRotatef((float)spirala * 0.018f, 0.0f, 1.0f, 0.0f);
                GL.glRotatef((float)speed * 0.008f, 1.0f, 1.0f, 0.0f);
                GL.glRotatef((float)speed * 0.008f, 0.0f, 1.0f, 1.0f);
                GL.glRotatef((float)speed * -0.005f, 1.0f, 0.0f, 1.0f);
            }
            GL.glRotatef(yAngle, 0.0f, 1.0f, 0.0f);
            GL.glRotatef(zAngle, 0.0f, 0.0f, 1.0f);
            if (checkBox)
            {
                GL.glTranslatef(xShift, yShift + (float)-speed * 0.18f, zShift);
            }
            GL.glTranslatef(xShift, yShift, zShift);



            /*
             *
             * Reflection drawing area start here
             *
             */

            GL.glPushMatrix();

            GL.glEnable(GL.GL_BLEND);
            GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

            //draw only to STENCIL buffer
            GL.glEnable(GL.GL_STENCIL_TEST);
            GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
            GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF);
            GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE);
            GL.glDisable(GL.GL_DEPTH_TEST);

            Drawlake();//Draw area when we want to see reflect

            // restore regular seascendings
            GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE);
            GL.glEnable(GL.GL_DEPTH_TEST);

            // reflection is drawn only where STENCIL buffer value equal to 1
            GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF);
            GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);


            /*
             * draw reflected scene
             */

            GL.glScalef(1, -1, 1); //swap axes down


            GL.glPushMatrix();
            DrawTexturedCube();

            //reflected penguin
            drawPenguin();

            draw_sun();
            draw_moon();
            GL.glPopMatrix();


            GL.glPopMatrix();
            GL.glEnable(GL.GL_LIGHTING);

            Drawlake();

            GL.glDisable(GL.GL_LIGHTING);


            GL.glStencilFunc(GL.GL_NOTEQUAL, 1, 0xFFFFFFFF);
            GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);

            GL.glDepthMask((byte)GL.GL_FALSE);
            GL.glDepthMask((byte)GL.GL_TRUE);

            drawFloorTextured();

            draw_sun();
            draw_moon();


            GL.glDisable(GL.GL_STENCIL_TEST);

            DrawTexturedCube();    //SKY BOX



            /*
             *
             * paint main scene area - start here
             *
             */

            // drawaxe();



            GL.glShadeModel(GL.GL_FLAT);

            GL.glEnable(GL.GL_LIGHTING);

            //Main Penguin
            drawPenguin();



            /////////

            GL.glDisable(GL.GL_LIGHTING);



            /*
             *
             * Draw shadows area - start here
             *
             */
            GL.glDisable(GL.GL_LIGHTING);


            GL.glPushMatrix();

            MakeShadowMatrix(ground);  //sending fround matrix
            GL.glMultMatrixf(cubeXform);

            GL.glShadeModel(GL.GL_FLAT);
            GL.glColor3d(0, 0, 0);//black

            drawPenguinShade();

            GL.glPopMatrix();



            GL.glFlush();
            WGL.wglSwapBuffers(m_uint_DC);
        }
// DWORD GetLastError(VOID);

// ############################################################################
// ############################################################################
// ############################################################################
// ############################################################################

// ============================================================================
// The following function, DemoCreateRenderingContext(ref_uint_DC,ref_uint_RC),
// can be used as a simple way to create an OpenGL "Rendering Context" (RC).
// **** DO NOT CALL DemoCreateRenderingContext() DIRECTLY IF YOU CHOOSE TO
// CALL DemoInitOpenGL() (below) TO ESTABLISH OPENGL. ****
// ============================================================================
        public static unsafe void DemoCreateRenderingContext
        (
            ref uint ref_uint_DC,
            ref uint ref_uint_RC
        )
        {
            ref_uint_RC = 0;

            PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR();

            // --------------------------------------------------------------------------
            pfd.nSize           = 40; // sizeof(PIXELFORMATDESCRIPTOR);
            pfd.nVersion        = 1;
            pfd.dwFlags         = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER);
            pfd.iPixelType      = (byte)(PFD_TYPE_RGBA);
            pfd.cColorBits      = 32;
            pfd.cRedBits        = 0;
            pfd.cRedShift       = 0;
            pfd.cGreenBits      = 0;
            pfd.cGreenShift     = 0;
            pfd.cBlueBits       = 0;
            pfd.cBlueShift      = 0;
            pfd.cAlphaBits      = 0;
            pfd.cAlphaShift     = 0;
            pfd.cAccumBits      = 0;
            pfd.cAccumRedBits   = 0;
            pfd.cAccumGreenBits = 0;
            pfd.cAccumBlueBits  = 0;
            pfd.cAccumAlphaBits = 0;
            pfd.cDepthBits      = 32;
            pfd.cStencilBits    = 0;
            pfd.cAuxBuffers     = 0;
            pfd.iLayerType      = (byte)(PFD_MAIN_PLANE);
            pfd.bReserved       = 0;
            pfd.dwLayerMask     = 0;
            pfd.dwVisibleMask   = 0;
            pfd.dwDamageMask    = 0;
            // --------------------------------------------------------------------------



            // --------------------------------------------------------------------------
            // Choose Pixel Format
            // --------------------------------------------------------------------------
            int iPixelFormat = 0;

            PIXELFORMATDESCRIPTOR *_pfd = &pfd;

            iPixelFormat = WGL.ChoosePixelFormat(ref_uint_DC, _pfd);

            if (0 == iPixelFormat)
            {
                uint   uint_LastError = WGL.GetLastError();
                string string_Message = "ChoosePixelFormat() FAILED:  Error: " + uint_LastError;
                WGL.MessageBox(0, string_Message, "WGL.DemoGetRenderingContext() : ERROR", MB_OK);
                return;
            }
            // --------------------------------------------------------------------------


            // --------------------------------------------------------------------------
            // Set Pixel Format
            // --------------------------------------------------------------------------
            int int_Result_SPF = 0;

            int_Result_SPF = WGL.SetPixelFormat(ref_uint_DC, iPixelFormat, _pfd);

            if (0 == int_Result_SPF)
            {
                uint   uint_LastError = WGL.GetLastError();
                string string_Message = "SetPixelFormat() FAILED.  Error: " + uint_LastError;
                WGL.MessageBox(0, string_Message, "WGL.DemoGetRenderingContext() : ERROR", MB_OK);
                return;
            }
            // --------------------------------------------------------------------------



            // --------------------------------------------------------------------------
            // Create Rendering Context (RC)
            // NOTE: You will get the following error:
            //             126 : ERROR_MOD_NOT_FOUND
            // if you attempt to create a render context too soon after creating a
            // window and getting its Device Context (DC).
            // See the comments for WGL.DemoInitOpenGL() on how to use a call to
            // WGL.wglSwapBuffers( ref_uint_DC ) before attempting to create the RC.
            // --------------------------------------------------------------------------
            ref_uint_RC = WGL.wglCreateContext(ref_uint_DC);

            if (0 == ref_uint_RC)
            {
                uint   uint_LastError = WGL.GetLastError();
                string string_Message = "wglCreateContext() FAILED.  Error: " + uint_LastError;
                WGL.MessageBox(0, string_Message, "WGL.DemoGetRenderingContext() : ERROR", MB_OK);
                return;
            }
            // --------------------------------------------------------------------------


            // --------------------------------------------------------------------------
            // Make the new Render Context (RC) the current Render Context (RC)
            // --------------------------------------------------------------------------
            int int_Result_MC = 0;

            int_Result_MC = WGL.wglMakeCurrent(ref_uint_DC, ref_uint_RC);

            if (0 == int_Result_MC)
            {
                uint   uint_LastError = WGL.GetLastError();
                string string_Message = "wglMakeCurrent() FAILED.  Error: " + uint_LastError;
                WGL.MessageBox(0, string_Message, "WGL.DemoGetRenderingContext() : ERROR", MB_OK);
                // ***************************
                WGL.wglDeleteContext(ref_uint_RC);
                ref_uint_RC = 0;
                // ***************************
                return;
            }
            // --------------------------------------------------------------------------
        }
Example #14
0
        public void Draw()
        {
            //Shadows
            pos[0] = 0;//ScrollValue[9];
            pos[1] = ScrollValue[8];
            pos[2] = ScrollValue[7];
            pos[3] = ScrollValue[9];


            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

            GL.glLoadIdentity();



            // not trivial
            double[] ModelVievMatrixBeforeSpecificTransforms = new double[16];
            double[] CurrentRotationTraslation = new double[16];

            GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2],
                          ScrollValue[3], ScrollValue[4], ScrollValue[5],
                          ScrollValue[6], ScrollValue[7], ScrollValue[8]);
            GL.glTranslatef(0.0f, 0.0f, -1.0f);


            if (!bPerspective)
            {
                GL.glTranslatef(0.0f, 0.0f, 8.0f);
            }



            //3D model b3
            GL.glTranslatef(0.0f, -5.0f, -15.0f);
            GL.glRotated(180, 0, 1, 0);
            //3D model e



            //save current ModelView Matrix values
            //in ModelVievMatrixBeforeSpecificTransforms array
            //ModelView Matrix ========>>>>>> ModelVievMatrixBeforeSpecificTransforms
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);
            //ModelView Matrix was saved, so
            //  GL.glLoadIdentity(); // make it identity matrix
            GL.glLoadIdentity(); // make it identity matrix

            //make transformation in accordance to KeyCode
            float delta;

            if (intOptionC != 0)
            {
                delta = 5.0f * Math.Abs(intOptionC) / intOptionC; // signed 5

                switch (Math.Abs(intOptionC))
                {
                case 1:
                    GL.glRotatef(delta, 1, 0, 0);
                    break;

                case 2:
                    GL.glRotatef(delta, 0, 1, 0);
                    break;

                case 3:
                    GL.glRotatef(delta, 0, 0, 1);
                    break;

                case 4:
                    GL.glTranslatef(delta / 20, 0, 0);
                    break;

                case 5:
                    GL.glTranslatef(0, delta / 20, 0);
                    break;

                case 6:
                    GL.glTranslatef(0, 0, delta / 20);
                    break;
                }
            }
            //as result - the ModelView Matrix now is pure representation
            //of KeyCode transform and only it !!!

            //save current ModelView Matrix values
            //in CurrentRotationTraslation array
            //ModelView Matrix =======>>>>>>> CurrentRotationTraslation
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation);

            //The GL.glLoadMatrix function replaces the current matrix with
            //the one specified in its argument.
            //The current matrix is the
            //projection matrix, modelview matrix, or texture matrix,
            //determined by the current matrix mode (now is ModelView mode)
            GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix

            //The GL.glMultMatrix function multiplies the current matrix by
            //the one specified in its argument.
            //That is, if M is the current matrix and T is the matrix passed to
            //GL.glMultMatrix, then M is replaced with M • T
            GL.glMultMatrixd(CurrentRotationTraslation);

            //save the matrix product in AccumulatedRotationsTraslations
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations);

            //replace ModelViev Matrix with stored ModelVievMatrixBeforeSpecificTransforms
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            //multiply it by KeyCode defined AccumulatedRotationsTraslations matrix
            GL.glMultMatrixd(AccumulatedRotationsTraslations);

            GL.glEnable(GL.GL_TEXTURE_2D);


            if (!rotate)
            {
                GL.glRotatef(0, 0, 20, 0);
                GL.glDepthRange(1, 1);////////if the zebra behind the cube, change to (1,1)
                GL.glPushMatrix();

                DrawTexturedCube();

                GL.glPopMatrix();
            }
            else
            {
                GL.glRotatef(0, 0, 20, 0);
                GL.glDepthRange(1, 1);
                GL.glPushMatrix();
                angle -= 0.1f;
                GL.glRotatef(angle, 0, 2, 0);
                DrawTexturedCube();

                GL.glPopMatrix();
            }


            GL.glRotated(100, 0, 90, 0);
            GL.glScaled(0.05, 0.05, 0.05);



            GL.glRotated(-90, 180, 0, 0);
            GL.glScaled(30, 30, 30);

            DrawFigures();


            GL.glEnable(GL.GL_BLEND);
            GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);


            //only floor, draw only to STENCIL buffer
            GL.glEnable(GL.GL_STENCIL_TEST);
            GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
            GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF); // draw floor always
            GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE);
            GL.glDisable(GL.GL_DEPTH_TEST);


            // restore regular settings
            GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE);
            GL.glEnable(GL.GL_DEPTH_TEST);


            GL.glEnable(GL.GL_STENCIL_TEST);

            // draw reflected scene
            GL.glPushMatrix();
            GL.glScalef(1, 1, -1); //swap on Z axis
            GL.glEnable(GL.GL_CULL_FACE);
            GL.glCullFace(GL.GL_BACK);
            DrawFigures();
            GL.glCullFace(GL.GL_FRONT);
            DrawFigures();
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glPopMatrix();


            // really draw floor
            //( half-transparent ( see its color's alpha byte)))
            // in order to see reflected objects
            GL.glDepthMask((byte)GL.GL_FALSE);
            DrawFloor();
            GL.glDepthMask((byte)GL.GL_TRUE);
            // Disable GL.GL_STENCIL_TEST to show All, else it will be cut on GL.GL_STENCIL
            GL.glDisable(GL.GL_STENCIL_TEST);
            DrawFigures();
            //REFLECTION e
            GL.glFlush();

            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #15
0
        /**********************************************************************************************************
        *
        *
        *
        * MAIN DRAW FUNCTION
        *
        *
        *
        **********************************************************************************************************/
        public void Draw()
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            GL.glViewport(0, 0, Width, Height);
            GL.glLoadIdentity();

            GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2],
                          ScrollValue[3], ScrollValue[4], ScrollValue[5],
                          ScrollValue[6], ScrollValue[7], ScrollValue[8]);

            GL.glRotatef(xAngle, 1.0f, 0.0f, 0.0f);
            GL.glRotatef(yAngle, 0.0f, 1.0f, 0.0f);
            GL.glRotatef(zAngle, 0.0f, 0.0f, 1.0f);
            GL.glTranslatef(xShift, yShift, zShift);

            pos[0] = light_position[0] = ScrollValue[9];
            pos[1] = light_position[1] = ScrollValue[10];
            pos[2] = light_position[2] = ScrollValue[11];
            pos[3] = light_position[3] = 0;

            GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, light_ambient);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, light_diffuse);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, light_specular);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position);

            GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
            GL.glEnable(GL.GL_LIGHT0);

            /*
             *
             * Reflection
             *
             */
            GL.glEnable(GL.GL_BLEND);
            GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
            if (reflectionOn)
            {
                //draw only to STENCIL buffer
                GL.glEnable(GL.GL_STENCIL_TEST);
                GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
                GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF);
                GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE);
                GL.glDisable(GL.GL_DEPTH_TEST);

                drawLake();

                // restore regular settings
                GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE);
                GL.glEnable(GL.GL_DEPTH_TEST);

                // reflection is drawn only where STENCIL buffer value equal to 1
                GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF);
                GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);

                /*
                 *
                 * draw reflected scene
                 *
                 */

                GL.glEnable(GL.GL_LIGHTING);
                for (currentTree = 0; currentTree < numOfTrees; currentTree++)
                {
                    GL.glPushMatrix();
                    //GL.glTranslated(randX[currentTree], 0,randZ[currentTree]);
                    GL.glTranslated(locationX[currentTree], 0, locationZ[currentTree]);
                    GL.glRotated(locationRotateY[currentTree], 0, 1, 0);
                    GL.glScalef(1, -1, 1); //swap on Z axis

                    if (scullFaceOn)
                    {
                        GL.glEnable(GL.GL_CULL_FACE);
                        GL.glCullFace(GL.GL_BACK);
                        GL.glCallList(TREE_LIST + currentTree);
                        GL.glCullFace(GL.GL_FRONT);
                        GL.glCallList(TREE_LIST + currentTree);
                        GL.glDisable(GL.GL_CULL_FACE);
                    }
                    else
                    {
                        GL.glCallList(TREE_LIST + currentTree);
                    }

                    GL.glPopMatrix();
                }

                drawLake();

                GL.glStencilFunc(GL.GL_NOTEQUAL, 1, 0xFFFFFFFF);
                GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);

                // really draw floor
                //( half-transparent ( see its color's alpha byte)))
                // in order to see reflected objects
                //GL.glDepthMask((byte)GL.GL_FALSE);
                GL.glDepthMask((byte)GL.GL_TRUE);
                if (!textureOn)
                {
                    drawFloor();
                }
                else
                {
                    drawFloorTextured();
                    DrawTexturedCube();
                }

                GL.glDisable(GL.GL_LIGHTING);
                GL.glDisable(GL.GL_STENCIL_TEST);
            }
            else
            {
                GL.glEnable(GL.GL_LIGHTING);
                drawLake();
                if (!textureOn)
                {
                    drawFloor();
                }
                else
                {
                    drawFloorTextured();
                    DrawTexturedCube();
                }
                GL.glDisable(GL.GL_LIGHTING);
            }

            DrawLight();

            /*
             * Draw trees
             */

            GL.glEnable(GL.GL_LIGHTING);
            GL.glPushMatrix();
            for (currentTree = 0; currentTree < numOfTrees; currentTree++)
            {
                GL.glPushMatrix();
                //GL.glTranslated(randX[currentTree], 0, randZ[currentTree]);
                GL.glTranslated(locationX[currentTree], 0, locationZ[currentTree]);
                GL.glRotated(locationRotateY[currentTree], 0, 1, 0);
                GL.glCallList(TREE_LIST + currentTree);
                GL.glPopMatrix();
            }
            GL.glPopMatrix();

            /*
             * Draw trees shadows
             */
            GL.glDisable(GL.GL_LIGHTING);
            GL.glColor3d(0, 0, 0);
            if (shadowOn)
            {
                GL.glPushMatrix();
                MakeShadowMatrix(ground);
                GL.glMultMatrixf(cubeXform);
                for (currentTree = 0; currentTree < numOfTrees; currentTree++)
                {
                    GL.glPushMatrix();
                    //GL.glTranslated(randX[currentTree], 0, randZ[currentTree]);
                    GL.glTranslated(locationX[currentTree], 0, locationZ[currentTree]);
                    GL.glRotated(locationRotateY[currentTree], 0, 1, 0);
                    GL.glCallList(TREE_LIST + currentTree);
                    GL.glPopMatrix();
                }
                GL.glPopMatrix();
            }

            GL.glFlush();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #16
0
        public void Draw()
        {
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
            GL.glMatrixMode(GL.GL_MODELVIEW);
            GL.glLoadIdentity();

            GL.glTranslatef(0.0f, -1.5f, -6.0f);
            GL.glRotatef(10, 1.0f, 0.0f, 0.0f);
            GL.glRotatef(-tank.rotation, 0.0f, 1.0f, 0.0f);
            GL.glRotatef(-tank.turretRotation, 0.0f, 1.0f, 0.0f);
            GL.glTranslatef(-tank.posX, 0.0f, -tank.posZ);

            //DrawAxes();
            DrawAll();

            //target
            target.Drawself();

            //LIGHT - before transforms
            //  hence it is in const position
            GL.glPushMatrix();
            GL.glEnable(GL.GL_LIGHTING);
            GL.glEnable(GL.GL_LIGHT0);
            GL.glTranslatef(0, 11, -35);
            float[] ambient = { 0, 0, 0.3f, 1 };
            if (tank.TankType == 2)
            {
                ambient[2] = 0.2f;
            }
            else
            {
                ambient[0] = 0.2f;
            }
            float[] diffuse  = { 1, 1, 1, 1 };
            float[] specular = { 0.5f, 0.5f, 0.5f, 1f };
            float[] pos      = { 0, 1f, -0.5f, 0 };
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, ambient);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, diffuse);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specular);
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos);

            GL.glColor3f(1, 1, 0);
            GL.glDisable(GL.GL_LIGHTING);
            GLU.gluSphere(obj, 1, 12, 12);    //SUN
            GL.glEnable(GL.GL_LIGHTING);
            GL.glPopMatrix();

            if (!stelthmode)
            {
                GL.glEnable(GL.GL_BLEND);
                GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
                GL.glEnable(GL.GL_STENCIL_TEST);
                GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
                GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF); // draw floor always
                GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE);
                GL.glDisable(GL.GL_DEPTH_TEST);
                DrawMirror(false);
                // restore regular settings
                GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE);
                GL.glEnable(GL.GL_DEPTH_TEST);

                // reflection is drawn only where STENCIL buffer value equal to 1
                GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF);
                GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);

                GL.glEnable(GL.GL_STENCIL_TEST);
                // draw reflected scene
                GL.glPushMatrix();
                GL.glScalef(-1, 1, 1); //swap on Z axis
                GL.glEnable(GL.GL_CULL_FACE);
                GL.glCullFace(GL.GL_BACK);
                tank.drawSelf();
                DrawBullets();
                GL.glCullFace(GL.GL_FRONT);
                tank.drawSelf();
                DrawBullets();
                GL.glDisable(GL.GL_CULL_FACE);
                GL.glPopMatrix();

                GL.glDepthMask((byte)GL.GL_FALSE);
                DrawMirror(false);
                GL.glDepthMask((byte)GL.GL_TRUE);
                // Disable GL.GL_STENCIL_TEST to show All, else it will be cut on GL.GL_STENCIL
                GL.glDisable(GL.GL_STENCIL_TEST);
            }
            else
            {
                GL.glEnable(GL.GL_BLEND);
                GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
                GL.glEnable(GL.GL_STENCIL_TEST);
                GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
                GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF); // draw floor always
                GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE);
                GL.glDisable(GL.GL_DEPTH_TEST);
                DrawMirror(false);
                // restore regular settings
                GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE);
                GL.glEnable(GL.GL_DEPTH_TEST);

                // reflection is drawn only where STENCIL buffer value equal to 1
                GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF);
                GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);

                GL.glEnable(GL.GL_STENCIL_TEST);
                // draw reflected scene
                GL.glPushMatrix();
                GL.glScalef(-1, 1, 1); //swap on Z axis
                GL.glEnable(GL.GL_CULL_FACE);
                GL.glCullFace(GL.GL_BACK);
                DrawBullets();
                GL.glCullFace(GL.GL_FRONT);
                DrawBullets();
                GL.glDisable(GL.GL_CULL_FACE);
                GL.glPopMatrix();

                GL.glDepthMask((byte)GL.GL_FALSE);
                DrawMirror(false);
                GL.glDepthMask((byte)GL.GL_TRUE);
                // Disable GL.GL_STENCIL_TEST to show All, else it will be cut on GL.GL_STENCIL
                GL.glDisable(GL.GL_STENCIL_TEST);
            }

            if (!stelthmode)
            {
                tank.drawSelf();
            }
            else
            {
                tank.drawstelth();
            }

            DrawMirror(true);
            DrawBullets();
            //REFLECTION e

            update();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #17
0
        public void Draw()
        {
            pos[0] = -4 + (float)xExisOrigin + (float)ScrollValue[11];
            pos[1] = 15 + (float)yExisOrigin + (float)ScrollValue[12];
            pos[2] = 15 + (float)ScrollValue[13];


            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            GL.glLoadIdentity();


            // not trivial
            double [] ModelVievMatrixBeforeSpecificTransforms = new double[16];
            double [] CurrentRotationTraslation = new double[16];

            GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2],
                          ScrollValue[3], ScrollValue[4], ScrollValue[5],
                          ScrollValue[6], ScrollValue[7], ScrollValue[8]);
            GL.glTranslatef(0.0f, 0.0f, -30.0f);

            GL.glRotatef(105, 0, 0, 1);
            GL.glRotatef(70, 0, 1, 0);
            GL.glRotatef(15, 1, 0, 0);
            //save current ModelView Matrix values
            //in ModelVievMatrixBeforeSpecificTransforms array
            //ModelView Matrix ========>>>>>> ModelVievMatrixBeforeSpecificTransforms
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);
            //ModelView Matrix was saved, so
            GL.glLoadIdentity(); // make it identity matrix

            //make transformation in accordance to KeyCode
            float delta;

            if (intOptionC != 0)
            {
                delta = 5.0f * Math.Abs(intOptionC) / intOptionC; // signed 5

                switch (Math.Abs(intOptionC))
                {
                case 1:
                    GL.glRotatef(delta, 1, 0, 0);
                    break;

                case 2:
                    GL.glRotatef(delta, 0, 1, 0);
                    break;

                case 3:
                    GL.glRotatef(delta, 0, 0, 1);
                    break;

                case 4:
                    GL.glTranslatef(delta / 20, 0, 0);
                    break;

                case 5:
                    GL.glTranslatef(0, delta / 20, 0);
                    break;

                case 6:
                    GL.glTranslatef(0, 0, delta / 20);
                    break;
                }
            }
            //as result - the ModelView Matrix now is pure representation
            //of KeyCode transform and only it !!!

            //save current ModelView Matrix values
            //in CurrentRotationTraslation array
            //ModelView Matrix =======>>>>>>> CurrentRotationTraslation
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation);

            //The GL.glLoadMatrix function replaces the current matrix with
            //the one specified in its argument.
            //The current matrix is the
            //projection matrix, modelview matrix, or texture matrix,
            //determined by the current matrix mode (now is ModelView mode)
            GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix

            //The GL.glMultMatrix function multiplies the current matrix by
            //the one specified in its argument.
            //That is, if M is the current matrix and T is the matrix passed to
            //GL.glMultMatrix, then M is replaced with M • T
            GL.glMultMatrixd(CurrentRotationTraslation);

            //save the matrix product in AccumulatedRotationsTraslations
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations);

            //replace ModelViev Matrix with stored ModelVievMatrixBeforeSpecificTransforms
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            //multiply it by KeyCode defined AccumulatedRotationsTraslations matrix
            GL.glMultMatrixd(AccumulatedRotationsTraslations);


            //REFLECTION//DrawAxes();

            //REFLECTION b
            intOptionB += 1;  //for rotation
            intOptionC += 10; //for rotation
            // without REFLECTION was only DrawAll();
            // now
            //!!!!------sky box
            GL.glPushMatrix();
            GL.glPushAttrib(GL.GL_CURRENT_BIT);
            GL.glColor4f(1.0f, 1.0f, 1.0f, 0.5f);


            GL.glEnable(GL.GL_TEXTURE_2D);
            GL.glDisable(GL.GL_BLEND);
            GL.glRotatef(90, 1, 0, 0);
            DrawTexturedCube();
            GL.glPopAttrib();
            GL.glPopMatrix();
            /////
            GL.glEnable(GL.GL_BLEND);
            GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);


            //only floor, draw only to STENCIL buffer
            GL.glEnable(GL.GL_STENCIL_TEST);
            GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
            GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF); // draw floor always
            GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE);
            GL.glDisable(GL.GL_DEPTH_TEST);

            DrawFloor3();

            // restore regular settings
            GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE);
            GL.glEnable(GL.GL_DEPTH_TEST);

            // reflection is drawn only where STENCIL buffer value equal to 1
            GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF);
            GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);

            GL.glEnable(GL.GL_STENCIL_TEST);

            // draw reflected scene
            GL.glPushMatrix();
            GL.glScalef(1, 1, -1); //swap on Z axis
            GL.glEnable(GL.GL_CULL_FACE);
            GL.glCullFace(GL.GL_BACK);
            DrawFigures();

            GL.glCullFace(GL.GL_FRONT);
            DrawFigures();

            GL.glDisable(GL.GL_CULL_FACE);
            GL.glPopMatrix();

            // really draw floor
            //( half-transparent ( see its color's alpha byte)))
            // in order to see reflected objects
            GL.glDepthMask((byte)GL.GL_FALSE);

            DrawFloor3();

            GL.glDepthMask((byte)GL.GL_TRUE);
            // Disable GL.GL_STENCIL_TEST to show All, else it will be cut on GL.GL_STENCIL
            GL.glDisable(GL.GL_STENCIL_TEST);



            DrawFigures();



            GL.glDisable(GL.GL_TEXTURE_2D);

            GL.glFlush();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #18
0
        public void Draw()
        {
            //Light position for shadows
            MainLightSource.X = ScrollValue[10];
            MainLightSource.Y = ScrollValue[11];
            MainLightSource.Z = ScrollValue[12];
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, MainLightSource.LightLocation());
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, new float[] { 0f, 0f, 0f, 1f });
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, new float[] { 1f, 1f, 1f });
            GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, new float[] { 0.628281f, 0.555802f, 0.366065f });

            GL.glLightfv(GL.GL_LIGHT2, GL.GL_POSITION, StaticRedLightSource.LightLocation());
            GL.glLightfv(GL.GL_LIGHT2, GL.GL_AMBIENT, new float[] { 0f, 0f, 0f, 1f });
            GL.glLightfv(GL.GL_LIGHT2, GL.GL_DIFFUSE, new float[] { 1f, 0f, 0f });
            GL.glLightfv(GL.GL_LIGHT2, GL.GL_SPECULAR, new float[] { 0.628281f, 0.555802f, 0.366065f });

            GL.glLightfv(GL.GL_LIGHT3, GL.GL_POSITION, StaticBlueLightSource.LightLocation());
            GL.glLightfv(GL.GL_LIGHT3, GL.GL_AMBIENT, new float[] { 0f, 0f, 0f, 1f });
            GL.glLightfv(GL.GL_LIGHT3, GL.GL_DIFFUSE, new float[] { 0f, 0f, 1f });
            GL.glLightfv(GL.GL_LIGHT3, GL.GL_SPECULAR, new float[] { 0.628281f, 0.555802f, 0.366065f });

            //GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, bannerLightPos);
            if (m_DeviceContext == 0 || m_RenderingContext == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

            GL.glLoadIdentity();

            // not trivial
            double[] ModelVievMatrixBeforeSpecificTransforms = new double[16];
            double[] CurrentRotationTraslation = new double[16];

            GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2],
                          ScrollValue[3], ScrollValue[4], ScrollValue[5],
                          ScrollValue[6], ScrollValue[7], ScrollValue[8]);
            GL.glTranslatef(0.0f, 0.0f, -3.0f);

            DrawOldAxes();

            //save current ModelView Matrix values
            //in ModelVievMatrixBeforeSpecificTransforms array
            //ModelView Matrix ========>>>>>> ModelVievMatrixBeforeSpecificTransforms
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);
            //ModelView Matrix was saved, so
            GL.glLoadIdentity(); // make it identity matrix

            //make transformation in accordance to KeyCode
            float delta;

            if (intOptionC != 0)
            {
                delta = 3.0f * Math.Abs(intOptionC) / intOptionC; // signed 5

                switch (Math.Abs(intOptionC))
                {
                case 1:
                    GL.glRotatef(delta, 1, 0, 0);
                    break;

                case 2:
                    GL.glRotatef(delta, 0, 1, 0);
                    break;

                case 3:
                    GL.glRotatef(delta, 0, 0, 1);
                    break;

                case 4:
                    GL.glTranslatef(delta / 20, 0, 0);
                    break;

                case 5:
                    GL.glTranslatef(0, delta / 20, 0);
                    break;

                case 6:
                    GL.glTranslatef(0, 0, delta / 20);
                    break;
                }
            }
            //as result - the ModelView Matrix now is pure representation
            //of KeyCode transform and only it !!!

            //save current ModelView Matrix values
            //in CurrentRotationTraslation array
            //ModelView Matrix =======>>>>>>> CurrentRotationTraslation
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation);

            //The GL.glLoadMatrix function replaces the current matrix with
            //the one specified in its argument.
            //The current matrix is the
            //projection matrix, modelview matrix, or texture matrix,
            //determined by the current matrix mode (now is ModelView mode)
            GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix

            //The GL.glMultMatrix function multiplies the current matrix by
            //the one specified in its argument.
            //That is, if M is the current matrix and T is the matrix passed to
            //GL.glMultMatrix, then M is replaced with M • T
            GL.glMultMatrixd(CurrentRotationTraslation);

            //save the matrix product in AccumulatedRotationsTraslations
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations);

            //replace ModelViev Matrix with stored ModelVievMatrixBeforeSpecificTransforms
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            //multiply it by KeyCode defined AccumulatedRotationsTraslations matrix
            GL.glMultMatrixd(AccumulatedRotationsTraslations);
            GL.glPushMatrix();             // save the current matrix
            GL.glScalef(zoom, zoom, zoom); // scale the matrix
            DrawAxes();
            DrawFigures();
            GL.glPopMatrix(); // load the unscaled matrix
            GL.glFlush();

            WGL.wglSwapBuffers(m_DeviceContext);
        }
// ############################################################################
// ############################################################################
// ############################################################################
// ############################################################################


// ============================================================================
// The following is an example of OpenGL rendering code, complete with
// buffer swapping.  This function can be called by a Form's "OnPaint()"
// method if a previous WGL.DemoInitOpenGL() call (for example) has
// already successfully established a valid Render Context (RC).
// ============================================================================

        public static void DemoOpenGLDraw
        (
            int int_WindowWidth,
            int int_WindowHeight,
            uint uint_DC
        )
        {
            int   int_Phase   = (int)(System.Environment.TickCount % 120000);
            float float_Phase = (float)(0.3f * (int_Phase));

            if (int_WindowWidth <= 0)
            {
                int_WindowWidth = 1;
            }
            if (int_WindowHeight <= 0)
            {
                int_WindowHeight = 1;
            }

            GL.glViewport(0, 0, int_WindowWidth, int_WindowHeight);

            GL.glEnable(GL.GL_DEPTH_TEST);
            GL.glDepthFunc(GL.GL_LEQUAL);
            GL.glEnable(GL.GL_CULL_FACE);
            GL.glCullFace(GL.GL_BACK);
            GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            GL.glMatrixMode(GL.GL_PROJECTION);
            GL.glLoadIdentity();

            //GL.glOrtho( 0.0f, (float)(int_WindowWidth), 0.0f, (float)(int_WindowHeight), -1.0f, 1.0f );
            GLU.gluPerspective
            (
                60.0,  // Field of view angle (Y angle; degrees)
                ((double)(int_WindowWidth) / (double)(int_WindowHeight)),
                1.0,   // Near plane
                1000.0 // Far  plane
            );

            GL.glMatrixMode(GL.GL_MODELVIEW);
            GL.glLoadIdentity();

            // Translating the camera to +600.0f Z is essentially
            // adding -600.0f to all drawing commands.
            GL.glTranslatef(0.0f, 0.0f, -600.0f);

            GL.glRotatef((0.11f * float_Phase), 1.0f, 0.0f, 0.0f);
            GL.glRotatef((0.31f * float_Phase), 0.0f, 1.0f, 0.0f);
            GL.glRotatef((0.19f * float_Phase), 0.0f, 0.0f, 1.0f);

            float[][] vert_xyz = new float[8][]
            {
                new float[] { -100.0f, -100.0f, -100.0f }, // 0
                new float[] { -100.0f, -100.0f, 100.0f },  // 1
                new float[] { -100.0f, 100.0f, -100.0f },  // 2
                new float[] { -100.0f, 100.0f, 100.0f },   // 3
                new float[] { 100.0f, -100.0f, -100.0f },  // 4
                new float[] { 100.0f, -100.0f, 100.0f },   // 5
                new float[] { 100.0f, 100.0f, -100.0f },   // 6
                new float[] { 100.0f, 100.0f, 100.0f } // 7
            };
            int [][] tri_abc = new int [12][]
            {
                new int[] { 0, 2, 4 }, new int[] { 4, 2, 6 }, // Back
                new int[] { 0, 4, 1 }, new int[] { 1, 4, 5 }, // Bottom
                new int[] { 0, 1, 2 }, new int[] { 2, 1, 3 }, // Left
                new int[] { 4, 6, 5 }, new int[] { 5, 6, 7 }, // Right
                new int[] { 2, 3, 6 }, new int[] { 6, 3, 7 }, // Top
                new int[] { 1, 5, 3 }, new int[] { 3, 5, 7 } // Front
            };
            float[][] colors_rgb = new float[12][]
            {
                new float[] { 0.5f, 0.1f, 0.1f }, new float[] { 1.0f, 0.1f, 0.1f }, // Red
                new float[] { 0.5f, 0.5f, 0.1f }, new float[] { 1.0f, 1.0f, 0.1f }, // Yellow
                new float[] { 0.1f, 0.5f, 0.1f }, new float[] { 0.1f, 1.0f, 0.1f }, // Green
                new float[] { 0.1f, 0.5f, 0.5f }, new float[] { 0.1f, 1.0f, 1.0f }, // Cyan
                new float[] { 0.1f, 0.1f, 0.5f }, new float[] { 0.1f, 0.1f, 1.0f }, // Blue
                new float[] { 0.5f, 0.1f, 0.5f }, new float[] { 1.0f, 0.1f, 1.0f } // Magenta
            };

            int iTriTotal = 12;
            int iTriIndex = 0;

            GL.glBegin(GL.GL_TRIANGLES);
            for (iTriIndex = 0; iTriIndex < iTriTotal; iTriIndex++)
            {
                GL.glColor3fv(colors_rgb[iTriIndex]);
                GL.glVertex3fv(vert_xyz[tri_abc[iTriIndex][0]]);

                GL.glColor3fv(colors_rgb[iTriIndex]);
                GL.glVertex3fv(vert_xyz[tri_abc[iTriIndex][1]]);

                GL.glColor3fv(colors_rgb[iTriIndex]);
                GL.glVertex3fv(vert_xyz[tri_abc[iTriIndex][2]]);
            }
            GL.glEnd();

            WGL.wglSwapBuffers(uint_DC);
        }
Example #20
0
        public void Draw()
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

            GL.glLoadIdentity();

            if (Weaponchanged)
            {
                //if WeaponIndex changed create lists again!
                Robot.PrepareAndDraw();
                Robot.PrepareAndDrawShadow();
                Weaponchanged = false;
            }

            GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2],
                          ScrollValue[3], ScrollValue[4], ScrollValue[5],
                          ScrollValue[6], ScrollValue[7], ScrollValue[8]);

            #region Mouse Control
            GL.glTranslatef(-X, -Y, -Z);
            GL.glRotatef(rotX, 1.0f, 0.0f, 0.0f);
            GL.glRotatef(rotY, 0.0f, 1.0f, 0.0f);
            GL.glRotatef(rotZ, 0.0f, 0.0f, 1.0f);
            #endregion


            //move camera to initial position - center of cube and above floor
            GL.glTranslatef(0.0f, 0.0f, -1.0f);
            GL.glTranslatef(0.0f, 5.0f, 0.0f);
            GL.glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);


            //update light position
            LightPosition[0] = ScrollValue[10];
            LightPosition[1] = ScrollValue[11];
            LightPosition[2] = ScrollValue[12];
            LightPosition[3] = 1.0f;

            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);
            GL.glLoadIdentity(); // make it identity matrix

            MoveRobotByDirection();

            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation);
            GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix
            GL.glMultMatrixd(CurrentRotationTraslation);
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations);
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            GL.glMultMatrixd(AccumulatedRotationsTraslations);


            //draw actual cube
            cube.Scale(xMaxOfCube, yMaxOfCube, zMaxOfCube);
            cube.Draw(1);

            GL.glRotatef(180, 0, 1, 0);
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);

            GL.glPushMatrix();
            GL.glLoadIdentity();
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            GL.glMultMatrixd(AccumulatedRotationsTraslations);


            //!!!!!!!!!!! draw orginal Robot
            GL.glPushMatrix();
            RotateRobotByDirection();
            GL.glCullFace(GL.GL_BACK);
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glEnable(GL.GL_LIGHTING);
            GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
            Robot.Draw(false);
            GL.glPopMatrix();


            GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix

            RobotPlace[0]        = AccumulatedRotationsTraslations[12];
            RobotPlaceForward[0] = RobotPlaceBackward[0] = RobotPlaceRight[0] = RobotPlaceLeft[0] = AccumulatedRotationsTraslations[12];
            RobotPlace[1]        = AccumulatedRotationsTraslations[14];
            RobotPlaceForward[1] = RobotPlaceBackward[1] = RobotPlaceRight[1] = RobotPlaceLeft[1] = AccumulatedRotationsTraslations[14];

            switch (WhatWillDirection)
            {
            case arrow.forward:
                //Look future to get wallk forward
                RobotPlaceForward = WillPlace(2.1f, 0, 0);
                break;

            case arrow.backward:
                //Look future to get wallk backward
                RobotPlaceBackward = WillPlace(-2.1f, 0, 0);
                break;

            case arrow.right:
                //Look future to get wallk right
                RobotPlaceRight = WillPlace(0, 0, 2.1f);
                break;

            case arrow.left:
                //Look future to get wallk left
                RobotPlaceLeft = WillPlace(0, 0, -2.1f);
                break;
            }

            if (((RobotPlace[0] < ((car.Drive % 46) - 23) + 7) && (RobotPlace[0] > ((car.Drive % 46) - 23) - 4)) && //in car length
                RobotPlace[1] > 5 && RobotPlace[1] < 10 && !Robot.IsJumping)     //in car width & not jumping
            {
                Robot.IsCrashWithCar = true;
            }

            //!!!!!!!!!!!
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glPopMatrix();
            GL.glRotatef(-180, 0, 1, 0);

            #region Reflaction to cube
            StartReflaction(-1, 1, -1);     //Reflaction to cube

            cube.Scale(xMaxOfCube - 0.002f, yMaxOfCube - 0.002f, zMaxOfCube - 0.002f);
            cube.Draw(-1);       //decrease 0.002 from each dimension of cube to avoid unexpected lines and -1 for mirrow efect
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glPopMatrix();
            #endregion

            // really draw mirror
            //( half-transparent ( see its color's alpha byte)))
            // in order to see reflected objects
            //GL.glPushMatrix();
            //GL.glTranslatef(0, -4, 0);
            //GL.glDepthMask((byte)GL.GL_FALSE);
            //GL.glRotatef(90,0,1,0);
            //DrawMirror();
            //GL.glDepthMask((byte)GL.GL_TRUE);
            //GL.glPopMatrix();

            GL.glScalef(-1, 1, 1);//Some rotation for normal Cube direction
            GL.glRotatef(180, 0, 1, 0);

            #region Reflaction to Robot
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);
            StartReflaction(-1, 1, 1);  //Start Reflaction to Robot
            GL.glLoadIdentity();
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation);
            GL.glLoadMatrixd(AccumulatedRotationsTraslations);
            GL.glMultMatrixd(CurrentRotationTraslation);
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations);
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            GL.glMultMatrixd(AccumulatedRotationsTraslations);



            //draw reflected Robot
            GL.glPushMatrix();
            RotateRobotByDirection();
            GL.glCullFace(GL.GL_BACK);
            GL.glCullFace(GL.GL_FRONT);
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glRotatef(-Robot.WalkAngle, 0, 1, 0);
            Robot.Draw(false);
            GL.glPopMatrix();
            GL.glDisable(GL.GL_CULL_FACE);
            GL.glPopMatrix();


            //draw all Robot shadows in the mirror!!
            MakeShadow(ModelVievMatrixBeforeSpecificTransforms, CurrentRotationTraslation);
            DrawLight();   //draw reflected light
            GL.glDisable(GL.GL_STENCIL_TEST);
            #endregion

            GL.glScalef(1, 1, -1);                                                          //Some rotation for normal Cube direction
            GL.glRotatef(180, 0, 1, 0);
            DrawLight();                                                                    //draw actual light
            MakeShadow(ModelVievMatrixBeforeSpecificTransforms, CurrentRotationTraslation); //draw all Robot shadows


            car.Drive += 0.5f;    //for animation of car moving

            //draw car reflection
            StartReflaction(-1, 1, 1);
            car.Draw(false);

            //draw car reflection shadow on floor
            StartReflaction(-1, 1, 1);
            GL.glDisable(GL.GL_LIGHTING);
            GL.glPushMatrix();
            MakeShadowMatrix(floorCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();

            //draw car reflection shadow on back wall
            StartReflaction(-1, 1, 1);
            GL.glDisable(GL.GL_LIGHTING);
            GL.glPushMatrix();
            MakeShadowMatrix(backWallCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();

            //draw car reflection shadow on front wall
            StartReflaction(-1, 1, 1);
            GL.glDisable(GL.GL_LIGHTING);
            GL.glPushMatrix();
            MakeShadowMatrix(frontWallCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();
            GL.glDisable(GL.GL_STENCIL_TEST);

            //draw the Frame of mirror
            mirror.DrawFrame();

            //draw mirror again to cover car from being shown on the other side of mirror
            GL.glPushMatrix();
            GL.glTranslatef(0, -4, 0);
            GL.glRotatef(90, 0, 1, 0);
            mirror.Draw();
            GL.glPopMatrix();

            //draw car
            car.Draw(false);

            //draw shadow car on floor
            GL.glPushMatrix();
            MakeShadowMatrix(floorCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();

            //draw shadow car on back wall
            GL.glPushMatrix();
            MakeShadowMatrix(backWallCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();

            //draw shadow car on front wall
            GL.glPushMatrix();
            MakeShadowMatrix(frontWallCoordForShadow);
            GL.glMultMatrixf(cubeXform);
            car.Draw(true);
            GL.glPopMatrix();


            GL.glFlush();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #21
0
        public void Draw()
        {
            float delta = 0;

            double[] ModelViewMatrixBeforeTransforms = new double[16];
            double[] CurrentTraslation = new double[16];

            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
            GL.glLoadIdentity();

            if (enableLookAtValue)
            {
                GLU.gluLookAt(LookAtNumberValue[0], LookAtNumberValue[1], LookAtNumberValue[2],
                              LookAtNumberValue[3], LookAtNumberValue[4], LookAtNumberValue[5],
                              LookAtNumberValue[6], LookAtNumberValue[7], LookAtNumberValue[8]);
            }

            GL.glTranslatef(0.0f, 0.0f, -20.0f);

            if (enableRotate)
            {
                GL.glRotatef(viewAngle, 0.0f, 1.0f, 0.0f);
                viewAngle -= 2f;
            }

            DrawRoom();
            DrawOldAxes();
            DrawLightSource();

            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelViewMatrixBeforeTransforms);
            GL.glLoadIdentity();

            if (coordSysMoveDirection != 0)
            {
                delta = 5.0f * Math.Abs(coordSysMoveDirection) / coordSysMoveDirection;

                switch (Math.Abs(coordSysMoveDirection))
                {
                case 1:
                    GL.glTranslatef(delta / 20, 0, 0);
                    break;

                case 2:
                    GL.glTranslatef(0, delta / 20, 0);
                    break;

                case 3:
                    GL.glTranslatef(0, 0, delta / 20);
                    break;

                case 4:
                    GL.glRotatef(delta, 1, 0, 0);
                    break;

                case 5:
                    GL.glRotatef(delta, 0, 1, 0);
                    break;

                case 6:
                    GL.glRotatef(delta, 0, 0, 1);
                    break;
                }
            }

            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentTraslation);
            GL.glLoadMatrixd(AccumulatedTraslations);
            GL.glMultMatrixd(CurrentTraslation);
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedTraslations);
            GL.glLoadMatrixd(ModelViewMatrixBeforeTransforms);
            GL.glMultMatrixd(AccumulatedTraslations);

            DrawAxes();
            GL.glCallList(handList);

            if (enableReflection)
            {
                GL.glEnable(GL.GL_BLEND);
                GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
                GL.glEnable(GL.GL_STENCIL_TEST);
                GL.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
                GL.glStencilFunc(GL.GL_ALWAYS, 1, 0xFFFFFFFF);
                GL.glColorMask((byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE, (byte)GL.GL_FALSE);
                GL.glDisable(GL.GL_DEPTH_TEST);

                //DrawFloor();
                GL.glCallList(floorMainList);

                GL.glColorMask((byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE, (byte)GL.GL_TRUE);
                GL.glEnable(GL.GL_DEPTH_TEST);
                GL.glStencilFunc(GL.GL_EQUAL, 1, 0xFFFFFFFF);
                GL.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);
                GL.glEnable(GL.GL_STENCIL_TEST);
                GL.glPushMatrix();
                GL.glScalef(1, -1, 1);
                GL.glEnable(GL.GL_CULL_FACE);
                GL.glCullFace(GL.GL_BACK);

                GL.glTranslated(0, 3, 0);
                DrawFigures();

                GL.glCullFace(GL.GL_FRONT);

                DrawFigures();

                GL.glDisable(GL.GL_CULL_FACE);
                GL.glPopMatrix();
                GL.glDepthMask((byte)GL.GL_FALSE);

                //DrawFloor();
                GL.glCallList(floorMainList);

                GL.glDepthMask((byte)GL.GL_TRUE);
                GL.glDisable(GL.GL_STENCIL_TEST);
            }

            GL.glFlush();
            WGL.wglSwapBuffers(m_uint_DC);
        }
Example #22
0
        public void Draw()
        {
            if (m_uint_DC == 0 || m_uint_RC == 0)
            {
                return;
            }

            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

            GL.glLoadIdentity();

            // not trivial
            double [] ModelVievMatrixBeforeSpecificTransforms = new double[16];
            double [] CurrentRotationTraslation = new double[16];

            GLU.gluLookAt(ScrollValue[0], ScrollValue[1], ScrollValue[2],
                          ScrollValue[3], ScrollValue[4], ScrollValue[5],
                          ScrollValue[6], ScrollValue[7], ScrollValue[8]);
            GL.glTranslatef(0.0f, 0.0f, -1.0f);

            DrawOldAxes();

            //save current ModelView Matrix values
            //in ModelVievMatrixBeforeSpecificTransforms array
            //ModelView Matrix ========>>>>>> ModelVievMatrixBeforeSpecificTransforms
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, ModelVievMatrixBeforeSpecificTransforms);
            //ModelView Matrix was saved, so
            GL.glLoadIdentity(); // make it identity matrix

            //make transformation in accordance to KeyCode
            float delta;

            if (intOptionC != 0)
            {
                delta = 5.0f * Math.Abs(intOptionC) / intOptionC; // signed 5

                switch (Math.Abs(intOptionC))
                {
                case 1:
                    GL.glRotatef(delta, 1, 0, 0);
                    break;

                case 2:
                    GL.glRotatef(delta, 0, 1, 0);
                    break;

                case 3:
                    GL.glRotatef(delta, 0, 0, 1);
                    break;

                case 4:
                    GL.glTranslatef(delta / 20, 0, 0);
                    break;

                case 5:
                    GL.glTranslatef(0, delta / 20, 0);
                    break;

                case 6:
                    GL.glTranslatef(0, 0, delta / 20);
                    break;
                }
            }
            //as result - the ModelView Matrix now is pure representation
            //of KeyCode transform and only it !!!

            //save current ModelView Matrix values
            //in CurrentRotationTraslation array
            //ModelView Matrix =======>>>>>>> CurrentRotationTraslation
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, CurrentRotationTraslation);

            //The GL.glLoadMatrix function replaces the current matrix with
            //the one specified in its argument.
            //The current matrix is the
            //projection matrix, modelview matrix, or texture matrix,
            //determined by the current matrix mode (now is ModelView mode)
            GL.glLoadMatrixd(AccumulatedRotationsTraslations); //Global Matrix

            //The GL.glMultMatrix function multiplies the current matrix by
            //the one specified in its argument.
            //That is, if M is the current matrix and T is the matrix passed to
            //GL.glMultMatrix, then M is replaced with M • T
            GL.glMultMatrixd(CurrentRotationTraslation);

            //save the matrix product in AccumulatedRotationsTraslations
            GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations);

            //replace ModelViev Matrix with stored ModelVievMatrixBeforeSpecificTransforms
            GL.glLoadMatrixd(ModelVievMatrixBeforeSpecificTransforms);
            //multiply it by KeyCode defined AccumulatedRotationsTraslations matrix
            GL.glMultMatrixd(AccumulatedRotationsTraslations);

            DrawAxes();

            DrawFigures();

            GL.glFlush();

            WGL.wglSwapBuffers(m_uint_DC);
        }