예제 #1
0
        public unsafe void DrawBox(bool drawChildren, bool bindBox)
        {
            Box box = bindBox ? _extents : GetBox();

            if (bindBox)
            {
                GL.MatrixMode(MatrixMode.Modelview);
                GL.PushMatrix();

                fixed(Matrix *m = &_frameMatrix)
                GL.MultMatrix((float *)m);
            }

            TKContext.DrawWireframeBox(box);

            if (bindBox)
            {
                GL.PopMatrix();
            }

            if (drawChildren)
            {
                foreach (MDL0BoneNode b in Children)
                {
                    b.DrawBox(true, bindBox);
                }
            }
        }
예제 #2
0
        public void DebugDump(string name, ConsoleColor color, params string[] data)
        {
            if (!TKContext.DebugLogging)
            {
                return;
            }

            //Build
            string msg          = $"";
            bool   wasLastLabel = false;

            foreach (string s in data)
            {
                if (!wasLastLabel)
                {
                    msg += s + "=";
                }
                else
                {
                    msg += s + ", ";
                }
                wasLastLabel = !wasLastLabel;
            }

            TKContext.DebugLog("UassetFile", name, msg, color);
        }
예제 #3
0
        internal unsafe void Render(TKContext ctx)
        {
            if (!_render)
            {
                return;
            }

            //bool t = !_flags[1] && _linkedBone != null;
            //if (t)
            //{
            //    //Apply bone transform
            //    GL.PushMatrix();
            //    fixed (Matrix* m = &_linkedBone._frameMatrix)
            //        GL.MultMatrix((float*)m);
            //}

            foreach (CollisionPlane p in _planes)
            {
                p.DrawPlanes();
            }
            foreach (CollisionLink l in _points)
            {
                l.Render(ctx);
            }

            //if (t)
            //    GL.PopMatrix();
        }
예제 #4
0
        public static unsafe GLTexture CreateBG(TKContext ctx)
        {
            GLTexture tex = new GLTexture(16, 16);

            tex._texId = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, tex._texId);

            int *      pixelData = stackalloc int[16 * 16];
            RGBAPixel *p         = (RGBAPixel *)pixelData;

            for (int y = 0; y < 16; y++)
            {
                for (int x = 0; x < 16; x++)
                {
                    *p++ = ((x & 8) == (y & 8)) ? _left : _right;
                }
            }

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Four, 16, 16, 0, PixelFormat.Rgba, PixelType.UnsignedByte, (VoidPtr)pixelData);

            return(tex);
        }
예제 #5
0
 internal void Bind(TKContext ctx)
 {
     foreach (MDL0EntryNode e in Children)
     {
         e.Bind(ctx);
     }
 }
예제 #6
0
        public unsafe void RenderTransformControl(TKContext context)
        {
            if (_playing)
            {
                return;
            }

            if (SelectedBone != null) //Render drag and drop control
            {
                if (_editType == TransformType.Rotation)
                {
                    RenderRotationControl(context, BoneLoc, OrbRadius, SelectedBone._frameMatrix.GetAngles());
                }
                else if (_editType == TransformType.Translation)
                {
                    RenderTranslationControl(context, BoneLoc, OrbRadius);
                }
                else if (_editType == TransformType.Scale)
                {
                    RenderScaleControl(context);
                }
            }

            if (VertexLoc != null && RenderVertices)
            {
                //if (_editType == TransformType.Rotation)
                //    RenderRotationControl(context, ((Vector3)VertexLoc), VertexOrbRadius, _oldAngles);
                //else
                RenderTranslationControl(context, ((Vector3)VertexLoc), VertexOrbRadius);
            }
        }
예제 #7
0
        private unsafe void RenderCatchCollision(Vector3 cam)
        {
            ResourceNode[] bl = _model._linker.BoneCache;

            int boneindex = _parameters[1];
            int size      = HitboxSize;

            Root.GetBoneIndex(ref boneindex);

            if (boneindex == 0) // if a hitbox is on TopN, make it follow TransN
            {
                if (Root.Data != null)
                {
                    boneindex = Root.Data._misc._boneRefs[4].boneIndex;
                    Root.GetBoneIndex(ref boneindex);
                }
                else
                {
                    int transindex = 0;
                    foreach (MDL0BoneNode bn in bl)
                    {
                        if (bn.Name.Equals("TransN"))
                        {
                            break;
                        }
                        transindex++;
                    }
                    if (transindex != bl.Length)
                    {
                        boneindex = transindex;
                    }
                }
            }
            MDL0BoneNode b = bl[boneindex] as MDL0BoneNode;

            Matrix     r         = b.Matrix.GetRotationMatrix();
            FrameState state     = b.Matrix.Derive();
            Vector3    bonePos   = state._translate;
            Vector3    pos       = new Vector3(Util.UnScalar(_parameters[3]), Util.UnScalar(_parameters[4]), Util.UnScalar(_parameters[5])) / state._scale;
            Vector3    globalPos = r.Multiply(pos);

            Matrix  m         = Matrix.TransformMatrix(new Vector3(1), state._rotate, globalPos + bonePos);
            Vector3 resultPos = m.GetPoint();

            m = Matrix.TransformMatrix(new Vector3(Util.UnScalar(size)), new Vector3(), resultPos);
            GL.PushMatrix();
            GL.MultMatrix((float *)&m);
            int    res       = 16;
            double drawangle = 360.0 / res;

            Vector3 color = Util.GetTypeColor(Util.HitboxType.Throwing);

            GL.Color4((color._x / 255.0f), (color._y / 225.0f), (color._z / 255.0f), 0.375f);
            GLDisplayList spheres = TKContext.GetSphereList();

            spheres.Call();

            GL.PopMatrix();
        }
예제 #8
0
 public static string WriteBinding(uint num, TKContext ctx)
 {
     if (!ctx.bSupportsGLSLBinding)
     {
         return("");
     }
     return(String.Format("layout(binding = {0}) ", num));
 }
예제 #9
0
 internal override void Unbind()
 {
     if (Texture != null)
     {
         Texture.Delete();
         Texture = null;
     }
     _context = null;
     Rendered = false;
 }
        unsafe internal override void OnInit(TKContext ctx)
        {
            //Set caps
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            _attached = new List <ResourceNode>();
            ctx._states["_Node_Refs"] = _attached;
        }
예제 #11
0
        unsafe internal override void OnInit(TKContext ctx)
        {
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Enable(EnableCap.LineSmooth);
            GL.Enable(EnableCap.PointSmooth);
            GL.LineWidth(_lineWidth);
            GL.PointSize(_pointWidth);
        }
예제 #12
0
        public void Render(TKContext ctx, ModelPanel mainWindow)
        {
            GL.Disable(EnableCap.Lighting);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Front);

            foreach (CollisionObject obj in _objects)
            {
                obj.Render(ctx);
            }
        }
예제 #13
0
        unsafe internal override void OnInit(TKContext ctx)
        {
            //Set caps
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            UpdateProjection();
        }
예제 #14
0
        internal override void Bind(TKContext ctx)
        {
            //Unbind(ctx);

            if (Name == "TShadow1")
            {
                Enabled = false;
            }

            _context = ctx;

            Selected = false;
            //Enabled = true;
        }
        internal unsafe override void OnInit(TKContext ctx)
        {
            //Share lists with original context
            //if (_currentTexture != null)
            //    _currentTexture._context.Share(_context);

            //Set caps
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            OnResized();
        }
예제 #16
0
        unsafe internal override void OnInit(TKContext ctx)
        {
            //Share lists with original context
            //if (_currentTexture != null)
            //    _currentTexture._context.Share(_context);

            //Set caps
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            OnResized();
        }
예제 #17
0
        public static void OnRenderFloor()
        {
            float s = 10.0f, t = 10.0f;
            float e = 30.0f;

            GL.PushAttrib(AttribMask.AllAttribBits);

            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.Lighting);
            GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
            GL.PolygonMode(MaterialFace.Back, PolygonMode.Fill);

            //So that the model clips with the floor
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);
            GL.MatrixMode(MatrixMode.Texture);
            GL.LoadIdentity();

            GLTexture bgTex = TKContext.FindOrCreate("TexBG", GLTexturePanel.CreateBG);

            bgTex.Bind();

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                            (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
                            (int)TextureMagFilter.Nearest);

            GL.Color4(_floorHue);

            GL.Begin(BeginMode.Quads);

            GL.TexCoord2(0.0f, 0.0f);
            GL.Vertex3(-e, 0.0f, -e);
            GL.TexCoord2(s, 0.0f);
            GL.Vertex3(e, 0.0f, -e);
            GL.TexCoord2(s, t);
            GL.Vertex3(e, 0.0f, e);
            GL.TexCoord2(0.0f, t);
            GL.Vertex3(-e, 0.0f, e);

            GL.End();

            GL.Disable(EnableCap.Texture2D);

            GL.PopAttrib();
        }
예제 #18
0
        public void Render(Color4 clr, float mult)
        {
            if (_highlight)
            {
                GL.Color4(1.0f, 1.0f, 0.0f, 1.0f);
            }
            else
            {
                GL.Color4(clr);
            }

            Vector2 v = Value;

            TKContext.DrawBox(
                new Vector3(v._x - mult * BoxRadius, v._y - mult * BoxRadius, LineWidth),
                new Vector3(v._x + mult * BoxRadius, v._y + mult * BoxRadius, -LineWidth));
        }
