GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


ARGH by luck
1
 
#ifndef TEXMAN_HEADER
#define TEXMAN_HEADER
#include "glTools.h"
#include    <gl\glaux.h>
#include    <gl\glu.h>


class texMan
{
    public: 
        GLuint texture_objects[35];

                
        GLubyte *bits; 
        BITMAPINFO *info;
        
        texMan()
        {

        }

        
            
        AUX_RGBImageRec* LoadBMP(char *Filename)                    // Loads A Bitmap Image
        {
        
            FILE *File=NULL;                            // File Handle

            if (!Filename)                                // Make Sure A Filename Was Given
            {
                return NULL;                            // If Not Return NULL
            }
            
            File = fopen(Filename,"r");                        // Check To See If The File Exists
            
            
            if (File)                                // Does The File Exist?
            {
                fclose(File);                            // Close The Handle
                return auxDIBImageLoad(Filename);                // Load The Bitmap And Return A Pointer
            }
            return NULL;                                // If Load Failed Return NULL

        }






        
        int LoadTexture(char * fileName, int index)
        {
        
            int Status=FALSE;                            // Status Indicator

            AUX_RGBImageRec *TextureImage[2];                    // Create Storage Space For The Texture

            memset(TextureImage,0,sizeof(void *)*1);                // Set The Pointer To NULL
            
            
            // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
            if (TextureImage[0]=LoadBMP(fileName))
            {
                
            
                Status=TRUE;                            // Set The Status To TRUE
                
                
                // Generate The Texture
                glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, 
                GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
                
                // Typical Texture Generation Using Data From The Bitmap
                glBindTexture(GL_TEXTURE_2D, texture_objects[index]);
        
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);    // Linear Filtering
                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    // Linear Filtering
    
                        
            
            }
            
            if (TextureImage[0])                            // If Texture Exists
                {
                    if (TextureImage[0]->data)                    // If Texture Image Exists
                    {
                        free(TextureImage[0]->data);                // Free The Texture Image Memory
                    }

                    free(TextureImage[0]);                        // Free The Image Structure
                }
            
            
            
            return Status;                                // Return The Status
            
          }

        
        
        void Init2D(void)
        {
                glEnable(GL_TEXTURE_2D); 
                
                glGenTextures(35, texture_objects);
            
                
            
                // Main Menu
            //    LoadTexture(".\\menus\\menu1.BMP", 0); 
                
            //    LoadTexture(".\\menus\\play.BMP", 1); 
            //    LoadTexture(".\\menus\\edit.BMP", 2); 
                
                LoadTexture(".\\menus\\options.BMP", 1); 
            
                // Cursor
                LoadTexture(".\\menus\\cursor1.BMP", 0);
            
                
                /*
                // Edit Menu
                LoadTexture(".\\menus\\EM_default.BMP", 5);  
                LoadTexture(".\\menus\\EM_file.BMP", 6);  
                LoadTexture(".\\menus\\EM_control.BMP", 7);  
                LoadTexture(".\\menus\\EM_options.BMP", 8);  
                LoadTexture(".\\menus\\EM_frame.BMP", 9);  
                LoadTexture(".\\menus\\EM_main_menu.BMP", 10);
                
                // File submenu
                LoadTexture(".\\menus\\EM_file_new.BMP", 11);  
                LoadTexture(".\\menus\\EM_file_load.BMP", 12);  
                LoadTexture(".\\menus\\EM_file_save.BMP", 13);  
                
                LoadTexture(".\\menus\\EM_file_new_s.BMP", 14);  
                LoadTexture(".\\menus\\EM_file_load_s.BMP", 15);  
                LoadTexture(".\\menus\\EM_file_save_s.BMP", 16);  

                
                // controls submenu

                LoadTexture(".\\menus\\EM_control_play.BMP", 17);  
                LoadTexture(".\\menus\\EM_control_stop.BMP", 18);  
                LoadTexture(".\\menus\\EM_control_loop.BMP", 19);  
                
                LoadTexture(".\\menus\\EM_control_play_s.BMP", 20);  
                LoadTexture(".\\menus\\EM_control_stop_s.BMP", 21);  
                LoadTexture(".\\menus\\EM_control_loop_s.BMP", 22);  

                
                // options submenu

                LoadTexture(".\\menus\\EM_options_frames.BMP", 23);  
                LoadTexture(".\\menus\\EM_options_time.BMP", 24);  
                LoadTexture(".\\menus\\EM_options_transf.BMP", 25);  
                
                LoadTexture(".\\menus\\EM_options_frames_s.BMP", 26);  
                LoadTexture(".\\menus\\EM_options_time_s.BMP", 27);  
                LoadTexture(".\\menus\\EM_options_transf_s.BMP", 28);  

                
                // frame submenu
                
                LoadTexture(".\\menus\\EM_frame_jumpto.BMP", 29);  
                LoadTexture(".\\menus\\EM_frame_save.BMP", 30);  
                LoadTexture(".\\menus\\EM_frame_edit.BMP", 31);  
                
                LoadTexture(".\\menus\\EM_frame_jumpto_s.BMP", 32);  
                LoadTexture(".\\menus\\EM_frame_save_s.BMP", 33);  
                LoadTexture(".\\menus\\EM_frame_edit_s.BMP", 34);  
  
                // background
                LoadTexture(".\\menus\\Bliss.BMP",35); 
                */        
        }

};
#endif