Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Problems loading textures

This topic is 6171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I''m writing some spanish tutorial about OpenGL based on the Nehe''s tutorials. I have a problem when I load textures, basically I do the same that Nehe and this run good in my computer and others computer''s friends, but some people talk to me that they can run this tutorial because this craft at the start with de "Debug assertion failed" windows or "Internal error", tracing when loading texture. Why? Here is the implementation of the CTextura object: //--------------------------------------------------------------- // Nombre: Constructor // Descripcion: Constructor de la clase. Inicializa las variables // Parametros: Ninguno //--------------------------------------------------------------- CTextura::CTextura() { m_nID=0; } //--------------------------------------------------------------- // Nombre: Destructor // Descripcion: Destructor de la clase. Elimina la textura // Parametros: Ninguno //--------------------------------------------------------------- CTextura::~CTextura() { Elimina(); } //--------------------------------------------------------------- // Nombre: Crear // Descripcion: Establece los parámetros GL para cargar // Parametros: // char* szNombreFichero: Nombre del fichero a cargar //--------------------------------------------------------------- bool CTextura::Crear(char* szNombreFichero) { Elimina(); // Copiamos el nombre de fichero unsigned long int nszLon = strlen(szNombreFichero); // Generamos la ID de la textura glGenTextures(1, &m_nID); m_nID++; // Usamos un offset de +1 para diferenciar del estado no-inicializado glBindTexture(GL_TEXTURE_2D, m_nID-1); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); return true; } //--------------------------------------------------------------- // Nombre: Elimina // Descripcion: Elimina la textura // Parametros: Ninguno //--------------------------------------------------------------- void CTextura::Elimina() { if( m_nID ) { m_nID--; glDeleteTextures(1, &m_nID); m_nID=0; } } //--------------------------------------------------------------- // Nombre: Usa // Descripcion: Usa la textura actual // Parametros: Ninguno //--------------------------------------------------------------- void CTextura::Usa() { glBindTexture(GL_TEXTURE_2D, m_nID-1); } //--------------------------------------------------------------- // Nombre: CargarBMP // Descripcion: Carga un fichero BMP y almacena los datos // Parametros: Ninguno //--------------------------------------------------------------- bool CTextura::CargarBMP(char *szNombreFichero) { FILE *hFichero; AUX_RGBImageRec *Imagen; bool bResultado=false; if (szNombreFichero) // Comprobamos que el nombre de fichero sea correcto { hFichero=fopen(szNombreFichero,"r"); // Comprobamos si el fichero existe (Si podemos abrirlo) if (hFichero) // ¿Existe el fichero? { fclose(hFichero); // Cerramos el handle Crear(szNombreFichero); Imagen=auxDIBImageLoad(szNombreFichero); // Cargamos el BMP m_nAncho=Imagen->sizeX; m_nAlto=Imagen->sizeY; glTexImage2D(GL_TEXTURE_2D, 0, 3, m_nAncho, m_nAlto, 0, GL_RGB, GL_UNSIGNED_BYTE, Imagen->data); bResultado=true; } } delete Imagen->data; delete Imagen; return bResultado; } All the code can be found in: http://usuarios.tripod.es/andromeda_studios/descarga/tutoriales/tutorial_7b.zip Thanks and sorry about my poor english

Share this post

Link to post
Share on other sites

Perhaps, you should use
instead of
delete Imagen->data;
delete Imagen;

Its right that new and delete should be preferred, but here you free sth that was allocated with malloc() before, so you MUST free it with free().

Greetings Ben

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!