예제 #19
0
        public void Render(TKContext ctx)
        {
            if (_highlight)
            {
                GL.Color4(1.0f, 1.0f, 0.0f, 1.0f);
            }
            else
            {
                GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            }

            Vector2 v = Value;

            ctx.DrawBox(
                new Vector3(v._x - BoxRadius, v._y - BoxRadius, LineWidth),
                new Vector3(v._x + BoxRadius, v._y + BoxRadius, -LineWidth));
        }
예제 #20
0
        public unsafe void RenderTranslationControl(TKContext context, Vector3 position, float radius)
        {
            GLDisplayList axis = GetAxes();

            //Enter local space
            Matrix m = Matrix.TransformMatrix(new Vector3(radius), new Vector3(), position);

            GL.PushMatrix();
            GL.MultMatrix((float *)&m);

            axis.Call();

            GL.PopMatrix();

            modelPanel.ScreenText["X"] = modelPanel.Project(new Vector3(_axisLDist + 0.1f, 0, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            modelPanel.ScreenText["Y"] = modelPanel.Project(new Vector3(0, _axisLDist + 0.1f, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            modelPanel.ScreenText["Z"] = modelPanel.Project(new Vector3(0, 0, _axisLDist + 0.1f) * m) - new Vector3(8.0f, 8.0f, 0);
        }
예제 #21
0
        public unsafe void RenderScaleControl(TKContext context)
        {
            GLDisplayList axis = GetScaleControl();

            //Enter local space
            Matrix m = Matrix.TransformMatrix(new Vector3(OrbRadius), new Vector3(), BoneLoc);

            GL.PushMatrix();
            GL.MultMatrix((float *)&m);

            axis.Call();

            GL.PopMatrix();

            modelPanel.ScreenText["X"] = modelPanel.Project(new Vector3(_axisLDist + 0.1f, 0, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            modelPanel.ScreenText["Y"] = modelPanel.Project(new Vector3(0, _axisLDist + 0.1f, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            modelPanel.ScreenText["Z"] = modelPanel.Project(new Vector3(0, 0, _axisLDist + 0.1f) * m) - new Vector3(8.0f, 8.0f, 0);
        }
예제 #22
0
        public static bool TryGetDataFromURL(string url, out string output)
        {
            try
            {
                WebClient wc  = new System.Net.WebClient();
                byte[]    raw = wc.DownloadData(url);

                output = Encoding.UTF8.GetString(raw);
                return(true);
            }
            catch (Exception ex)
            {
                output = "";

                TKContext.LogException(ex.ToString());
                return(false);
            }
        }
예제 #23
0
        public static GLDisplayList CreateNodeOrb()
        {
            GLDisplayList circle = TKContext.GetRingList();
            GLDisplayList orb    = new GLDisplayList();

            orb.Begin();
            GL.PushMatrix();

            GL.Scale(_nodeRadius, _nodeRadius, _nodeRadius);
            circle.Call();
            GL.Rotate(90.0f, 0.0f, 1.0f, 0.0f);
            circle.Call();
            GL.Rotate(90.0f, 1.0f, 0.0f, 0.0f);
            circle.Call();

            GL.PopMatrix();
            orb.End();
            return(orb);
        }
예제 #24
0
        public void Render(TKContext ctx, Vector3 cam)
        {
            switch (_event)
            {
            case 0x06000D00:
            case 0x062B0D00:
                RenderOffensiveCollision(ctx, cam);
                break;

            case 0x06150F00:
                RenderSpecialOffensiveCollision(ctx, cam);
                break;

            case 0x060A0800:
            case 0x060A0900:
            case 0x060A0A00:
                RenderCatchCollision(ctx, cam);
                break;
            }
        }
예제 #25
0
        private void lstDrawCalls_DoubleClick(object sender, EventArgs e)
        {
            if (_updating)
            {
                return;
            }

            DrawCall drawCall = lstDrawCalls.SelectedItem as DrawCall;

            if (drawCall != null)
            {
                drawCall._render = !drawCall._render;
                lstDrawCalls.SetItemChecked(lstDrawCalls.SelectedIndex, drawCall._render);

                if (_targetObject?.Model != null)
                {
                    TKContext.InvalidateModelPanels(_targetObject.Model);
                }
            }
        }
        public static unsafe GLTexture CreateBG(TKContext ctx)
        {
            GLTexture tex = new GLTexture(16, 16);
            tex._texId = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, tex._texId);

            int* pixelData = stackalloc int[16 * 16];
            RGBAPixel* p = (RGBAPixel*)pixelData;

            for (int y = 0; y < 16; y++)
                for (int x = 0; x < 16; x++)
                    *p++ = ((x & 8) == (y & 8)) ? _left : _right;

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Four, 16, 16, 0, PixelFormat.Rgba, PixelType.UnsignedByte, (VoidPtr)pixelData);

            return tex;
        }
예제 #27
0
 internal void Bind(TKContext ctx, int prog)
 {
     if (!String.IsNullOrEmpty(PAT0Texture))
     {
         if (!PAT0Textures.ContainsKey(PAT0Texture))
         {
             PAT0Textures[PAT0Texture] = new MDL0TextureNode(PAT0Texture)
             {
                 Source = null, palette = !String.IsNullOrEmpty(PAT0Palette) ? RootNode.FindChildByType(PAT0Palette, true, ResourceNodes.ResourceType.PLT0) as PLT0Node : null
             }
         }
         ;
         MDL0TextureNode t = PAT0Textures[PAT0Texture];
         t.Bind(ctx);
         t.Prepare(this, prog);
     }
     else if (_texture != null)
     {
         _texture.Prepare(this, prog);
     }
 }
예제 #28
0
        public static unsafe int IndexOfPattern(byte[] src, byte[] pattern)
        {
            fixed(byte *srcPtr = &src[0])
            fixed(byte *patternPtr = &pattern[0])
            {
                for (int x = 0; x < src.Length; x++)
                {
                    byte currentValue = *(srcPtr + x);

                    if (currentValue != *patternPtr)
                    {
                        continue;
                    }

                    bool match = false;

                    for (int y = 0; y < pattern.Length; y++)
                    {
                        byte tempValue = *(srcPtr + x + y);
                        if (tempValue != *(patternPtr + y))
                        {
                            match = false;
                            break;
                        }

                        match = true;
                    }

                    if (match)
                    {
                        return(x);
                    }
                }
            }

            TKContext.LogInner("WARNING", "No pattern found!", ConsoleColor.Yellow);

            return(-1);
        }
예제 #29
0
        private unsafe void modelPanel1_PreRender(object sender, TKContext ctx)
        {
            if (RenderFloor)
            {
                GLTexture _bgTex = ctx.FindOrCreate <GLTexture>("TexBG", GLTexturePanel.CreateBG);

                float s = 10.0f, t = 10.0f;
                float e = 30.0f;

                GL.Disable(EnableCap.CullFace);
                GL.Disable(EnableCap.Blend);
                GL.Disable(EnableCap.Lighting);
                GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
                GL.PolygonMode(MaterialFace.Back, PolygonMode.Fill);

                GL.Enable(EnableCap.Texture2D);

                GL.Color4(StaticMainWindow._floorHue);

                _bgTex.Bind();

                GL.Begin(BeginMode.Quads);

                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex3(-e, 0.0f, -e);
                GL.TexCoord2(s, 0.0f);
                GL.Vertex3(e, 0.0f, -e);
                GL.TexCoord2(s, t);
                GL.Vertex3(e, 0.0f, e);
                GL.TexCoord2(0, t);
                GL.Vertex3(-e, 0.0f, e);

                GL.End();

                GL.Disable(EnableCap.Texture2D);
            }

            Attributes.PreRender();
        }
예제 #30
0
        public void SetProgramVariables(TKContext ctx)
        {
            if (ctx.bSupportsGLSLUBO)
            {
                GL.UniformBlockBinding(_programHandle, 0, 1);
                if (vertexShaderHandle != 0)
                {
                    GL.UniformBlockBinding(_programHandle, 1, 2);
                }
            }

            if (!ctx.bSupportsGLSLUBO)
            {
                for (int a = 8; a < UniformNames.Length; a++)
                {
                    UniformLocations[a] = GL.GetUniformLocation(_programHandle, UniformNames[a]);
                }
            }

            if (!ctx.bSupportsGLSLBinding)
            {
                for (int a = 0; a < 8; a++)
                {
                    if ((UniformLocations[a] = GL.GetUniformLocation(_programHandle, UniformNames[a])) != -1)
                    {
                        GL.Uniform1(UniformLocations[a], a);
                    }
                }
            }

            // Need to get some attribute locations
            if (vertexShaderHandle != 0 && !ctx.bSupportsGLSLATTRBind)
            {
                // We have no vertex Shader
                GL.BindAttribLocation(_programHandle, SHADER_NORM1_ATTRIB, "rawnorm1");
                GL.BindAttribLocation(_programHandle, SHADER_NORM2_ATTRIB, "rawnorm2");
                GL.BindAttribLocation(_programHandle, SHADER_POSMTX_ATTRIB, "fposmtx");
            }
        }
예제 #31
0
        internal unsafe override void OnInit(TKContext ctx)
        {
            Vector3 v = (Vector3)BackColor;

            GL.ClearColor(v._x, v._y, v._z, 0.0f);
            GL.ClearDepth(1.0);

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);

            GL.ShadeModel(ShadingModel.Smooth);

            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);
            GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
            GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Nicest);
            GL.Hint(HintTarget.GenerateMipmapHint, HintMode.Nicest);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Enable(EnableCap.AlphaTest);
            GL.AlphaFunc(AlphaFunction.Gequal, 0.1f);

            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);

            GL.PointSize(3.0f);
            GL.LineWidth(2.0f);
            GL.Disable(EnableCap.PointSmooth);
            GL.Disable(EnableCap.PolygonSmooth);
            GL.Disable(EnableCap.LineSmooth);

            GL.Enable(EnableCap.Normalize);

            //Set client states
            ctx._states["_Node_Refs"] = _resourceList;
        }
예제 #32
0
        protected internal override void OnRender(TKContext ctx, PaintEventArgs e)
        {
            if (_showCamCoords)
            {
                Vector3 v = _camera.GetPoint().Round(3);
                Vector3 r = _camera._rotation.Round(3);
                ScreenText[String.Format("Position\nX: {0}\nY: {1}\nZ: {2}\n\nRotation\nX: {3}\nY: {4}\nZ: {5}", v._x, v._y, v._z, r._x, r._y, r._z)] = new Vector3(5.0f, 5.0f, 0.5f);
            }

            if (_ctx._needsUpdate)
            {
                OnInit(ctx);
                OnResized();
                _ctx._needsUpdate = false;
            }

            if (_bgImage == null)
            {
                GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);
            }

            RecalcLight();

            if (PreRender != null)
            {
                PreRender(this, ctx);
            }

            foreach (IRenderedObject o in _settings._renderList)
            {
                o.Render(ctx, this);
            }

            if (PostRender != null)
            {
                PostRender(this, ctx);
            }
        }
예제 #33
0
        public void Attach(TKContext ctx)
        {
            _visible = true;
            ApplyCHR(null, 0);
            ApplySRT(null, 0);

            foreach (MDL0GroupNode g in Children)
                g.Bind(ctx);

            VIS0Indices = new Dictionary<string, List<int>>(); int i = 0;
            if (_objList != null)
            foreach (MDL0ObjectNode p in _objList)
            {
                if (p._bone != null && p._bone.BoneIndex != 0)
                    if (VIS0Indices.ContainsKey(p._bone.Name))
                        if (!VIS0Indices[p._bone.Name].Contains(i))
                            VIS0Indices[p._bone.Name].Add(i);
                        else { }
                    else VIS0Indices.Add(p._bone.Name, new List<int> { i });
                i++;
            }
        }
예제 #34
0
        public unsafe void RenderRotationControl(TKContext context, Vector3 position, float radius, Vector3 rotate)
        {
            Matrix m = Matrix.TransformMatrix(new Vector3(radius), position.LookatAngles(CamLoc) * Maths._rad2degf, position);

            GL.PushMatrix();
            GL.MultMatrix((float*)&m);

            GLDisplayList sphere = context.GetCircleList();
            GLDisplayList circle = context.GetRingList();

            //Orb
            GL.Color4(0.7f, 0.7f, 0.7f, 0.15f);
            sphere.Call();

            GL.Disable(EnableCap.DepthTest);

            //Container
            GL.Color4(0.4f, 0.4f, 0.4f, 1.0f);
            circle.Call();

            //Circ
            if (_snapCirc || _hiCirc)
                GL.Color4(Color.Yellow);
            else
                GL.Color4(1.0f, 0.8f, 0.5f, 1.0f);
            GL.Scale(_circOrbScale, _circOrbScale, _circOrbScale);
            circle.Call();

            //Pop
            GL.PopMatrix();

            GL.Enable(EnableCap.DepthTest);

            //Enter local space
            m = Matrix.TransformMatrix(new Vector3(radius), rotate, position);

            ModelPanel.ScreenText["X"] = ModelPanel.Project(new Vector3(1.1f, 0, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            ModelPanel.ScreenText["Y"] = ModelPanel.Project(new Vector3(0, 1.1f, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            ModelPanel.ScreenText["Z"] = ModelPanel.Project(new Vector3(0, 0, 1.1f) * m) - new Vector3(8.0f, 8.0f, 0);

            GL.PushMatrix();
            GL.MultMatrix((float*)&m);

            //Z
            if (_snapZ || _hiZ)
                GL.Color4(Color.Yellow);
            else
                GL.Color4(0.0f, 0.0f, 1.0f, 1.0f);

            circle.Call();
            GL.Rotate(90.0f, 0.0f, 1.0f, 0.0f);

            //X
            if (_snapX || _hiX)
                GL.Color4(Color.Yellow);
            else
                GL.Color4(Color.Red);

            circle.Call();
            GL.Rotate(90.0f, 1.0f, 0.0f, 0.0f);

            //Y
            if (_snapY || _hiY)
                GL.Color4(Color.Yellow);
            else
                GL.Color4(Color.Green);

            circle.Call();

            //Pop
            GL.PopMatrix();
        }
 private void _modelPanel_PreRender(object sender, TKContext context)
 {
 }
        internal unsafe override void OnInit(TKContext ctx)
        {
            //Set caps
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Enable(EnableCap.LineSmooth);
            GL.Enable(EnableCap.PointSmooth);
            GL.LineWidth(_lineWidth);
            GL.PointSize(_pointWidth);

            OnResized();
        }
 internal override void Bind(TKContext ctx)
 {
     _renderUpdate = true;
 }
예제 #38
0
        private unsafe void modelPanel1_PostRender(object sender, TKContext context)
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Disable(EnableCap.Lighting);
            GL.Enable(EnableCap.DepthTest);

            if (RenderVertices)
                if (_editingAll && _targetModels != null)
                    foreach (MDL0Node m in _targetModels)
                        m.RenderVertices(context, false);
                else if (TargetModel != null)
                    TargetModel.RenderVertices(context, false);

            if (RenderNormals)
                if (_editingAll && _targetModels != null)
                    foreach (MDL0Node m in _targetModels)
                        m.RenderNormals(context);
                else if (TargetModel != null)
                    TargetModel.RenderNormals(context);

            //Show the user where the light source is
            if (_renderLightDisplay)
            {
                GL.Color4(Color.Blue);
                GL.Disable(EnableCap.Lighting);
                GL.Disable(EnableCap.DepthTest);

                GL.Scale(ModelPanel.LightPosition._x, ModelPanel.LightPosition._x, ModelPanel.LightPosition._x);

                GL.Rotate(90.0f, 1, 0, 0);

                float azimuth = ModelPanel.LightPosition._y.Clamp180Deg();
                float elevation = ModelPanel.LightPosition._z.Clamp180Deg();

                if (Math.Abs(azimuth) == Math.Abs(elevation) && azimuth % 180.0f == 0 && elevation % 180.0f == 0)
                {
                    azimuth = 0;
                    elevation = 0;
                }

                int i; float x;
                float e = azimuth;

                bool flip = false;
                if (e < 0)
                {
                    e = -e;
                    flip = true;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                float f = (float)((int)e);
                float diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }
                GL.End();

                if (flip) GL.Rotate(-180.0f, 1, 0, 0);

                GL.Rotate(90.0f, 0, 1, 0);
                GL.Rotate(90.0f, 0, 0, 1);
                GL.Rotate(180.0f, 1, 0, 0);
                GL.Rotate(90.0f - azimuth, 0, 1, 0);

                e = elevation;

                if (e < 0)
                {
                    e = -e;
                    GL.Rotate(180.0f, 1, 0, 0);
                }

                f = (float)((int)e);
                diff = (float)Math.Round(e - f, 1);

                GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
                for (i = 0; i < f; i++)
                {
                    GL.Vertex2(Math.Cos(i * Maths._deg2radf), Math.Sin(i * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((i + 1) * Maths._deg2radf), Math.Sin((i + 1) * Maths._deg2radf));
                }
                for (x = 0; x < diff; x += 0.1f)
                {
                    GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                    GL.Vertex2(Math.Cos((x + 0.1f + (float)i) * Maths._deg2radf), Math.Sin((x + 0.1f + (float)i) * Maths._deg2radf));
                }

                GL.Vertex2(Math.Cos((x + (float)i) * Maths._deg2radf), Math.Sin((x + (float)i) * Maths._deg2radf));
                GL.Color4(Color.Orange);
                GL.Vertex3(0, 0, 0);

                GL.End();
            }

            GL.Clear(ClearBufferMask.DepthBufferBit);

            RenderSCN0Controls(context);
            RenderTransformControl(context);

            if (!ModelPanel._grabbing && !ModelPanel._scrolling && !_playing)
            {
                GL.Color4(Color.Black);
                GL.ColorMask(false, false, false, false);

                if (RenderVertices)
                    if (_editingAll && _targetModels != null)
                        foreach (MDL0Node m in _targetModels)
                            m.RenderVertices(context, true);
                    else if (TargetModel != null)
                        TargetModel.RenderVertices(context, true);

                if (RenderBones)
                {
                    //Render invisible depth orbs
                    GLDisplayList list = context.GetSphereList();
                    if (_editingAll)
                    {
                        foreach (MDL0Node m in _targetModels)
                            foreach (MDL0BoneNode bone in m._linker.BoneCache)
                                if (bone != SelectedBone)
                                    RenderOrb(bone, list);
                    }
                    else if (TargetModel != null && TargetModel._linker != null && TargetModel._linker.BoneCache != null)
                        foreach (MDL0BoneNode bone in _targetModel._linker.BoneCache)
                            if (bone != SelectedBone)
                                RenderOrb(bone, list);
                }

                //Render invisible depth planes for translation and scale controls
                if (_editType != TransformType.Rotation && ((SelectedBone != null && RenderBones) || (VertexLoc != null && RenderVertices)))
                {
                    #region Axis Selection Display List

                    GLDisplayList selList = new GLDisplayList();

                    selList.Begin();

                    GL.Begin(BeginMode.Quads);

                    //X Axis
                    //XY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, _axisSelectRange, 0.0f);
                    GL.Vertex3(_axisLDist, -_axisSelectRange, 0.0f);
                    //XZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, _axisSelectRange);
                    GL.Vertex3(_axisLDist, 0.0f, -_axisSelectRange);

                    //Y Axis
                    //YX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, _axisLDist, 0.0f);
                    GL.Vertex3(-_axisSelectRange, _axisLDist, 0.0f);
                    //YZ quad
                    GL.Vertex3(0.0f, 0.0f, -_axisSelectRange);
                    GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, _axisSelectRange);
                    GL.Vertex3(0.0f, _axisLDist, -_axisSelectRange);

                    //Z Axis
                    //ZX quad
                    GL.Vertex3(-_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                    GL.Vertex3(_axisSelectRange, 0.0f, _axisLDist);
                    GL.Vertex3(-_axisSelectRange, 0.0f, _axisLDist);
                    //ZY quad
                    GL.Vertex3(0.0f, -_axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                    GL.Vertex3(0.0f, _axisSelectRange, _axisLDist);
                    GL.Vertex3(0.0f, -_axisSelectRange, _axisLDist);

                    GL.End();

                    selList.End();

                    #endregion

                    if (_editType != TransformType.Rotation && SelectedBone != null)
                    {
                        Matrix m = Matrix.TransformMatrix(new Vector3(OrbRadius), new Vector3(), BoneLoc);
                        GL.PushMatrix();
                        GL.MultMatrix((float*)&m);

                        selList.Call();

                        if (_editType == TransformType.Translation)
                        {
                            GL.Begin(BeginMode.Quads);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);
                            GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisSelectRange);
                            GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);
                            GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);
                            GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);

                            GL.End();
                        }
                        else
                        {
                            GL.Begin(BeginMode.Triangles);

                            //XY
                            GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                            GL.Vertex3(_scaleHalf2LDist, _axisSelectRange, 0.0f);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, 0.0f);

                            //YZ
                            GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                            GL.Vertex3(0.0f, _scaleHalf2LDist, _axisSelectRange);
                            GL.Vertex3(0.0f, 0.0f, _scaleHalf2LDist);

                            //XZ
                            GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                            GL.Vertex3(_axisSelectRange, 0.0f, _scaleHalf2LDist);
                            GL.Vertex3(_scaleHalf2LDist, 0.0f, 0.0f);

                            GL.End();
                        }

                        GL.PopMatrix();
                    }

                    if (VertexLoc != null && RenderVertices)
                    {
                        Matrix m = Matrix.TransformMatrix(new Vector3(VertexOrbRadius), new Vector3(), ((Vector3)VertexLoc));
                        GL.PushMatrix();
                        GL.MultMatrix((float*)&m);

                        selList.Call();

                        GL.Begin(BeginMode.Quads);

                        //XY
                        GL.Vertex3(0.0f, _axisSelectRange, 0.0f);
                        GL.Vertex3(_axisHalfLDist, _axisSelectRange, 0.0f);
                        GL.Vertex3(_axisHalfLDist, _axisHalfLDist, 0.0f);
                        GL.Vertex3(0.0f, _axisHalfLDist, 0.0f);

                        //YZ
                        GL.Vertex3(0.0f, 0.0f, _axisSelectRange);
                        GL.Vertex3(0.0f, _axisHalfLDist, _axisSelectRange);
                        GL.Vertex3(0.0f, _axisHalfLDist, _axisHalfLDist);
                        GL.Vertex3(0.0f, 0.0f, _axisHalfLDist);

                        //XZ
                        GL.Vertex3(_axisSelectRange, 0.0f, 0.0f);
                        GL.Vertex3(_axisSelectRange, 0.0f, _axisHalfLDist);
                        GL.Vertex3(_axisHalfLDist, 0.0f, _axisHalfLDist);
                        GL.Vertex3(_axisHalfLDist, 0.0f, 0.0f);

                        GL.End();

                        GL.PopMatrix();
                    }
                }

                GL.ColorMask(true, true, true, true);
            }
        }
 internal void Bind(TKContext ctx, int prog)
 {
     if (!String.IsNullOrEmpty(PAT0Texture))
     {
         if (!PAT0Textures.ContainsKey(PAT0Texture))
             PAT0Textures[PAT0Texture] = new MDL0TextureNode(PAT0Texture) { Source = null, palette = !String.IsNullOrEmpty(PAT0Palette) ? RootNode.FindChildByType(PAT0Palette, true, ResourceNodes.ResourceType.PLT0) as PLT0Node : null };
         MDL0TextureNode t = PAT0Textures[PAT0Texture];
         t.Bind(ctx);
         t.Prepare(this, prog);
     }
     else if (_texture != null)
         _texture.Prepare(this, prog);
 }
        public void Render(TKContext ctx, ModelPanel mainWindow)
        {
            GL.Disable(EnableCap.Lighting);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Front);

            foreach (CollisionObject obj in _objects)
                obj.Render(ctx);
        }
        internal unsafe void Render(TKContext ctx)
        {
            if (!_render)
                return;

            //bool t = !_flags[1] && _linkedBone != null;
            //if (t)
            //{
            //    //Apply bone transform
            //    GL.PushMatrix();
            //    fixed (Matrix* m = &_linkedBone._frameMatrix)
            //        GL.MultMatrix((float*)m);
            //}

            foreach (CollisionPlane p in _planes)
                p.DrawPlanes();
            foreach (CollisionLink l in _points)
                l.Render(ctx);

            //if (t)
            //    GL.PopMatrix();
        }
 public void Attach(TKContext ctx)
 {
 }
        public void Render(TKContext ctx)
        {
            if (_highlight)
                GL.Color4(1.0f, 1.0f, 0.0f, 1.0f);
            else
                GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);

            Vector2 v = Value;

            ctx.DrawBox(
                new Vector3(v._x - BoxRadius, v._y - BoxRadius, LineWidth),
                new Vector3(v._x + BoxRadius, v._y + BoxRadius, -LineWidth));
        }
        protected internal unsafe override void OnRender(TKContext ctx, PaintEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.ClearColor(Color.White);

            if (_keyRoot == null)
                return;

            CalcXY();

            if (_allKeys)
            {
                //Draw lines
                //GL.Color4(Color.Black);
                //GL.Begin(BeginMode.Lines);
                //for (KeyframeEntry entry = _keyRoot._next; (entry != _keyRoot); entry = entry._next)
                //{
                //    float xv = entry._index * xinc;
                //    GL.Vertex2(xv, 0.0f);
                //    GL.Vertex2(xv, Height);

                //    float yv = (GetFrameValue(entry._index) - _minVal) * yinc;
                //    GL.Vertex2(0.0f, yv);
                //    GL.Vertex2(Width, yv);
                //}
                //GL.End();

                //Draw tangents
                if (_drawTans)
                    for (KeyframeEntry entry = _keyRoot._next; (entry != _keyRoot); entry = entry._next)
                        DrawTangent(entry, 0);
                else if (_selKey != null && !Linear)
                    DrawTangent(_selKey, 0);

                //Draw interpolation
                GL.Color4(Color.Red);
                GL.Begin(BeginMode.LineStrip);
                if (!_linear)
                    for (float i = 0; i < (float)_frameLimit; i += (1 / _precision))
                        GL.Vertex2(i * _xScale, (GetFrameValue(i) - _minVal) * _yScale);
                else
                    for (KeyframeEntry entry = _keyRoot._next; (entry != _keyRoot); entry = entry._next)
                        GL.Vertex2(entry._index * _xScale, (GetFrameValue(entry._index) - _minVal) * _yScale);
                GL.End();

                //Draw frame indicator
                GL.Color4(Color.Blue);
                if (_frame >= 0 && _frame < _frameLimit)
                {
                    GL.Begin(BeginMode.Lines);

                    float r = _frame * _xScale;
                    GL.Vertex2(r, 0.0f);
                    GL.Vertex2(r, Height);

                    GL.End();
                }

                //Draw points
                GL.Color4(Color.Black);
                GL.Begin(BeginMode.Points);
                for (KeyframeEntry entry = _keyRoot._next; (entry != _keyRoot); entry = entry._next)
                {
                    bool t = false;
                    if (t = (_hiKey == entry || _selKey == entry))
                    {
                        GL.PointSize(_pointWidth * 4.0f);
                        GL.Color4(Color.Orange);
                    }
                    GL.Vertex2(entry._index * _xScale, (GetFrameValue(entry._index) - _minVal) * _yScale);

                    if (t)
                    {
                        GL.PointSize(_pointWidth);
                        GL.Color4(Color.Black);
                    }
                }
                GL.End();
            }
            else if (SelectedKeyframe != null)
            {
                //Draw lines
                GL.Color4(Color.Black);
                GL.Begin(BeginMode.Lines);

                int min = GetKeyframeMinIndex();
                int max = GetKeyframeMaxIndex();

                float xv = (SelectedKeyframe._index - min) * _xScale;
                GL.Vertex2(xv, 0.0f);
                GL.Vertex2(xv, Height);

                float yv = (GetFrameValue(SelectedKeyframe._index) - _minVal) * _yScale;
                GL.Vertex2(0.0f, yv);
                GL.Vertex2(Width, yv);

                GL.End();

                //Draw interpolation
                GL.Color4(Color.Red);
                GL.Begin(BeginMode.LineStrip);
                for (float i = 0; i <= (float)(max - min); i += (1 / _precision))
                    GL.Vertex2(i * _xScale, (GetFrameValue(i + min) - _minVal) * _yScale);
                GL.End();

                //Draw tangent
                DrawTangent(SelectedKeyframe, min);
                if (_drawTans)
                {
                    if (SelectedKeyframe._prev._index != -1)
                        DrawTangent(SelectedKeyframe._prev, min);
                    if (SelectedKeyframe._next._index != -1)
                        DrawTangent(SelectedKeyframe._next, min);
                }

                //Draw points
                GL.Color4(Color.Black);
                GL.Begin(BeginMode.Points);

                if (SelectedKeyframe._prev._index != -1)
                    GL.Vertex2((SelectedKeyframe._prev._index - min) * _xScale, (GetFrameValue(SelectedKeyframe._prev._index) - _minVal) * _yScale);
                GL.Vertex2((SelectedKeyframe._index - min) * _xScale, (GetFrameValue(SelectedKeyframe._index) - _minVal) * _yScale);
                if (SelectedKeyframe._next._index != -1)
                    GL.Vertex2((SelectedKeyframe._next._index - min) * _xScale, (GetFrameValue(SelectedKeyframe._next._index) - _minVal) * _yScale);

                GL.End();
            }
        }
