Beispiel #1
0
        public void Compile()
        {
            float[] data = LoadTexture(bitmap);
            GL.BindTexture(TextureTarget.Texture2D, _textureID);

            GL.TextureStorage2D(_textureID, _maxMipmapLevel, SizedInternalFormat.Rgba32f, bitmap.Width, bitmap.Height);
            GL.TextureSubImage2D(_textureID, 0, 0, 0, bitmap.Width, bitmap.Height, OpenTK.Graphics.OpenGL4.PixelFormat.Rgba, PixelType.Float, data);

            GL.GenerateTextureMipmap(_textureID);
            GL.TextureParameterI(_textureID, TextureParameterName.TextureBaseLevel, ref _minMipmapLevel);
            GL.TextureParameterI(_textureID, TextureParameterName.TextureMaxLevel, ref _maxMipmapLevel);
            var textureMinFilter = (int)TextureMinFilter.LinearMipmapLinear;

            GL.TextureParameterI(_textureID, TextureParameterName.TextureMinFilter, ref textureMinFilter);
            var textureMagFilter = (int)TextureMinFilter.Linear;

            GL.TextureParameterI(_textureID, TextureParameterName.TextureMagFilter, ref textureMagFilter);
            // data not needed from here on, OpenGL has the data

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            ELogger.Log(ELogger.LogType.Log, ELoggerTag.Texture, "Texture compile complete");
            ELogger.Log(ELogger.LogType.Log, ELoggerTag.Texture, "\tTexture width: " + bitmap.Width.ToString());
            ELogger.Log(ELogger.LogType.Log, ELoggerTag.Texture, "\tTexture height: " + bitmap.Height.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Begin loading the asset folder
        /// </summary>
        /// <returns></returns>
        public static EAssetDatabase Load()
        {
            ELogger.Log(ELogger.LogType.Log, ELoggerTag.Initialize, "Asset start loading...");

            // Check project folder structure exist
            foreach (var i in FolderStructure.All)
            {
                if (!Directory.Exists(i))
                {
                    _lastLoadResult = new LoadingResult()
                    {
                        flag = LoadingResultFlag.FolderNotExist, message = "Missing " + i + " folder in the project root"
                    };
                    ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, _lastLoadResult.message);
                    return(null);
                }
            }
            EAssetDatabase buffer = new EAssetDatabase();

            _lastLoadResult = new LoadingResult()
            {
                flag = LoadingResultFlag.Successfully, message = "Asset database loading successfully"
            };
            ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, _lastLoadResult.message);
            return(buffer);
        }
Beispiel #3
0
        public void SetShader(string vertex, string fragment)
        {
            vertexShader = GL.CreateShader(ShaderType.VertexShader);
            GL.ShaderSource(vertexShader, vertex);
            GL.CompileShader(vertexShader);
            string shaderLog = GL.GetShaderInfoLog(vertexShader);

            if (shaderLog != System.String.Empty)
            {
                ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Shader, shaderLog);
            }

            GL.AttachShader(_program, vertexShader);

            fragmentShader = GL.CreateShader(ShaderType.FragmentShader);
            GL.ShaderSource(fragmentShader, fragment);
            GL.CompileShader(vertexShader);
            shaderLog = GL.GetShaderInfoLog(fragmentShader);
            if (shaderLog != System.String.Empty)
            {
                ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Shader, shaderLog);
            }

            GL.AttachShader(_program, fragmentShader);

            GL.LinkProgram(_program);
        }
Beispiel #4
0
        public static void CreateDefaultSetting()
        {
            ELogger.Log(ELogger.LogType.Log, ELoggerTag.Initialize, "Craete default setting file");
            string jsonText = JsonConvert.SerializeObject(new EGameSetting(), Formatting.Indented);

            File.WriteAllText(SettingFileName, jsonText);
        }
Beispiel #5
0
        public static void CreateFolderStructure()
        {
            ELogger.Log(ELogger.LogType.Log, ELoggerTag.Initialize, "Craete default project folder structure");

            foreach (var i in FolderStructure.All)
            {
                Directory.CreateDirectory(i);
            }
        }
Beispiel #6
0
        public static void LogOutput()
        {
            string[] message = ELogger.GetLoggerMessage();
            string   _m      = "";

            for (int i = 0; i < message.Length; i++)
            {
                _m += message[i] + "\n";
            }

            File.WriteAllText(LogFileName, _m);
        }
Beispiel #7
0
 public void Load(string path)
 {
     if (File.Exists(path))
     {
         bitmap = (Bitmap)Image.FromFile(path);
         ELogger.Log(ELogger.LogType.Log, ELoggerTag.Texture, "Loading texture from path: " + path);
         Compile();
     }
     else
     {
         ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Texture, "Cannot find texture from path: " + path);
     }
 }
