diff --git a/.gitignore b/.gitignore index f0738af..4baaa00 100644 --- a/.gitignore +++ b/.gitignore @@ -24,9 +24,9 @@ #*.lib # Executables -#*.exe -#*.out -#*.app +*.exe +*.out +*.app # ---> C # Object files diff --git a/opengl-test-two/bin/Debug/opengl-test-two.exe b/opengl-test-two/bin/Debug/opengl-test-two.exe deleted file mode 100644 index 65df034..0000000 Binary files a/opengl-test-two/bin/Debug/opengl-test-two.exe and /dev/null differ diff --git a/opengl-test-two/main.cpp b/opengl-test-two/main.cpp index 7cc4eb6..f97fb56 100644 --- a/opengl-test-two/main.cpp +++ b/opengl-test-two/main.cpp @@ -84,31 +84,62 @@ int main(int argc, char* args[]) { glBindBuffer(GL_ARRAY_BUFFER, colorbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_uv_buffer_data), g_uv_buffer_data, GL_STATIC_DRAW); + // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer. + GLuint FramebufferName; + glGenFramebuffers(1, &FramebufferName); + glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); + + tex1 = LoadTexture("../img/tests/flieger.jpg",&textw,&texth); - printf("Tex1: %d", tex1); - tex2 = LoadTexture("../img/tests/flieger2.jpg",&textw2,&texth2); - printf("Tex2: %d", tex2); + printf("Tex1: %d\n", tex1); glfwSetWindowSize(window, textw, texth); glViewport(0, 0, textw, texth); glfwSetWindowSizeLimits(window, textw, texth, textw, texth); + // The texture we' 2 triangles -> 1 square + glDisableVertexAttribArray(0); + + + // Render to the screen + glUseProgram(0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glViewport(0,0,textw, texth); // Render on the whole framebuffer, complete from the lower left corner to the upper right + + + glUseProgram(programRefineID); + glUniform1i(textureLocTri, 2); + glUniform1i(textureLocFore, 0); + // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); diff --git a/opengl-test-two/opengl-test-two.depend b/opengl-test-two/opengl-test-two.depend index 2647a78..1a80ac8 100644 --- a/opengl-test-two/opengl-test-two.depend +++ b/opengl-test-two/opengl-test-two.depend @@ -742,3 +742,13 @@ "loaders.h" +1473669189 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\src\loaders.cpp + + + + + "loaders.h" + +1473669189 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\loaders.h + + diff --git a/opengl-test-two/refinement.fragmentshader b/opengl-test-two/refinement.fragmentshader new file mode 100644 index 0000000..cd10ef8 --- /dev/null +++ b/opengl-test-two/refinement.fragmentshader @@ -0,0 +1,46 @@ +#version 330 core + +// Interpolated values from the vertex shaders +in vec2 UV; + +// Ouput data +out vec3 color; + +// Values that stay constant for the whole mesh. +uniform sampler2D trimap; +uniform sampler2D foreground; + + +int IS_BACKGROUND = 0; +int IS_UNDEFINED = 1; +int IS_FOREGROUND = 2; +int UNSET = -1; + +vec3 getTriColor(vec2 uvCoord) { + return texture(trimap, uvCoord).rgb; +} + +vec3 getForeColor(vec2 uvCoord) { + return texture(foreground, uvCoord).rgb; +} + +int getState(vec3 c) { + if (all(lessThanEqual(c, vec3(0.2f)))) { + return IS_BACKGROUND; + } else if (all(greaterThanEqual(c, vec3(0.8f)))) { + return IS_FOREGROUND; + } else { + return IS_UNDEFINED; + } +} + + +void main(){ + color = getTriColor(UV); + int status = getState(color); + + + if (status==IS_FOREGROUND) { + color = getForeColor(UV).rgb; + } +} diff --git a/opengl-test-two/refinement.vertexshader b/opengl-test-two/refinement.vertexshader new file mode 100644 index 0000000..da3cb49 --- /dev/null +++ b/opengl-test-two/refinement.vertexshader @@ -0,0 +1,17 @@ +#version 330 core + +// Input vertex data, different for all executions of this shader. +layout(location = 0) in vec3 vertexPosition_modelspace; +layout(location = 1) in vec2 vertexUV; + +// Output data ; will be interpolated for each fragment. +out vec2 UV; + +void main(){ + // Output position of the vertex, in clip space : MVP * position + gl_Position = vec4(vertexPosition_modelspace, 1); + + // UV of the vertex. No special space for this one. + UV = vertexUV; +} + diff --git a/opengl-test-two/trimap.fragmentshader b/opengl-test-two/trimap.fragmentshader index eb87cfa..0e5c5d3 100644 --- a/opengl-test-two/trimap.fragmentshader +++ b/opengl-test-two/trimap.fragmentshader @@ -4,11 +4,11 @@ in vec2 UV; // Ouput data -out vec3 color; +layout(location = 0) out vec3 color; +//out vec3 color; // Values that stay constant for the whole mesh. uniform sampler2D myTextureSampler; -uniform sampler2D myTextureSampler2; // Relative width/height of a pixel uniform float pixWidth; @@ -23,7 +23,7 @@ int UNSET = -1; vec3 getColor(vec2 uvCoord) { - return texture(myTextureSampler2, uvCoord).rgb; + return texture(myTextureSampler, uvCoord).rgb; } bool isBackground(vec3 c) { @@ -70,10 +70,10 @@ void main(){ } if (status == IS_BACKGROUND) { - color = vec3(1.0f, 0.0f, 0.0f); + color = vec3(0.0f); } else if (status == IS_FOREGROUND) { - color = vec3(0.0f, 1.0f, 0.0f); + color = vec3(1.0f); } else { - color = vec3(0.0f, 0.0f, 1.0f); + color = vec3(0.5f); } } diff --git a/opengl-test-two/trimap.vertexshader b/opengl-test-two/trimap.vertexshader index da3cb49..920a21f 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.x, -1*vertexPosition_modelspace.y, vertexPosition_modelspace.z, 1); // UV of the vertex. No special space for this one. UV = vertexUV;