Merged trimap into opengl
This commit is contained in:
Binary file not shown.
@@ -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");
|
GLuint programID = LoadShaders("trimap.vertexshader", "trimap.fragmentshader");
|
||||||
printf("%d", programID);
|
GLint textureLocation = glGetUniformLocation(programID, "myTextureSampler");
|
||||||
GLint textureLocation = glGetUniformLocationARB(programID, "myTextureSampler");
|
GLint widthLocation = glGetUniformLocation(programID, "pixWidth");
|
||||||
glUniform1i(textureLocation, tex_jpe);
|
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);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glUseProgram(programID);
|
glUseProgram(programID);
|
||||||
|
glUniform1f(widthLocation, 1.0f/textw);
|
||||||
|
glUniform1f(heigthLocation, 1.0f/texth);
|
||||||
// 1rst attribute buffer : vertices
|
// 1rst attribute buffer : vertices
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp
|
1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp
|
||||||
<iostream>
|
<iostream>
|
||||||
|
|
||||||
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
|
||||||
<GL/glew.h>
|
<GL/glew.h>
|
||||||
<GLFW/glfw3.h>
|
<GLFW/glfw3.h>
|
||||||
<SDL2/SDL.h>
|
<SDL2/SDL.h>
|
||||||
|
|||||||
@@ -8,10 +8,71 @@ out vec3 color;
|
|||||||
|
|
||||||
// Values that stay constant for the whole mesh.
|
// Values that stay constant for the whole mesh.
|
||||||
uniform sampler2D myTextureSampler;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ out vec2 UV;
|
|||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
// Output position of the vertex, in clip space : MVP * position
|
// 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 of the vertex. No special space for this one.
|
||||||
UV = vertexUV;
|
UV = vertexUV;
|
||||||
|
|||||||
Reference in New Issue
Block a user