public int DrawSomething(ILua lua)
 {
     if (surface is null)
     {
         if (interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out _, out IntPtr isurfacePtr))
         {
             surface = new(isurfacePtr);
         }
         else
         {
             Console.WriteLine("failed to load");
         }
     }
     if (surface is not null)
     {
         Console.WriteLine("drawing");
         surface.DrawSetColor(0, 255, 0, 255);
         surface.DrawFilledRect(0, 0, 25, 10);
         surface.DrawSetColor(0, 0, 255, 255);
         surface.DrawFilledRect(20, 0, 25, 10);
         Console.WriteLine("drawn OMG");
     }
     return(0);
 }
Esempio n. 2
0
        public int Render(ILua lua)
        {
            //render.PushRenderTarget(textureRT)
            //cam.Start2D()
            // render.Clear(0, 0, 0, 0)

            lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
            lua.GetField(-1, "CurTime");
            lua.MCall(0, 1);
            int CurTime = (int)lua.GetNumber(-1);

            lua.Pop();

            // PushRenderTarget
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "render");
                lua.GetField(-1, "PushRenderTarget");
                lua.PushUserType(rt, (int)TYPES.TEXTURE);
                lua.MCall(1, 0);
                lua.Pop();
            }

            // Start 2D
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "cam");
                lua.GetField(-1, "Start2D");
                lua.MCall(0, 0);
                lua.Pop();
            }

            // Clear
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "render");
                lua.GetField(-1, "Clear");
                lua.PushNumber(0);
                lua.PushNumber(0);
                lua.PushNumber(0);
                lua.PushNumber(0);
                lua.MCall(4, 0);
                lua.Pop();
            }
            // Draw Rects
            {
                if (surface is not null)
                {
                    surface.DrawSetColor(255, 255, 255, 255);
                    surface.DrawFilledRect(20, (100 + (((int)Math.Sin(CurTime)) * 50)), 50, 50);
                    surface.DrawSetColor(255, 0, 0, 100);
                    surface.DrawFilledRect(120, (100 + (((int)Math.Sin(CurTime)) * 50)), 50, 50);
                }
                else
                {
                    lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                    lua.GetField(-1, "surface");
                    lua.GetField(-1, "SetDrawColor");
                    lua.PushNumber(255);
                    lua.PushNumber(255);
                    lua.PushNumber(255);
                    lua.PushNumber(255);
                    lua.MCall(4, 0);
                    lua.Pop(2);

                    lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                    lua.GetField(-1, "surface");
                    lua.GetField(-1, "DrawRect");
                    lua.PushNumber(20);
                    lua.PushNumber((100 + (((int)Math.Sin(CurTime)) * 50)));
                    lua.PushNumber(50);
                    lua.PushNumber(50);
                    lua.MCall(4, 0);
                    lua.Pop(2);

                    lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                    lua.GetField(-1, "surface");
                    lua.GetField(-1, "SetDrawColor");
                    lua.PushNumber(255);
                    lua.PushNumber(0);
                    lua.PushNumber(0);
                    lua.PushNumber(100);
                    lua.MCall(4, 0);
                    lua.Pop(2);

                    lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                    lua.GetField(-1, "surface");
                    lua.GetField(-1, "DrawRect");
                    lua.PushNumber(120);
                    lua.PushNumber((100 + (((int)Math.Sin(CurTime)) * 50)));
                    lua.PushNumber(50);
                    lua.PushNumber(50);
                    lua.MCall(4, 0);
                    lua.Pop(2);
                }
            }

            // End2D
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "cam");
                lua.GetField(-1, "End2D");
                lua.MCall(0, 0);
                lua.Pop();
            }

            // Pop
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "render");
                lua.GetField(-1, "PopRenderTarget");
                lua.MCall(0, 0);
                lua.Pop();
            }

            // Draw it on screen
            {
                if (surface is not null)
                {
                    surface.DrawSetColor(255, 255, 255, 255);
                }
                else
                {
                    lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                    lua.GetField(-1, "surface");
                    lua.GetField(-1, "SetDrawColor");
                    lua.PushNumber(255);
                    lua.PushNumber(255);
                    lua.PushNumber(255);
                    lua.PushNumber(255);
                    lua.MCall(4, 0);
                    lua.Pop();
                }

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "surface");
                lua.GetField(-1, "SetMaterial");
                lua.PushUserType(mat, (int)TYPES.MATERIAL);
                lua.MCall(1, 0);
                lua.Pop();

                if (surface is not null)
                {
                    surface.DrawTexturedRect(50, 50, 512, 512);
                }
                else
                {
                    lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                    lua.GetField(-1, "surface");
                    lua.GetField(-1, "DrawTexturedRect");
                    lua.PushNumber(50);
                    lua.PushNumber(50);
                    lua.PushNumber(512);
                    lua.PushNumber(512);
                    lua.MCall(4, 0);
                    lua.Pop();
                }
            }

            return(0);
        }