Esempio n. 1
0
 protected void dsSetTexture(DS_TEXTURE_NUMBER texture_number)
 {
     if (current_state != 2)
         throw new Exception("drawing function called outside simulation loop");
     tnum = texture_number;
 }
Esempio n. 2
0
        void dsDrawFrame(int width, int height, bool pause)
        {
            if (current_state < 1)
                throw new Exception("internal error");
            current_state = 2;

            // setup stuff
            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);
            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.TextureGenS);
            GL.Disable(EnableCap.TextureGenT);
            GL.ShadeModel(ShadingModel.Flat);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.FrontFace(FrontFaceDirection.Ccw);

            // setup viewport
            GL.Viewport(0, 0, width, height);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            float vnear = 0.1f;
            float vfar = 1000.0f;
            float k = 0.8f;     // view scale, 1 = +/- 45 degrees
            if (width >= height)
            {
                float k2 = (float)height / (float)width;
                GL.Frustum(-vnear * k, vnear * k, -vnear * k * k2, vnear * k * k2, vnear, vfar);
            }
            else
            {
                float k2 = (float)width / (float)height;
                GL.Frustum(-vnear * k * k2, vnear * k * k2, -vnear * k, vnear * k, vnear, vfar);
            }

            // setup lights. it makes a difference whether this is done in the
            // GL_PROJECTION matrix mode (lights are scene relative) or the
            // GL_MODELVIEW matrix mode (lights are camera relative, bad!).
            //		static GLfloat light_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
            //		static GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
            //		static GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
            GL.Light(LightName.Light0, LightParameter.Ambient, light_ambient);
            GL.Light(LightName.Light0, LightParameter.Diffuse, light_diffuse);
            GL.Light(LightName.Light0, LightParameter.Specular, light_specular);
            GL.Color3(1.0f, 1.0f, 1.0f);

            // clear the window
            //GL.ClearColor(0.5f, 0.5f, 0.5f, 0);
            GL.ClearColor(clearColor.R / 255f, clearColor.G / 255f, clearColor.B / 255f, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // snapshot camera position (in MS Windows it is changed by the GUI thread)
            float[] view2_xyz = (float[])view_xyz.Clone();
            float[] view2_hpr = (float[])view_hpr.Clone();
            //		memcpy (view2_xyz,view_xyz);//,sizeof(float)*3);
            //		memcpy (view2_hpr,view_hpr);//,sizeof(float)*3);

            // go to GL_MODELVIEW matrix mode and set the camera
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            setCamera(view2_xyz[0], view2_xyz[1], view2_xyz[2],
                    view2_hpr[0], view2_hpr[1], view2_hpr[2]);

            // set the light position (for some reason we have to do this in model view.
            //		static GLfloat light_position[] = { LIGHTX, LIGHTY, 1.0, 0.0 };
            GL.Light(LightName.Light0, LightParameter.Position, light_position);

            // draw the background (ground, sky etc)
            drawSky(view2_xyz);
            drawGround();

            // draw the little markers on the ground
            drawPyramidGrid();

            // leave openGL in a known state - flat shaded white, no textures
            GL.Enable(EnableCap.Lighting);
            GL.Disable(EnableCap.Texture2D);
            GL.ShadeModel(ShadingModel.Flat);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            GL.Color3(1.0f, 1.0f, 1.0f);
            setColor(1.0f, 1.0f, 1.0f, 1.0f);

            // draw the rest of the objects. set drawing state first.
            color[0] = 1.0f;
            color[1] = 1.0f;
            color[2] = 1.0f;
            color[3] = 1.0f;
            tnum = DS_TEXTURE_NUMBER.DS_NONE;
            //if (fn.step) 
            //fn.step(pause);
        }