All posts by kpark

Texture Animation

Texture Animation
5974008442.zip
// init 중간생략..

 for (int i=0; i<7; i++)
 {
  char filename[255];
  sprintf(filename, “tacgun0%d.rgb”, i);
        texture[i] = InitTexture(filename);
 }


// draw 중간생략..

 glActiveTexture(GL_TEXTURE0);
 glBindTexture(GL_TEXTURE_2D, texture[currentTex]);
 drawSquare();
 glBindTexture(GL_TEXTURE_2D, 0);

// update

void update()
{
 static int currentTime, deltaTime, prevTime = 0;
 currentTime = glutGet(GLUT_ELAPSED_TIME);
 deltaTime = currentTime – prevTime;
 prevTime = currentTime;
 currentTex = (GLuint) ((float)currentTime * 0.01) % 7;
 glutPostRedisplay();
}

ModernOpenGL Mipmap

Automatic mipmap generation


Mipmaps of a texture can be automatically generated with the glGenerateMipmap function. OpenGL 3.0 or greater is required for this function (or the extension GL_ARB_framebuffer_object). The function works quite simply; when you call it for a texture, mipmaps are generated for that texture:
http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation




  glTexImage2D(GL_TEXTURE_2D, 0, numComponents == 3 ? GL_RGB : GL_RGBA, imageWidth, imageHeight,  0, numComponents == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, imagePtr);
  glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps now!!
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);



 

OpenGL Texture Mapping Filtering & Environment Parameters

Wrapping parameters (CLAMP | CLAMP_TO_EDGE | GL_REPEAT | GL_MIRRORED_REPEAT)


// Square Vertices Texture Coordinates
 squareTextureCoords.push_back(glm::vec2(-1.0f, -1.0f));
 squareTextureCoords.push_back(glm::vec2(3.0f, -1.0f));
 squareTextureCoords.push_back(glm::vec2(3.0f, 3.0f));
 squareTextureCoords.push_back(glm::vec2
(-1.0f, 3.0f));

//(왼쪽 아래)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

//(오른쪽 아래)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

//(왼쪽 위)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

//(오른쪽 위)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
사용자 삽입 이미지4500481641.cpp

Magnification/Minification/Mipmap filter parameters (NEAREST | LINEAR)

//(위왼쪽)
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_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

//(아래왼쪽)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

//(아래오른쪽)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
사용자 삽입 이미지3006233632.cpp