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: Texture Mipmapping

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    18

    Texture Mipmapping

    Hello,

    I've been trying to get mipmapping working but I'm really confused as to why my approach doesn't work. Here's what I've got.

    texture related init:

    Code :
    // generate the texture
    CreateGLTexture("panelbrn01scr.tga", wallPieceTexture_);
    glBindTexture(GL_TEXTURE_2D, wallPieceTexture_);	
     
    // set up the texture function
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     
    // set up the texture filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
    // generate the mipmap data for the texture
    glGenerateMipmap(GL_TEXTURE_2D);

    the render call:

    Code :
    glEnable(GL_TEXTURE_2D);
     
    glBindTexture(GL_TEXTURE_2D, wallPieceTexture_);
     
    glBindVertexArray(wallPieceArray_);
     
    glPushMatrix();
    	for(int i = 0; i < 10; i++) {
    		glPushMatrix();
    			for(int j = 0; j < 10; j++) {
    				glDrawArrays(GL_TRIANGLES, 0, M_WALL_PIECE_VERTICES);
    				glTranslatef(1.0f, 0.0f, 0.0f);
    			}
    		glPopMatrix();
    		glTranslatef(0.0f, 1.0f, 0.0f);
    	}
    glPopMatrix();
     
     
    glDisable(GL_TEXTURE_2D);

    CreateGLTexture() by Matthew Brett:

    Code :
    bool CreateGLTexture(char *name, GLuint & TexID )
    {
    	LoadTGA(name);
     
     
    	// Typical Texture Generation Using Data From The TGA ( CHANGE )
    	glGenTextures(1, &TexID);				// Create The Texture ( CHANGE )
    	glBindTexture(GL_TEXTURE_2D, TexID);
    	glTexImage2D(GL_TEXTURE_2D, 0, texture_bpp / 8, texture_width, texture_height, 0, texture_type, GL_UNSIGNED_BYTE, texture_imageData);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     
    	if (texture_imageData)						// If Texture Image Exists ( CHANGE )
    	{
    		free(texture_imageData);					// Free The Texture Image Memory ( CHANGE )
    	}
     
     
     
    	return false;
    }

    I would post the rendered image but due to being too new of a member the forum has restricted me in doing so. However, I'm sure all of you know what artifacts I get due to no mipmapping so shouldn't be a problem.

    I'm not sure as to where I'm going wrong here. Any help would be greatly appreciated!

    Thanks in advance!

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    18
    Found the issue! The problem was with the program flow: I initialized other data that set the MIN_FILTER differently after generating the mipmaps. After adding the calls to the glTexParameteri() to the render function just before rendering the mipmapped textured object, everything worked fine.

Posting Permissions

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