standard texture class?

standard texture class?

Post by ehmdji » Fri, 31 Jan 2003 03:30:00



hi,

im trying to put nehe's texture-loading-code in a class, but i get
compile errors.
has anyone else done something like this and could provide me with
that class?

i just want to load textures onto objects like
LoadTexture("pic.tif");

i know this problem is more a c++ prob, but anyways:

AUX_RGBImageRec Texture::LoadBMP() {
...

Quote:}

this line gives me: overloaded function ...

thanks.

 
 
 

standard texture class?

Post by Niss » Fri, 31 Jan 2003 18:39:40



> i know this problem is more a c++ prob, but anyways:

> AUX_RGBImageRec Texture::LoadBMP() {
> ...
> }

> this line gives me: overloaded function ...

Overloaded function what?

Make sure your declaration and definition is the same.

Declaration:

class Texture
{
AUX_RGBImageRec LoadBMP(char *name);

Quote:};

would require the following definition:

AUX_RGBImageRec Texture::LoadBMP(char *name)
{
        blablabla

Quote:}

"A machine that goes PING!" - Monthy Python
"All's fair in war and profit!"- Ferengi rule of aquisition no. 43


 
 
 

standard texture class?

Post by berthelot samu » Sat, 01 Feb 2003 23:18:34


hi,
i did it for my game. here is the code of the .h file

// Texture.h: interface for the CTexture class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TEXTURE_H__4A9403ED_A954_44CC_8863_A2F8EEF0D9F5__INCLUDED_)
#define AFX_TEXTURE_H__4A9403ED_A954_44CC_8863_A2F8EEF0D9F5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <math.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl\glaux.h>

class CTexture  
{
public:

        unsigned int m_texID;
        AUX_RGBImageRec *m_textureImage;

        CTexture(){m_textureImage = NULL;}
        virtual ~CTexture(){Unload();}

        void Unload()
        {
                glDeleteTextures(1, &m_texID);

                if (m_textureImage != NULL)
                        free(m_textureImage);
                m_textureImage = NULL;
        }

        void cleanTexture()
        {
                if (m_textureImage)                                            
                {      
                        if (m_textureImage->data)                            
                                free(m_textureImage->data);                  
                        free(m_textureImage);                                  
                }
        }

        void LoadGLTextures(char *Filename);
        AUX_RGBImageRec *LoadBMP(char *Filename);

Quote:};

#endif // !defined(AFX_TEXTURE_H__4A9403ED_A954_44CC_8863_A2F8EEF0D9F5__INCLUDED_)

and that is the code of the .cpp file

// Texture.cpp: implementation of the CTexture class.
//
//////////////////////////////////////////////////////////////////////

#include "Texture.h"

AUX_RGBImageRec* CTexture::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

Quote:}

void CTexture::LoadGLTextures(char *Filename)                           // Load Bitmaps And
Convert To Textures
{
        m_textureImage=LoadBMP(Filename);

Quote:}

good luck !
sam

> hi,

> im trying to put nehe's texture-loading-code in a class, but i get
> compile errors.
> has anyone else done something like this and could provide me with
> that class?

> i just want to load textures onto objects like
> LoadTexture("pic.tif");

> i know this problem is more a c++ prob, but anyways:

> AUX_RGBImageRec Texture::LoadBMP() {
> ...
> }

> this line gives me: overloaded function ...

> thanks.