예제 #45
0
        protected internal override void OnRender(TKContext ctx, PaintEventArgs e)
        {
            if (_showCamCoords)
            {
                Vector3 v = _camera.GetPoint().Round(3);
                Vector3 r = _camera._rotation.Round(3);
                ScreenText[String.Format("Position\nX: {0}\nY: {1}\nZ: {2}\n\nRotation\nX: {3}\nY: {4}\nZ: {5}", v._x, v._y, v._z, r._x, r._y, r._z)] = new Vector3(5.0f, 5.0f, 0.5f);
            }

            if (_ctx._needsUpdate)
            {
                OnInit(ctx);
                OnResized();
                _ctx._needsUpdate = false;
            }

            if (_bgImage == null)
                GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);

            RecalcLight();

            if (PreRender != null)
                PreRender(this, ctx);

            foreach (IRenderedObject o in _settings._renderList)
                o.Render(ctx, this);

            if (PostRender != null)
                PostRender(this, ctx);
        }
        public string GeneratePixelShaderCode(MDL0ObjectNode Object, PSGRENDER_MODE PSGRenderMode, TKContext ctx)
        {
            tempShader = "";

            int numStages = ShaderNode.Children.Count;
            int numTexgen = Children.Count;

            w("//Pixel Shader for TEV stages\n");
            w("//{0} TEV stages, {1} texgens, {2} IND stages\n", numStages, numTexgen, IndirectShaderStages);

            int nIndirectStagesUsed = 0;
            if (IndirectShaderStages > 0)
                for (int i = 0; i < numStages; ++i)
                {
                    TEVStage stage = ShaderNode.Children[i] as TEVStage;
                    if (stage.IndirectActive && stage.bt < IndirectShaderStages)
                        nIndirectStagesUsed |= 1 << stage.bt;
                }

            DepthTextureEnable = (/*bpmem.ztex2.op != ZTEXTURE_DISABLE && */!ZCompareLoc && EnableDepthTest && EnableDepthUpdate)/* || g_ActiveConfig.bEnablePerPixelDepth*/;

            //A few required defines and ones that will make our lives a lot easier
            if (ctx.bSupportsGLSLBinding || ctx.bSupportsGLSLUBO)
            {
                w("#version 330 compatibility\n");
                if (ctx.bSupportsGLSLBinding)
                    w("#extension GL_ARB_shading_language_420pack : enable\n");
                //if (ctx.bSupportsGLSLUBO)
                //    w("#extension GL_ARB_uniform_buffer_object : enable\n");
            }
            else
                w("#version 120\n");

            if (ctx.bSupportsGLSLATTRBind)
                w("#extension GL_ARB_explicit_attrib_location : enable\n");

            w("#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
            w("#define lerp(x, y, z) mix(x, y, z)\n");

            w("float fmod(float x, float y)\n");
            w("{\n");
            w("float z = fract(abs(x / y)) * abs(y);\n");
            w("return (x < 0) ? -z : z;\n");
            w("}\n");

            for (uint i = 0; i < 8; i++)
                w("{0}uniform sampler2D samp{1};\n", WriteBinding(i, ctx), i);

            w("\n");

            w("uniform vec4 " + I_COLORS + "[4];\n");
            w("uniform vec4 " + I_KCOLORS + "[4];\n");
            w("uniform vec4 " + I_ALPHA + ";\n");
            w("uniform vec4 " + I_TEXDIMS + "[8];\n");
            w("uniform vec4 " + I_ZBIAS + "[2];\n");
            w("uniform vec4 " + I_INDTEXSCALE + "[2];\n");
            w("uniform vec4 " + I_INDTEXMTX + "[6];\n");
            w("uniform vec4 " + I_FOG + "[3];\n");

            // Compiler will optimize these out by itself.
            w("uniform vec4 " + I_PLIGHTS + "[40];\n");
            w("uniform vec4 " + I_PMATERIALS + "[4];\n");

            w("vec4 ocol0;\n");

            if (DepthTextureEnable)
                w("float depth;\n");

            w("vec4 rawpos = gl_FragCoord;\n");

            w("vec4 colors_0 = gl_Color;\n");
            w("vec4 colors_1 = gl_SecondaryColor;\n");

            if (numTexgen < 7)
            {
                for (int i = 0; i < numTexgen; i++)
                    w("vec3 uv{0} = gl_TexCoord[{0}].xyz;\n", i);
                w("vec4 clipPos = gl_TexCoord[{0}];\n", numTexgen);
                w("vec4 Normal = gl_TexCoord[{0}];\n", numTexgen + 1);
            }
            else
                for (int i = 0; i < 8; ++i)
                    w("vec4 uv{0} = gl_TexCoord[{0}];\n", i);

            w("void main()\n{\n");

            AlphaPretest Pretest = PretestAlpha();
            //if (PSGRenderMode == PSGRENDER_MODE.PSGRENDER_DSTALPHA_ALPHA_PASS && !DepthTextureEnable && Pretest >= 0)
            //{
            //    if (Pretest == AlphaPretest.AlwaysFail)
            //    {
            //        w("ocol0 = vec4(0);\n");
            //        w("discard;\n");

            //        if(PSGRenderMode != PSGRENDER_MODE.PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND)
            //            w("gl_FragColor = ocol0;\n");

            //        w("return;\n");
            //    }
            //    else
            //        w("ocol0 = " + I_ALPHA + ".aaaa;\n");

            //    w("}\n");

            //    return tempShader;
            //}

            w("vec4 c0 = " + I_COLORS + "[1], c1 = " + I_COLORS + "[2], c2 = " + I_COLORS + "[3], prev = vec4(0.0f, 0.0f, 0.0f, 0.0f), textemp = vec4(0.0f, 0.0f, 0.0f, 0.0f), rastemp = vec4(0.0f, 0.0f, 0.0f, 0.0f), konsttemp = vec4(0.0f, 0.0f, 0.0f, 0.0f);\n");
            w("vec3 comp16 = vec3(1.0f, 255.0f, 0.0f), comp24 = vec3(1.0f, 255.0f, 255.0f*255.0f);\n");
            w("vec4 alphabump = vec4(0.0f,0.0f,0.0f,0.0f);\n");
            w("vec3 tevcoord = vec3(0.0f, 0.0f, 0.0f);\n");
            w("vec2 wrappedcoord=vec2(0.0f,0.0f), tempcoord=vec2(0.0f,0.0f);\n");
            w("vec4 cc0 = vec4(0.0f,0.0f,0.0f,0.0f), cc1 = vec4(0.0f,0.0f,0.0f,0.0f);\n");
            w("vec4 cc2 = vec4(0.0f,0.0f,0.0f,0.0f), cprev = vec4(0.0f,0.0f,0.0f,0.0f);\n");
            w("vec4 crastemp=vec4(0.0f,0.0f,0.0f,0.0f), ckonsttemp = vec4(0.0f,0.0f,0.0f,0.0f);\n\n");

            if (Children.Count < 7)
            {
                w("vec3 _norm0 = normalize(Normal.xyz);\n\n");
                w("vec3 pos = vec3(clipPos.x,clipPos.y,Normal.w);\n");
            }
            else
            {
                w("vec3 _norm0 = normalize(vec3(uv4.w,uv5.w,uv6.w));\n\n");
                w("vec3 pos = vec3(uv0.w,uv1.w,uv7.w);\n");
            }

            w("vec4 mat, lacc;\nvec3 ldir, h;\nfloat dist, dist2, attn;\n");

            Object.tabs = tabs;
            tempShader += Object.GenerateLightingShader(I_PMATERIALS, I_PLIGHTS, "colors_", "colors_");

            //if (numTexgen < 7)
            //    w("clipPos = vec4(rawpos.x, rawpos.y, clipPos.z, clipPos.w);\n");
            //else
            //    w("vec4 clipPos = vec4(rawpos.x, rawpos.y, uv2.w, uv3.w);\n");

            // HACK to handle cases where the tex gen is not enabled
            if (numTexgen == 0)
                w("vec3 uv0 = vec3(0.0f, 0.0f, 0.0f);\n");
            else
            {
                for (int i = 0; i < numTexgen; ++i)
                {
                    // optional perspective divides
                    if (((MDL0MaterialRefNode)Children[i]).Projection == TexProjection.STQ)
                    {
                        w("if (uv{0}.z != 0.0f)\n", i);
                        w("    uv{0}.xy = uv{0}.xy / uv{0}.z;\n", i);
                    }

                    //w("uv{0}.xy = uv{0}.xy * "+I_TEXDIMS+"[{0}].zw;\n", i);
                }
            }

            for (int i = 0; i < IndirectShaderStages; i++)
            {
                if ((nIndirectStagesUsed & (1 << i)) != 0)
                {
                    uint texcoord = (ShaderNode._swapBlock._Value16.Value >> ((i + 1) * 3) & 7);

                    if (texcoord < numTexgen)
                        w("tempcoord = uv{0}.xy * " + I_INDTEXSCALE + "[{1}].{2};\n", texcoord, i / 2, (i & 1) != 0 ? "zw" : "xy");
                    else
                        w("tempcoord = vec2(0.0f, 0.0f);\n");

                    SampleTexture(String.Format("vec3 indtex{0}", i), "tempcoord", "abg", (ShaderNode._swapBlock._Value16.Value >> (i * 3) & 7));
                }
            }

            foreach (TEVStage stage in ShaderNode.Children)
                if (stage.Index < ActiveShaderStages)
                    w(stage.Write(this, Object));
                else break;

            if (numStages > 0)
            {
                w("prev.rgb = {0};\n", tevCOutputTable[(int)((TEVStage)ShaderNode.Children[numStages - 1]).ColorRegister]);
                w("prev.a = {0};\n", tevAOutputTable[(int)((TEVStage)ShaderNode.Children[numStages - 1]).AlphaRegister]);
            }

            // emulation of unsigned 8 overflow when casting
            //w("prev = fract(4.0f + prev * (255.0f/256.0f)) * (256.0f/255.0f);\n");

            if (Pretest == AlphaPretest.AlwaysFail)
            {
                w("ocol0 = vec4(0.0f);\n");

                //if (DepthTextureEnable)
                //    w("depth = 1.0f;\n");

                //if (PSGRenderMode == PSGRENDER_MODE.PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND)
                //    w("ocol1 = vec4(0.0f);\n");
                //else
                w("gl_FragColor = ocol0;\n");

                if (DepthTextureEnable)
                    w("gl_FragDepth = depth;\n");

                w("discard;\n");

                w("return;\n");
            }
            else
            {
                if (Pretest != AlphaPretest.AlwaysPass)
                    WriteAlphaTest(PSGRenderMode);

                //if (_fog != null && (_fog.Type != 0) || DepthTextureEnable)
                //{
                //    // the screen space depth value = far z + (clip z / clip w) * z range
                //    w("float zCoord = " + I_ZBIAS + "[1].x + (clipPos.z / clipPos.w) * " + I_ZBIAS + "[1].y;\n");
                //}

                //if (DepthTextureEnable)
                //{
                //    // use the texture input of the last texture stage (textemp), hopefully this has been read and is in correct format...
                //    if (/*bpmem.ztex2.op != ZTEXTURE_DISABLE && */!ZCompLoc && EnableDepthTest && EnableDepthUpdate)
                //    {
                //        //if (bpmem.ztex2.op == ZTEXTURE_ADD)
                //        //    Write("zCoord = dot("+I_ZBIAS+"[0].xyzw, textemp.xyzw) + "+I_ZBIAS+"[1].w + zCoord;\n");
                //        //else
                //            w("zCoord = dot(" + I_ZBIAS + "[0].xyzw, textemp.xyzw) + " + I_ZBIAS + "[1].w;\n");

                //        // scale to make result from frac correct
                //        w("zCoord = zCoord * (16777215.0f/16777216.0f);\n");
                //        w("zCoord = fract(zCoord);\n");
                //        w("zCoord = zCoord * (16777216.0f/16777215.0f);\n");
                //    }
                //    w("depth = zCoord;\n");
                //}

                //if (PSGRenderMode == PSGRENDER_MODE.PSGRENDER_DSTALPHA_ALPHA_PASS)
                //    w("ocol0 = vec4(prev.rgb, " + I_ALPHA + ".a);\n");
                //else
                {
                    WriteFog();
                    w("ocol0 = prev;\n");
                }

                //if (PSGRenderMode == PSGRENDER_MODE.PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND)
                //{
                //    w("ocol1 = ocol0;\n");
                //    w("ocol0.a = " + I_ALPHA + ".a;\n");
                //}

                //if (DepthTextureEnable)
                //    w("gl_FragDepth = depth;\n");
                //if (PSGRenderMode != PSGRENDER_MODE.PSGRENDER_DSTALPHA_DUAL_SOURCE_BLEND)
                w("gl_FragColor = ocol0;\n");

            }
            w("}\n");

            return tempShader;
        }
예제 #47
0
        public unsafe void RenderScaleControl(TKContext context)
        {
            GLDisplayList axis = GetScaleControl();

            //Enter local space
            Matrix m = Matrix.TransformMatrix(new Vector3(OrbRadius), new Vector3(), BoneLoc);
            GL.PushMatrix();
            GL.MultMatrix((float*)&m);

            axis.Call();

            GL.PopMatrix();

            ModelPanel.ScreenText["X"] = ModelPanel.Project(new Vector3(_axisLDist + 0.1f, 0, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            ModelPanel.ScreenText["Y"] = ModelPanel.Project(new Vector3(0, _axisLDist + 0.1f, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            ModelPanel.ScreenText["Z"] = ModelPanel.Project(new Vector3(0, 0, _axisLDist + 0.1f) * m) - new Vector3(8.0f, 8.0f, 0);
        }
        public void Render(TKContext ctx, ModelPanel mainWindow)
        {
            foreach (MDL0ObjectNode p in _objects)
                p.Render(ctx, false, mainWindow);

            #region Old

            //if (Model._mainWindow != null && Model._mainWindow._scn0 != null && (LightSet >= 0 || FogSet >= 0))
            //{
            //    ModelEditControl m = Model._mainWindow;
            //    SCN0Node scn = m._scn0;
            //    int animFrame = m._animFrame;
            //    SCN0GroupNode fog;
            //    if (FogSet >= 0 && (fog = scn.GetFolder<SCN0FogNode>()) != null && fog.Children.Count > FogSet)
            //    {
            //        SCN0FogNode f = fog.Children[FogSet] as SCN0FogNode;
            //        GL.Enable(EnableCap.Fog);
            //        uint mode = 0;
            //        switch (f.Type)
            //        {
            //            case FogType.OrthographicExp:
            //            case FogType.PerspectiveExp:
            //                mode = (uint)OpenTK.Graphics.OpenGL.FogMode.Exp;
            //                break;
            //            case FogType.OrthographicExp2:
            //            case FogType.PerspectiveExp2:
            //                mode = (uint)OpenTK.Graphics.OpenGL.FogMode.Exp2;
            //                break;
            //            case FogType.OrthographicLinear:
            //            case FogType.PerspectiveLinear:
            //                mode = (uint)OpenTK.Graphics.OpenGL.FogMode.Linear;
            //                break;
            //            case FogType.OrthographicRevExp:
            //            case FogType.PerspectiveRevExp:
            //                mode = (uint)OpenTK.Graphics.OpenGL.FogMode.Linear;
            //                break;
            //            case FogType.OrthographicRevExp2:
            //            case FogType.PerspectiveRevExp2:
            //                mode = (uint)OpenTK.Graphics.OpenGL.FogMode.Linear;
            //                break;
            //        }
            //        GL.Fog(OpenTK.Graphics.OpenGL.FogParameter.FogMode, mode);
            //        float* l = stackalloc float[4];
            //        if (f.Colors.Count == 1)
            //        {
            //            l[0] = (float)f.Colors[0].R / 255f;
            //            l[1] = (float)f.Colors[0].G / 255f;
            //            l[2] = (float)f.Colors[0].B / 255f;
            //            l[3] = (float)f.Colors[0].A / 255f;
            //        }
            //        else if (animFrame - 1 < f.Colors.Count)
            //        {
            //            l[0] = (float)f.Colors[animFrame - 1].R / 255f;
            //            l[1] = (float)f.Colors[animFrame - 1].G / 255f;
            //            l[2] = (float)f.Colors[animFrame - 1].B / 255f;
            //            l[3] = (float)f.Colors[animFrame - 1].A / 255f;
            //        }
            //        GL.Fog(OpenTK.Graphics.OpenGL.FogParameter.FogColor, l);
            //        //ctx.glFog(FogParameter.FogDensity, 0.05f);
            //        GL.Hint(HintTarget.FogHint, HintMode.Nicest);
            //        GL.Fog(OpenTK.Graphics.OpenGL.FogParameter.FogStart, f._startKeys.GetFrameValue(animFrame - 1));
            //        GL.Fog(OpenTK.Graphics.OpenGL.FogParameter.FogEnd, f._endKeys.GetFrameValue(animFrame - 1));
            //    }
            //    else
            //        GL.Disable(EnableCap.Fog);
            //}
            //else
            //    GL.Disable(EnableCap.Fog);

            #endregion
        }
예제 #49
0
        public unsafe void RenderSCN0Controls(TKContext context)
        {
            if (_scn0 == null)
                return;

            GL.Color4(Color.Blue);
            GL.Disable(EnableCap.Lighting);

            if (scn0Editor._light != null)
            {
                SCN0LightNode l = scn0Editor._light;
                Vector3 start = new Vector3(
                l.GetFrameValue(LightKeyframeMode.StartX, CurrentFrame - 1),
                l.GetFrameValue(LightKeyframeMode.StartY, CurrentFrame - 1),
                l.GetFrameValue(LightKeyframeMode.StartZ, CurrentFrame - 1));
                Vector3 end = new Vector3(
                l.GetFrameValue(LightKeyframeMode.EndX, CurrentFrame - 1),
                l.GetFrameValue(LightKeyframeMode.EndY, CurrentFrame - 1),
                l.GetFrameValue(LightKeyframeMode.EndZ, CurrentFrame - 1));

                //GL.Color4(Color.Coral);
                GL.Begin(BeginMode.Lines);

                GL.Vertex3(start._x, start._y, start._z);
                GL.Vertex3(end._x, end._y, end._z);

                GL.End();

                //GL.Color4(Color.MediumPurple);
                //GL.Begin(BeginMode.LineStrip);
                //for (int i = 0; i < MaxFrame; i++)
                //    GL.Vertex3(l.GetFrameValue(LightKeyframeMode.StartX, i), l.GetFrameValue(LightKeyframeMode.StartY, i), l.GetFrameValue(LightKeyframeMode.StartZ, i));
                //GL.End();

                //GL.Color4(Color.ForestGreen);
                //GL.Begin(BeginMode.LineStrip);
                //for (int i = 0; i < MaxFrame; i++)
                //    GL.Vertex3(l.GetFrameValue(LightKeyframeMode.EndX, i), l.GetFrameValue(LightKeyframeMode.EndY, i), l.GetFrameValue(LightKeyframeMode.EndZ, i));
                //GL.End();

                ModelPanel.ScreenText["Light Start"] = ModelPanel.Project(start);
                ModelPanel.ScreenText["Light End"] = ModelPanel.Project(end);

                //Render these if selected
                //if (_lightStartSelected || _lightEndSelected)
                //{
                //    Matrix m;
                //    float s1 = start.TrueDistance(CamLoc) / _orbRadius * 0.1f;
                //    float e1 = end.TrueDistance(CamLoc) / _orbRadius * 0.1f;
                //    GLDisplayList axis = GetAxes();
                //    if (_lightStartSelected)
                //    {
                //        m = Matrix.TransformMatrix(new Vector3(s1), new Vector3(), start);

                //        GL.PushMatrix();
                //        GL.MultMatrix((float*)&m);

                //        axis.Call();
                //        GL.PopMatrix();
                //    }
                //    if (_lightEndSelected)
                //    {
                //        m = Matrix.TransformMatrix(new Vector3(e1), new Vector3(), end);

                //        GL.PushMatrix();
                //        GL.MultMatrix((float*)&m);

                //        axis.Call();
                //        GL.PopMatrix();
                //    }
                //}
            }

            if (scn0Editor._camera != null)
            {
                SCN0CameraNode c = scn0Editor._camera;
                Vector3 start = new Vector3(
                c.GetFrameValue(CameraKeyframeMode.PosX, CurrentFrame - 1),
                c.GetFrameValue(CameraKeyframeMode.PosY, CurrentFrame - 1),
                c.GetFrameValue(CameraKeyframeMode.PosZ, CurrentFrame - 1));
                Vector3 end = new Vector3(
                c.GetFrameValue(CameraKeyframeMode.AimX, CurrentFrame - 1),
                c.GetFrameValue(CameraKeyframeMode.AimY, CurrentFrame - 1),
                c.GetFrameValue(CameraKeyframeMode.AimZ, CurrentFrame - 1));

                //GL.Color4(Color.Blue);
                GL.Begin(BeginMode.Lines);

                GL.Vertex3(start._x, start._y, start._z);
                GL.Vertex3(end._x, end._y, end._z);

                GL.End();

                //GL.Color4(Color.OrangeRed);
                //GL.Begin(BeginMode.LineStrip);
                //for (int i = 0; i < MaxFrame; i++)
                //    GL.Vertex3(c.GetFrameValue(CameraKeyframeMode.PosX, i), c.GetFrameValue(CameraKeyframeMode.PosY, i), c.GetFrameValue(CameraKeyframeMode.PosZ, i));
                //GL.End();

                //GL.Color4(Color.SkyBlue);
                //GL.Begin(BeginMode.LineStrip);
                //for (int i = 0; i < MaxFrame; i++)
                //    GL.Vertex3(c.GetFrameValue(CameraKeyframeMode.AimX, i), c.GetFrameValue(CameraKeyframeMode.AimY, i), c.GetFrameValue(CameraKeyframeMode.AimZ, i));
                //GL.End();

                ModelPanel.ScreenText["Camera Position"] = ModelPanel.Project(start);
                ModelPanel.ScreenText["Camera Aim"] = ModelPanel.Project(end);

                GL.Color4(Color.Black);

                //Render these if selected
                //if (_lightStartSelected || _lightEndSelected)
                //{
                //    Matrix m;
                //    float s = start.TrueDistance(CamLoc) / _orbRadius * 0.1f;
                //    float e = end.TrueDistance(CamLoc) / _orbRadius * 0.1f;
                //    GLDisplayList axis = GetAxes();
                //    if (_lightStartSelected)
                //    {
                //        m = Matrix.TransformMatrix(new Vector3(s), new Vector3(), start);

                //        GL.PushMatrix();
                //        GL.MultMatrix((float*)&m);

                //        axis.Call();
                //        GL.PopMatrix();
                //    }
                //    if (_lightEndSelected)
                //    {
                //        m = Matrix.TransformMatrix(new Vector3(e), new Vector3(), end);

                //        GL.PushMatrix();
                //        GL.MultMatrix((float*)&m);

                //        axis.Call();
                //        GL.PopMatrix();
                //    }
                //}
            }
        }
예제 #50
0
        public unsafe void RenderTransformControl(TKContext context)
        {
            if (_playing)
                return;

            if (SelectedBone != null) //Render drag and drop control
            {
                if (_editType == TransformType.Rotation)
                    RenderRotationControl(context, BoneLoc, OrbRadius, SelectedBone._frameMatrix.GetAngles());
                else if (_editType == TransformType.Translation)
                    RenderTranslationControl(context, BoneLoc, OrbRadius);
                else if (_editType == TransformType.Scale)
                    RenderScaleControl(context);
            }

            if (VertexLoc != null && RenderVertices)
            {
                //if (_editType == TransformType.Rotation)
                //    RenderRotationControl(context, ((Vector3)VertexLoc), VertexOrbRadius, _oldAngles);
                //else
                    RenderTranslationControl(context, ((Vector3)VertexLoc), VertexOrbRadius);
            }
        }
예제 #51
0
 public void Bind(int index, int program, TKContext ctx)
 {
     if (program != -1 && ctx != null && ctx._shadersEnabled)
     {
         index = index.Clamp(0, 7);
         GL.ActiveTexture(TextureUnit.Texture0 + index);
         GL.BindTexture(TextureTarget.Texture2D, Initialize());
         GL.Uniform1(GL.GetUniformLocation(program, "Texture" + index), index);
     }
     else
         GL.BindTexture(TextureTarget.Texture2D, Initialize());
 }
예제 #52
0
        internal unsafe override void OnInit(TKContext ctx)
        {
            Vector3 v = (Vector3)BackColor;
            GL.ClearColor(v._x, v._y, v._z, 0.0f);
            GL.ClearDepth(1.0f);

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);

            GL.ShadeModel(ShadingModel.Smooth);

            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Hint(HintTarget.LineSmoothHint, HintMode.Fastest);
            GL.Hint(HintTarget.PointSmoothHint, HintMode.Fastest);
            GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Fastest);
            GL.Hint(HintTarget.GenerateMipmapHint, HintMode.Fastest);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            GL.Enable(EnableCap.AlphaTest);
            GL.AlphaFunc(AlphaFunction.Gequal, 0.1f);

            //GL.PointSize(3.0f);
            //GL.LineWidth(2.0f);

            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);
            //GL.Enable(EnableCap.Normalize);

            RecalcLight();

            //Set client states
            ctx._states["_Node_Refs"] = _settings._resourceList;
        }
예제 #53
0
        public void Render(TKContext ctx, ModelPanel mainWindow)
        {
            if (!_visible)
                return;

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            _mainWindow = mainWindow;

            if (_matrixOffset != Matrix.Identity && _matrixOffset != new Matrix())
            {
                GL.PushMatrix();
                Matrix m = _matrixOffset;
                GL.MultMatrix((float*)&m);
            }

            if (_renderPolygons || _renderWireframe)
            {
                GL.Enable(EnableCap.Lighting);
                GL.Enable(EnableCap.DepthTest);

                float maxDrawPriority = 0.0f;
                if (_objList != null)
                    foreach (MDL0ObjectNode p in _objList)
                        maxDrawPriority = Math.Max(maxDrawPriority, p.DrawPriority);

                //Draw objects in the prioritized order of materials.
                List<MDL0ObjectNode> rendered = new List<MDL0ObjectNode>();
                if (_matList != null)
                    foreach (MDL0MaterialNode m in _matList)
                        foreach (MDL0ObjectNode p in m._objects)
                        {
                            RenderObject(p, ctx, mainWindow, maxDrawPriority);
                            rendered.Add(p);
                        }

                //Render any remaining objects
                if (_objList != null)
                    foreach (MDL0ObjectNode p in _objList)
                        if (!rendered.Contains(p))
                            RenderObject(p, ctx, mainWindow, maxDrawPriority);
            }

            if (_renderBox)
            {
                //GL.LineWidth(1.0f);
                GL.Disable(EnableCap.Lighting);
                //GL.Disable(EnableCap.DepthTest);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GL.Color4(Color.Gray);

                DrawBox();

                if (_objList != null)
                    if (_polyIndex != -1 && ((MDL0ObjectNode)_objList[_polyIndex])._render)
                        ((MDL0ObjectNode)_objList[_polyIndex]).DrawBox();
                //else
                //    foreach (MDL0ObjectNode p in _polyList)
                //        if (p._render)
                //            p.DrawBox();
            }

            //Turn off the last bound shader program.
            if (ctx._shadersEnabled) { GL.UseProgram(0); GL.ClientActiveTexture(TextureUnit.Texture0); }

            if (_renderBones)
            {
                GL.Enable(EnableCap.Blend);
                GL.Disable(EnableCap.Lighting);
                GL.Disable(EnableCap.DepthTest);
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                //GL.LineWidth(2.0f);

                if (_boneList != null)
                    foreach (MDL0BoneNode bone in _boneList)
                        bone.Render(ctx, mainWindow);
            }

            //if (_billboardBones.Count > 0)
            //{
            //    //Transform bones
            //    if (_boneList != null)
            //        foreach (MDL0BoneNode b in _boneList)
            //            b.RecalcFrameState();
            //    //Transform nodes
            //    foreach (Influence inf in _influences._influences)
            //        inf.CalcMatrix();
            //    //Weight Vertices
            //    if (_objList != null)
            //        foreach (MDL0ObjectNode poly in _objList)
            //            poly.WeightVertices();
            //    //Morph vertices to currently selected SHP
            //    ApplySHP(_currentSHP, _currentSHPIndex);
            //}

            if (_matrixOffset != Matrix.Identity && _matrixOffset != new Matrix())
                GL.PopMatrix();
        }
        protected internal unsafe override void OnRender(TKContext ctx, PaintEventArgs e)
        {
            GLTexture _bgTex = ctx.FindOrCreate<GLTexture>("TexBG", CreateBG);
            _bgTex.Bind();

            //Draw BG
            float s = (float)Width / (float)_bgTex.Width, t = (float)Height / (float)_bgTex.Height;

            GL.Begin(BeginMode.Quads);

            GL.TexCoord2(0.0f, 0.0f);
            GL.Vertex2(0.0f, 0.0f);
            GL.TexCoord2(s, 0.0f);
            GL.Vertex2(1.0, 0.0f);
            GL.TexCoord2(s, t);
            GL.Vertex2(1.0, 1.0);
            GL.TexCoord2(0, t);
            GL.Vertex2(0.0f, 1.0);

            GL.End();

            //Draw texture
            if ((_currentTexture != null) && (_currentTexture._texId != 0))
            {
                float tAspect = (float)_currentTexture.Width / _currentTexture.Height;
                float wAspect = (float)Width / Height;
                float* points = stackalloc float[8];

                if (tAspect > wAspect) //Texture is wider, use horizontal fit
                {
                    points[0] = points[6] = 0.0f;
                    points[2] = points[4] = 1.0f;

                    points[1] = points[3] = ((Height - ((float)Width / _currentTexture.Width * _currentTexture.Height))) / Height / 2.0f;
                    points[5] = points[7] = 1.0f - points[1];
                }
                else
                {
                    points[1] = points[3] = 0.0f;
                    points[5] = points[7] = 1.0f;

                    points[0] = points[6] = (Width - ((float)Height / _currentTexture.Height * _currentTexture.Width)) / Width / 2.0f;
                    points[2] = points[4] = 1.0f - points[0];
                }

                GL.BindTexture(TextureTarget.Texture2D, _currentTexture._texId);

                GL.Begin(BeginMode.Quads);

                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex2(&points[0]);
                GL.TexCoord2(1.0f, 0.0f);
                GL.Vertex2(&points[2]);
                GL.TexCoord2(1.0f, 1.0f);
                GL.Vertex2(&points[4]);
                GL.TexCoord2(0.0f, 1.0f);
                GL.Vertex2(&points[6]);

                GL.End();
            }
        }
예제 #55
0
        public unsafe void RenderTranslationControl(TKContext context, Vector3 position, float radius)
        {
            GLDisplayList axis = GetAxes();

            //Enter local space
            Matrix m = Matrix.TransformMatrix(new Vector3(radius), new Vector3(), position);
            GL.PushMatrix();
            GL.MultMatrix((float*)&m);

            axis.Call();

            GL.PopMatrix();

            ModelPanel.ScreenText["X"] = ModelPanel.Project(new Vector3(_axisLDist + 0.1f, 0, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            ModelPanel.ScreenText["Y"] = ModelPanel.Project(new Vector3(0, _axisLDist + 0.1f, 0) * m) - new Vector3(8.0f, 8.0f, 0);
            ModelPanel.ScreenText["Z"] = ModelPanel.Project(new Vector3(0, 0, _axisLDist + 0.1f) * m) - new Vector3(8.0f, 8.0f, 0);
        }
예제 #56
0
 public void RenderNormals(TKContext ctx)
 {
     if (_renderNormals && _objList != null)
     {
         GL.Disable(EnableCap.Lighting);
         GL.Enable(EnableCap.DepthTest);
         if (_polyIndex != -1)
         {
             MDL0ObjectNode o = (MDL0ObjectNode)_objList[_polyIndex];
             if (o._render)
                 o._manager.RenderNormals(ctx, _mainWindow);
         }
         else
             foreach (MDL0ObjectNode p in _objList)
                 if (p._render)
                     p._manager.RenderNormals(ctx, _mainWindow);
     }
 }
예제 #57
0
        public void RenderObject(MDL0ObjectNode p, TKContext ctx, ModelPanel mainWindow, float maxDrawPriority)
        {
            if (p._render)
            {
                if (_dontRenderOffscreen)
                {
                    Vector3 min = new Vector3(float.MaxValue);
                    Vector3 max = new Vector3(float.MinValue);

                    if (p._manager != null)
                        foreach (Vertex3 vertex in p._manager._vertices)
                        {
                            Vector3 v = mainWindow.Project(vertex.WeightedPosition);

                            min.Min(v);
                            max.Max(v);
                        }

                    if (max._x < 0 || min._x > mainWindow.Size.Width ||
                        max._y < 0 || min._y > mainWindow.Size.Height)
                        return;
                }

                if (_renderPolygons)
                {
                    float polyOffset = 0.0f;
                    //polyOffset -= p.DrawPriority;
                    //polyOffset += maxDrawPriority;
                    if (_renderWireframe)
                        polyOffset += 1.0f;
                    if (polyOffset != 0)
                    {
                        GL.Enable(EnableCap.PolygonOffsetFill);
                        GL.PolygonOffset(1.0f, polyOffset);
                    }
                    else
                        GL.Disable(EnableCap.PolygonOffsetFill);
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                    p.Render(ctx, false, mainWindow);
                }
                if (_renderWireframe)
                {
                    GL.Disable(EnableCap.PolygonOffsetFill);
                    GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                    GL.LineWidth(0.5f);
                    p.Render(ctx, true, mainWindow);
                }
            }
        }
예제 #58
0
 public void RenderVertices(TKContext ctx, bool pass2)
 {
     if (_renderVertices && _objList != null)
     {
         GL.Disable(EnableCap.Lighting);
         GL.Enable(EnableCap.DepthTest);
         if (_polyIndex != -1)
         {
             MDL0ObjectNode o = (MDL0ObjectNode)_objList[_polyIndex];
             if (o._render)
             {
                 o._manager.RenderVerts(ctx, o._matrixNode, _selectedBone, _mainWindow._camera.GetPoint(), pass2);
                 return;
             }
         }
         foreach (MDL0ObjectNode p in _objList)
             if (p._render)
                 p._manager.RenderVerts(ctx, p._matrixNode, _selectedBone, _mainWindow._camera.GetPoint(), pass2);
     }
 }
 public static string WriteBinding(uint num, TKContext ctx)
 {
     if (!ctx.bSupportsGLSLBinding)
         return "";
     return String.Format("layout(binding = {0}) ", num);
 }
예제 #60
0
        private unsafe void modelPanel1_PreRender(object sender, TKContext ctx)
        {
            if (RenderFloor)
            {
                GLTexture _bgTex = ctx.FindOrCreate<GLTexture>("TexBG", GLTexturePanel.CreateBG);

                float s = 10.0f, t = 10.0f;
                float e = 30.0f;

                GL.Disable(EnableCap.CullFace);
                GL.Disable(EnableCap.Blend);
                GL.Disable(EnableCap.Lighting);
                GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
                GL.PolygonMode(MaterialFace.Back, PolygonMode.Fill);

                GL.Enable(EnableCap.Texture2D);

                _bgTex.Bind();

                GL.Color4(StaticMainWindow._floorHue);

                GL.Begin(BeginMode.Quads);

                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex3(-e, 0.0f, -e);
                GL.TexCoord2(s, 0.0f);
                GL.Vertex3(e, 0.0f, -e);
                GL.TexCoord2(s, t);
                GL.Vertex3(e, 0.0f, e);
                GL.TexCoord2(0, t);
                GL.Vertex3(-e, 0.0f, e);

                GL.End();

                GL.Disable(EnableCap.Texture2D);
            }
        }