Beispiel #8
0
        public static EGameSetting Loading()
        {
            if (!File.Exists(SettingFileName))
            {
                _lastLoadResult = new LoadingResult()
                {
                    flag = LoadingResultFlag.FileNotExist, message = "file path: " + SettingFileName + " does not exist"
                };
                ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, _lastLoadResult.message);
                return(null);
            }

            string jsonText = File.ReadAllText(SettingFileName);

            try
            {
                EGameSetting buffer =
                    JsonConvert.DeserializeObject <EGameSetting>(jsonText, new JsonSerializerSettings
                {
                    MissingMemberHandling = MissingMemberHandling.Error
                });

                _lastLoadResult = new LoadingResult()
                {
                    flag = LoadingResultFlag.Successfully, message = "Setting file loading successfully"
                };
                ELogger.Log(ELogger.LogType.Log, ELoggerTag.Initialize, _lastLoadResult.message);
                return(buffer);
            }
            catch (JsonSerializationException ex)
            {
                _lastLoadResult = new LoadingResult()
                {
                    flag = LoadingResultFlag.Failed, message = ex.Message
                };
                ELogger.Log(ELogger.LogType.Log, ELoggerTag.Initialize, _lastLoadResult.message);
                return(null);
                // Could not find member 'DeletedDate' on object of type 'Account'. Path 'DeletedDate', line 4, position 23.
            }
        }
Beispiel #9
0
 public EActor(string name) : base(name)
 {
     ELogger.Log(ELogger.LogType.Log, ELoggerTag.Scene, "Adding actor to scene: " + name);
     components = new List <EActorComponent>();
     OnLoad();
 }
Beispiel #10
0
 public EMaterial(EShader useShader)
 {
     shader = useShader;
     ELogger.Log(ELogger.LogType.Log, ELoggerTag.Material, "Adding material: " + this.GetType().Name);
 }
Beispiel #11
0
 public ETexture(string name)
 {
     _textureName = name;
     ELogger.Log(ELogger.LogType.Log, ELoggerTag.Texture, "Create new texture: " + _textureID.ToString());
     GL.CreateTextures(TextureTarget.Texture2D, 1, out _textureID);
 }
Beispiel #12
0
 protected override void OnLoad(EventArgs e)
 {
     ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, "Application start...");
     ApplicationStart();
     base.OnLoad(e);
 }
Beispiel #13
0
        public EWindow(int width, int height) : base(width, height, new GraphicsMode(32, 0, 0, 4), "Ellyality Demo")
        {
            GLWidth  = width;
            GLHeight = height;

            // Initialize the engine
            EEngine.Initialize();
            VSync = VSyncMode.Off;

            // Loading the asset into database
            EEngine.instance.assetDatabase = EAssetDatabase.Load();

            // Check if the loading successfully
            if (EAssetDatabase.GetResult().flag == LoadingResultFlag.FolderNotExist)
            {
                ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, "Missing project folder");
                EAssetDatabase.CreateFolderStructure();
                EErrorReport.ExportReport(ELogger.GetLoggerMessage());
                Exit();
            }

            if (EAssetDatabase.GetResult().flag == LoadingResultFlag.Failed)
            {
                ELogger.Log(ELogger.LogType.Error, ELoggerTag.Initialize, "Loading asset failed");
                EErrorReport.ExportReport(ELogger.GetLoggerMessage());
                Exit();
            }

            // Loading the setting file into engine
            EEngine.instance.setting = EGameSetting.Loading();

            // Check if the loading successfully
            if (EGameSetting.GetResult().flag == LoadingResultFlag.FileNotExist)
            {
                ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, "Missing project files");
                EGameSetting.CreateDefaultSetting();
                EErrorReport.ExportReport(ELogger.GetLoggerMessage());
                Exit();
            }

            if (EGameSetting.GetResult().flag == LoadingResultFlag.Failed)
            {
                ELogger.Log(ELogger.LogType.Error, ELoggerTag.Initialize, "Loading setting failed");
                EGameSetting.CreateDefaultSetting();
                EErrorReport.ExportReport(ELogger.GetLoggerMessage());
                Exit();
            }

            // If there is no scene has select
            // Create an empty scene for engine drawing
            if (EEngine.instance.setting.FirstLoadingScene == null || EEngine.instance.setting.FirstLoadingScene == "")
            {
                EEngine.instance.loadScene.Add(EScene.GetDefaultScene());
                ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, "Default scene setting is null ! loading default scene instead...");
            }

            // Hide console window
            var handle = GetConsoleWindow();

            ShowWindow(handle, EEngine.instance.setting.DebugMode ? SW_SHOW : SW_HIDE);

            ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, "Application fixed update rate: " + EEngine.instance.setting.FixedUpdateTime.ToString());
            ELogger.Log(ELogger.LogType.Warning, ELoggerTag.Initialize, "Application frame fresh rate: " + (double)1 / (double)EEngine.instance.setting.FramePreSecond);
            Run(EEngine.instance.setting.FixedUpdateTime, (double)1 / (double)EEngine.instance.setting.FramePreSecond);
        }
Beispiel #14
0
 protected override void OnClosing(CancelEventArgs e)
 {
     ApplicationQuit(e);
     ELogger.LogOutput();
     base.OnClosing(e);
 }
Beispiel #15
0
 public EShader()
 {
     _program = GL.CreateProgram();
     ELogger.Log(ELogger.LogType.Log, ELoggerTag.Shader, "Create new shader: " + _program.ToString());
 }