Esempio n. 1
0
 public static void DeleteTexture(TextureNode Node)
 {
     if (Node != null)
     {
         DeleteTexture(Node.FilePath);
     }
 }
Esempio n. 2
0
        public static void Init()
        {
            _ScreenWidth  = ConsoleVarManager.GetValueToUShort("ScreenWidth");
            _ScreenHeight = ConsoleVarManager.GetValueToUShort("ScreenHeight");

            _CharsPerLine   = (ushort)(_ScreenWidth >> 3);              // division by 8
            _LinesPerScreen = (ushort)((_ScreenHeight >> 3) - 1);       // division by 8; last line is console input line

            _ConsoleBackground = TextureManager.LoadTexture(ConsoleVarManager.GetValueToString("ConsoleBackground"), GL.GL_TEXTURE_2D, TextureManager.TM_PP_NONE);
            GL.TexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, (int)GL.GL_DECAL);

            _ConsoleChars = TextureManager.LoadTexture(ConsoleVarManager.GetValueToString("ConsoleCharacters"), GL.GL_TEXTURE_2D, TextureManager.TM_PP_NONE);
            GL.TexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, (int)GL.GL_DECAL);
        }
Esempio n. 3
0
        public static void DeleteTexture(string FilePath)
        {
            string FilePathShort = FilePathStandardization(FilePath);

            // Is it already loaded?
            TextureNode Node = FindTexture(FilePathShort);

            if (Node != null)
            {
                uint[] GLTextureNumber = new uint[1];
                GLTextureNumber[0] = Node.GLTextureNumber;

                GL.DeleteTextures(1, GLTextureNumber);

                Textures.Remove(FilePathShort);
            }
        }
Esempio n. 4
0
        public static void SetupGL()
        {
            WGL.SwapIntervalEXT(1);                                         // 60 fps is enough for us :)

            if (ConsoleManager.IsOpen)
            {
                GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
                GL.Color3f(1.0f, 1.0f, 1.0f);

                GL.Enable(GL.GL_DEPTH_TEST);
                GL.DepthFunc(GL.GL_LEQUAL);
                GL.ShadeModel(GL.GL_SMOOTH);

                GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
                GL.Enable(GL.GL_TEXTURE_2D);

                GL.Hint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
                GL.Disable(GL.GL_DITHER);                                       // Actually we shouldn't have DITHERING in RGBA mode, but anyway...
                GL.Enable(GL.GL_BLEND);
                GL.BlendFunc(GL.GL_ONE, GL.GL_ONE);
            }
            else
            {
                if (ConsoleVarManager.GetValueToByte("DemoFreeglut") == 1)
                {
                    GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
                    GL.Color3f(1.0f, 1.0f, 1.0f);

                    GL.Disable(GL.GL_DEPTH_TEST);
                    GL.ShadeModel(GL.GL_FLAT);

                    GL.Disable(GL.GL_TEXTURE_2D);

                    GL.Hint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
                    GL.Disable(GL.GL_DITHER);
                    GL.Disable(GL.GL_BLEND);
                }

                if (ConsoleVarManager.GetValueToByte("DemoCubemapping") == 1)
                {
                    GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);                      // Black background
                    GL.Color3f(1.0f, 1.0f, 1.0f);

                    GL.ShadeModel(GL.GL_SMOOTH);                                // Enables smooth color shading

                    GL.ClearDepth(1.0);                                         // Depth buffer setup
                    GL.Enable(GL.GL_DEPTH_TEST);                                // Enable depth buffer
                    GL.DepthFunc(GL.GL_LESS);                                   // Type of depth test to do

                    GL.Hint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);   // Really nice perspective calculations

                    GL.Enable(GL.GL_TEXTURE_2D);                                // Enable texture mapping
                    GL.Disable(GL.GL_DITHER);
                    GL.Disable(GL.GL_BLEND);

                    CM_BACK       = TextureManager.LoadTexture("data/cm_back.jpg", GL.GL_TEXTURE_2D, TextureManager.TM_PP_FLIP_IMAGE);
                    CM_X_POSITIVE = TextureManager.LoadCubemapTexture("data/cm_xpos.jpg", GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, TextureManager.TM_PP_FLIP_IMAGE);
                    CM_X_NEGATIVE = TextureManager.LoadCubemapTexture("data/cm_xneg.jpg", GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, TextureManager.TM_PP_FLIP_IMAGE);
                    CM_Y_POSITIVE = TextureManager.LoadCubemapTexture("data/cm_ypos.jpg", GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, TextureManager.TM_PP_FLIP_IMAGE);
                    CM_Y_NEGATIVE = TextureManager.LoadCubemapTexture("data/cm_yneg.jpg", GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, TextureManager.TM_PP_FLIP_IMAGE);
                    CM_Z_POSITIVE = TextureManager.LoadCubemapTexture("data/cm_zpos.jpg", GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, TextureManager.TM_PP_FLIP_IMAGE);
                    CM_Z_NEGATIVE = TextureManager.LoadCubemapTexture("data/cm_zneg.jpg", GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT, TextureManager.TM_PP_FLIP_IMAGE);

                    // Enable S T and R Texture Coordinate Generation as a reflection map
                    GL.TexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, (int)GL.GL_REFLECTION_MAP_EXT);
                    GL.TexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, (int)GL.GL_REFLECTION_MAP_EXT);
                    GL.TexGeni(GL.GL_R, GL.GL_TEXTURE_GEN_MODE, (int)GL.GL_REFLECTION_MAP_EXT);

                    if (GLConfig.GL_VERSION_1_2)
                    {
                        GL.TexParameteri(GL.GL_TEXTURE_CUBE_MAP_EXT, GL.GL_TEXTURE_WRAP_S, (int)GL.GL_CLAMP_TO_EDGE);
                        GL.TexParameteri(GL.GL_TEXTURE_CUBE_MAP_EXT, GL.GL_TEXTURE_WRAP_T, (int)GL.GL_CLAMP_TO_EDGE);
                        GL.TexParameteri(GL.GL_TEXTURE_CUBE_MAP_EXT, GL.GL_TEXTURE_WRAP_R, (int)GL.GL_CLAMP_TO_EDGE);
                    }
                    else
                    {
                        GL.TexParameteri(GL.GL_TEXTURE_CUBE_MAP_EXT, GL.GL_TEXTURE_WRAP_S, (int)GL.GL_CLAMP);
                        GL.TexParameteri(GL.GL_TEXTURE_CUBE_MAP_EXT, GL.GL_TEXTURE_WRAP_T, (int)GL.GL_CLAMP);
                        GL.TexParameteri(GL.GL_TEXTURE_CUBE_MAP_EXT, GL.GL_TEXTURE_WRAP_R, (int)GL.GL_CLAMP);
                    }

                    SphereQuadratic = GLU.NewQuadric();
                    GLU.QuadricNormals(SphereQuadratic, GLU.GLU_SMOOTH);
                }

                if (ConsoleVarManager.GetValueToByte("DemoGUI") == 1)
                {
                    GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);                      // Black background

                    GL.ShadeModel(GL.GL_SMOOTH);                                // Enables smooth color shading

                    GL.ClearDepth(1.0);                                         // Depth buffer setup
                    GL.Enable(GL.GL_DEPTH_TEST);                                // Enable depth buffer
                    GL.DepthFunc(GL.GL_LESS);                                   // Type of depth test to do

                    GL.Hint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);   // Really nice perspective calculations

                    GL.Disable(GL.GL_TEXTURE_2D);                               // Enable texture mapping
                    GL.Disable(GL.GL_DITHER);
                    GL.Enable(GL.GL_BLEND);
                    GL.BlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
                }
            }
        }
