diff --git a/opengl-test-two/bin/Debug/opengl-test-two.exe b/opengl-test-two/bin/Debug/opengl-test-two.exe index 8c77a22..c259a5b 100644 Binary files a/opengl-test-two/bin/Debug/opengl-test-two.exe and b/opengl-test-two/bin/Debug/opengl-test-two.exe differ diff --git a/opengl-test-two/main.cpp b/opengl-test-two/main.cpp index 8716c01..4125152 100644 --- a/opengl-test-two/main.cpp +++ b/opengl-test-two/main.cpp @@ -251,12 +251,18 @@ int main(int argc, char* args[]) { - tex_jpe=LoadTexture("../img/tests/test.bmp",&textw,&texth); + tex_jpe=LoadTexture("../img/tests/test.png",&textw,&texth); GLuint programID = LoadShaders("trimap.vertexshader", "trimap.fragmentshader"); - printf("%d", programID); - GLint textureLocation = glGetUniformLocationARB(programID, "myTextureSampler"); - glUniform1i(textureLocation, tex_jpe); + GLint textureLocation = glGetUniformLocation(programID, "myTextureSampler"); + GLint widthLocation = glGetUniformLocation(programID, "pixWidth"); + GLint heigthLocation = glGetUniformLocation(programID, "pixHeight"); + printf("Shader program ID: %d\n", programID); + printf("textureLocation: %d\n", textureLocation); + printf("widthLocation: %d\n", widthLocation); + printf("heigthLocation: %d\n", heigthLocation); + printf("Width: %f\n", 1.0f/textw); + printf("Height: %f\n", 1.0f/texth); @@ -270,7 +276,8 @@ int main(int argc, char* args[]) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(programID); - + glUniform1f(widthLocation, 1.0f/textw); + glUniform1f(heigthLocation, 1.0f/texth); // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); @@ -286,12 +293,12 @@ int main(int argc, char* args[]) { glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorbuffer); glVertexAttribPointer( - 1, // attribute. No particular reason for 1, but must match the layout in the shader. - 2, // size - GL_FLOAT, // type - GL_FALSE, // normalized? - 0, // stride - (void*)0 // array buffer offset + 1, // attribute. No particular reason for 1, but must match the layout in the shader. + 2, // size + GL_FLOAT, // type + GL_FALSE, // normalized? + 0, // stride + (void*)0 // array buffer offset ); diff --git a/opengl-test-two/opengl-test-two.depend b/opengl-test-two/opengl-test-two.depend index a86399f..d81bcc1 100644 --- a/opengl-test-two/opengl-test-two.depend +++ b/opengl-test-two/opengl-test-two.depend @@ -2,7 +2,7 @@ 1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp -1473097371 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\main.cpp +1473106263 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\main.cpp diff --git a/opengl-test-two/trimap.fragmentshader b/opengl-test-two/trimap.fragmentshader index bdd956c..a098a00 100644 --- a/opengl-test-two/trimap.fragmentshader +++ b/opengl-test-two/trimap.fragmentshader @@ -8,10 +8,71 @@ out vec3 color; // Values that stay constant for the whole mesh. uniform sampler2D myTextureSampler; +//uniform float pixWidth; +//uniform float pixHeight; -void main(){ - // Output color = color of the texture at the specified UV - color = texture( myTextureSampler, UV ).rgb; + + + +int IS_BACKGROUND = 0; +int IS_UNDEFINED = 1; +int IS_FOREGROUND = 2; +int UNSET = -1; + + +vec3 getColor(vec2 uvCoord) { + return texture(myTextureSampler, uvCoord).rgb; } +bool isBackground(vec3 c) { + // 49,206, 11 + 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))) + ) { + return true; + } else { + return false; + } +} + +void main(){ + float pixWidth = 0.001174f; + float pixHeight = 0.002083f; + int status = UNSET; + float pw = pixWidth; + float ph = pixHeight; + + // Output color = color of the texture at the specified UV + for(int w=-5;w<=5;w++){ + for(int h=-5;h<=5;h++){ + if (w+h==-10) { // first pixel + if (isBackground(getColor(UV+vec2(pixWidth*w,pixHeight*h)))) { + status = IS_BACKGROUND; + } else { + status = IS_FOREGROUND; + } + } else { // other pixels + if (isBackground(getColor(UV+vec2(pixWidth*w,pixHeight*h)))) { + if (status != IS_BACKGROUND) { + status = IS_UNDEFINED; + break; + } + } else { + if (status != IS_FOREGROUND) { + status = IS_UNDEFINED; + break; + } + } + } + } + } + + if (status == IS_BACKGROUND) { + color = vec3(1.0f, 0.0f, 0.0f); + } else if (status == IS_FOREGROUND) { + color = vec3(0.0f, 1.0f, 0.0f); + } else { + color = vec3(0.0f, 0.0f, 1.0f); + } +} diff --git a/opengl-test-two/trimap.vertexshader b/opengl-test-two/trimap.vertexshader index 59305f6..da3cb49 100644 --- a/opengl-test-two/trimap.vertexshader +++ b/opengl-test-two/trimap.vertexshader @@ -9,7 +9,7 @@ out vec2 UV; void main(){ // Output position of the vertex, in clip space : MVP * position - gl_Position = vec4(vertexPosition_modelspace,1); + gl_Position = vec4(vertexPosition_modelspace, 1); // UV of the vertex. No special space for this one. UV = vertexUV;