Category Archives: Modern OpenGL

OpenGL Blending Filter

OpenGL Blending Filter

14.OpenGLBlendingFilter.zip


 glEnable(GL_BLEND);
 if (g_filter == 0)                     // Default (no blending) = Cs*1
  glBlendFunc(GL_ONE, GL_ZERO);
 else if (g_filter == 1)                // Draw background only = Cd*1
  glBlendFunc(GL_ZERO, GL_ONE);
 else if (g_filter == 2)                // Cs*1 + Cd*1
  glBlendFunc(GL_ONE, GL_ONE);
 else if (g_filter == 3)                // Alpha blending (back-to-front) = Cs*As + Cd*(1-As)
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 else if (g_filter == 4)                // Additive blending (brighten the scene) = Cs*As + Cd*1
  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 else if (g_filter == 5)                // Multiplicative blending = Cd*Cs
  glBlendFunc(GL_ZERO, GL_SRC_COLOR);
 else if (g_filter == 6)                // darken the scene = Cd*As
  glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
 else if (g_filter == 7)                 // Invert all the colors = Cs*(1-Cd)
  glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);

Texture Animation

Texture Animation


// 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();
}

OpenGL Texture Mapping Filtering & Environment Parameters

Wrapping parameters (CLAMP | CLAMP_TO_EDGE | GL_REPEAT | GL_MIRRORED_REPEAT)

// Square 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);

사용자 삽입 이미지



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);

사용자 삽입 이미지

simage library



COIN3D simage library (http://www.coin3d.org/lib/simage)


  • COIN3D simage가 제공하는 이미지 포멧은 JPEG, PNG, GIF, TIFF, RGB, PIC, TGA, EPS등 다양하다.
  • COIN3D의 simage library를 사용하려면, 프로젝트에 additional library and include directory를 추가해야한다. 프로젝트 폴더 안에 include 와 lib 디렉토리를 생성하고 simage.h 과 simage1d.lib를 복사한다.
  • 그리고, 프로젝트에 simage1.lib 라이브러리를 링크한다.


simage include와 library directory 추가, 라이브러리 링크

Project->Properties(ALT+F7)->Configuration Properties->C/C++->General에
Additional Include Directories에 ./include를 넣는다.

Project->Properties(ALT+F7)->Configuration Properties->C/C++->Preprocessor에 Preprocessor Definitions에 ;SIMAGE_DLL를 추가한다.

Project->Properties(ALT+F7)->Configuration Properties->Linker->General에
Additional Library Directories에 ./lib/debug를 넣는다.

Project->Properties(ALT+F7)->Configuration Properties->Linker->Input에
Additional Dependencies에 simage1.lib을 추가한다.