Esempio n. 5
0
        public static TextureNode LoadTexture(string FilePath, uint GLTarget, byte ImagePreProcess)
        {
            string FilePathShort = FilePathStandardization(FilePath);

            // Is it already loaded?
            if (FindTexture(FilePathShort) != null)
            {
                return(FindTexture(FilePathShort));
            }
            // Texture not found, load it into the memory
            else
            {
                // Add the current working directory of OpenGLDotNet
                string currentDirName = System.IO.Directory.GetCurrentDirectory();
                string FilePathLong   = currentDirName + @"\" + FilePathShort;
                FilePathLong = FilePathLong.Replace(@"\\", @"\");

                // Generate a new image number from DevIL
                uint ILTextureNumber = IL.GenImage();
                IL.BindImage(ILTextureNumber);

                // Load it into the memory with DevIL
                if (IL.LoadImage(FilePathLong))
                {
                    // Preprocess Check
                    if ((ImagePreProcess & TM_PP_FLIP_IMAGE) > 0)
                    {
                        ILU.FlipImage();
                    }
                    if ((ImagePreProcess & TM_PP_MIRROR_IMAGE) > 0)
                    {
                        ILU.Mirror();
                    }

                    // Create a new TextureNode
                    TextureNode Node = new TextureNode();

                    Node.FilePath      = FilePathShort;
                    Node.Width         = (uint)IL.GetInteger(IL.IL_IMAGE_WIDTH);
                    Node.Height        = (uint)IL.GetInteger(IL.IL_IMAGE_HEIGHT);
                    Node.Depth         = (uint)IL.GetInteger(IL.IL_IMAGE_DEPTH);
                    Node.GLImageFormat = (uint)IL.GetInteger(IL.IL_IMAGE_FORMAT);
                    Node.GLImageType   = (uint)IL.GetInteger(IL.IL_IMAGE_TYPE);
                    Node.DataSize      = (uint)IL.GetInteger(IL.IL_IMAGE_SIZE_OF_DATA);

                    // Generate a new texture number from OpenGL
                    uint[] GLTextureNumber = new uint[1];
                    GL.GenTextures(1, GLTextureNumber);
                    // Assign the new number to node
                    Node.GLTextureNumber = GLTextureNumber[0];

                    GL.BindTexture(GLTarget, Node.GLTextureNumber);
                    GL.TexImage2D(GLTarget, 0, (int)Node.GLImageFormat, (int)Node.Width, (int)Node.Height, 0, Node.GLImageFormat, Node.GLImageType, IL.GetData());

                    GL.TexParameteri(GLTarget, GL.GL_TEXTURE_WRAP_S, (int)GL.GL_CLAMP_TO_EDGE);
                    GL.TexParameteri(GLTarget, GL.GL_TEXTURE_WRAP_T, (int)GL.GL_CLAMP_TO_EDGE);
                    GL.TexParameteri(GLTarget, GL.GL_TEXTURE_WRAP_R, (int)GL.GL_CLAMP_TO_EDGE);
                    GL.TexParameteri(GLTarget, GL.GL_TEXTURE_MAG_FILTER, (int)GL.GL_LINEAR);
                    GL.TexParameteri(GLTarget, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR);

                    // We are done uploading the image, free up memory from DevIL
                    IL.DeleteImage(ILTextureNumber);

                    Textures.Add(FilePathShort, Node);

                    return(Node);
                }
                // Texture couldn't be loaded, return null
                else
                {
                    return(null);
                }
            }
        }