diff --git a/img/backgrounds/sky.jpg b/img/backgrounds/sky.jpg new file mode 100644 index 0000000..6272390 Binary files /dev/null and b/img/backgrounds/sky.jpg differ diff --git a/opengl-test-two/main.cpp b/opengl-test-two/main.cpp index f97fb56..b2911a2 100644 --- a/opengl-test-two/main.cpp +++ b/opengl-test-two/main.cpp @@ -10,7 +10,7 @@ int main(int argc, char* args[]) { GLFWwindow* window; - GLuint tex1, tex2; + GLuint texFG, texBG; int textw, texth; int textw2, texth2; @@ -92,20 +92,19 @@ int main(int argc, char* args[]) { - tex1 = LoadTexture("../img/tests/flieger.jpg",&textw,&texth); - printf("Tex1: %d\n", tex1); + texBG = LoadTexture("../img/backgrounds/sky.jpg",&textw2,&texth2); + texFG = LoadTexture("../img/tests/flieger.jpg",&textw,&texth); + printf("Tex1: %d\n", texFG); glfwSetWindowSize(window, textw, texth); glViewport(0, 0, textw, texth); glfwSetWindowSizeLimits(window, textw, texth, textw, texth); - // The texture we' -1473145022 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\main.cpp +1473703631 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\main.cpp - - - - + "loaders.h" 1473015242 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h diff --git a/opengl-test-two/refinement.fragmentshader b/opengl-test-two/refinement.fragmentshader index cd10ef8..09a7857 100644 --- a/opengl-test-two/refinement.fragmentshader +++ b/opengl-test-two/refinement.fragmentshader @@ -9,6 +9,7 @@ out vec3 color; // Values that stay constant for the whole mesh. uniform sampler2D trimap; uniform sampler2D foreground; +uniform sampler2D background; int IS_BACKGROUND = 0; @@ -24,6 +25,10 @@ vec3 getForeColor(vec2 uvCoord) { return texture(foreground, uvCoord).rgb; } +vec3 getBackColor(vec2 uvCoord) { + return texture(background, uvCoord).rgb; +} + int getState(vec3 c) { if (all(lessThanEqual(c, vec3(0.2f)))) { return IS_BACKGROUND; @@ -42,5 +47,9 @@ void main(){ if (status==IS_FOREGROUND) { color = getForeColor(UV).rgb; + } else if (status==IS_BACKGROUND) { + color = getBackColor(UV).rgb; + } else { + // render undefined area } } diff --git a/opengl-test-two/trimap.fragmentshader b/opengl-test-two/trimap.fragmentshader index 0e5c5d3..75da72f 100644 --- a/opengl-test-two/trimap.fragmentshader +++ b/opengl-test-two/trimap.fragmentshader @@ -21,6 +21,10 @@ int IS_UNDEFINED = 1; int IS_FOREGROUND = 2; int UNSET = -1; +vec3 greenValue = vec3(0.0f, 1.0f, 0.0f); +vec3 difference = vec3(40.0f/255.0f); +int radius = 10; + vec3 getColor(vec2 uvCoord) { return texture(myTextureSampler, uvCoord).rgb; @@ -31,8 +35,8 @@ bool isBackground(vec3 c) { if (all( lessThanEqual(c, vec3(51.0f/255.0f, 208.0f/255.0f, 13.0f/255.0f))) && all(greaterThanEqual(c, vec3(47.0f/255.0f, 204.0f/255.0f, 9.0f/255.0f)))*/ // 0, 255, 0 - if (all( lessThanEqual(c, vec3(2.0f/255.0f, 255.0f/255.0f, 2.0f/255.0f))) && - all(greaterThanEqual(c, vec3(0.0f/255.0f, 253.0f/255.0f, 0.0f/255.0f))) + if (all( lessThanEqual(c, greenValue+difference)) && + all(greaterThanEqual(c, greenValue-difference)) ) { return true; } else { @@ -43,9 +47,9 @@ bool isBackground(vec3 c) { void main(){ int status = UNSET; - for(int w=-5;w<=5;w++){ - for(int h=-5;h<=5;h++){ - if (w+h==-10) { // first pixel + for(int w=-radius;w<=radius;w++){ + for(int h=-radius;h<=radius;h++){ + if (w+h==-radius*2) { // first pixel if (isBackground(getColor(UV+vec2(pixWidth*w, pixHeight*h)))) { status = IS_BACKGROUND; } else {