Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: glGenerateMipmap is showing no texture

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Sep 2013
    Posts
    1

    glGenerateMipmap is showing no texture

    Hi I wanted to put a texture on a cube, so I used this:

    My load function:
    Code :
    void LoadTEX()
    {	
    	unsigned int texture;  
    	HBITMAP GLtex;
    	BITMAP tex;
    	byte Texture=TEX;
     
    	GLtex= (HBITMAP)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(Texture), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
    	GetObject(GLtex,sizeof(tex), &tex);
    	glGenTextures(1, &texture);
    	glPixelStorei(GL_UNPACK_ROW_LENGTH, tex.bmWidth);
    	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    	glBindTexture( GL_TEXTURE_2D, texture );
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.bmWidth, tex.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, tex.bmBits);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
    	glActiveTexture(GL_TEXTURE0);
    	glGenerateMipmap(GL_TEXTURE_2D);
    	// gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, tex.bmWidth, tex.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, tex.bmBits);
    	DeleteObject(GLtex);		
    }

    My display function:
    Code :
    		 glEnable(GL_TEXTURE_2D);
    		 glBindTexture( GL_TEXTURE_2D, texture );
    		 drawTexObject();

    If I uncomment gluBuild2DMipmaps and comment glGenerateMipmap the texture is on the cube. Why this what I'am trying is not working with GenerateMinimap ? The window is not even shown. I just can't work out this.

    The texture is loaded from resource file and it is a BMP 512x512 24bpp BGR. I got OpenGL 3.1 support on ATI card.

  2. #2
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    97
    hi,

    i canīt give the propper answer right now, but 2 things.

    1. whenever you have a opengl call not working as expected: check for glErrors !!!! It really helps so mutch
    Code :
    extern void CheckGLErrors( int x )
    {
      GLenum err ;
     
      while ( (err = glGetError()) != GL_NO_ERROR )
        fprintf( stderr, "\n %i ) OpenGL Error : %i ,  %s\n", x ,err,  gluErrorString ( err ) );
    };

    2. You should just rearrange your code.. that may help, some stuff is nit needed there:
    Code :
    void LoadTEX() 
    {
             unsigned int texture;
             HBITMAP GLtex;
             BITMAP tex;
             byte Texture=TEX;
             GLtex= (HBITMAP)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(Texture), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
             GetObject(GLtex,sizeof(tex), &tex);
     
         glGenTextures(1, &texture);
         glPixelStorei(GL_UNPACK_ROW_LENGTH, tex.bmWidth);
         glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
         glBindTexture( GL_TEXTURE_2D, texture );
     
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.bmWidth, tex.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, tex.bmBits);
     
         glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST);
         glGenerateMipmap(GL_TEXTURE_2D);
     
         // gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, tex.bmWidth, tex.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, tex.bmBits);
         DeleteObject(GLtex);
      }

    hope you find it..
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •