3 Commits

Author SHA1 Message Date
Caesar2011
2147b74e86 Tri-Map working now; output of every state in a different color 2016-09-05 22:21:12 +02:00
Caesar2011
2acbd0c10f Trimap implemented; need bugfixes 2016-09-05 21:58:45 +02:00
Caesar2011
fe718a4658 Merged texturebuffer into opengl 2016-09-05 19:45:47 +02:00
5 changed files with 84 additions and 16 deletions

View File

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

View File

@@ -2,7 +2,7 @@
1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp
<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>
<GLFW/glfw3.h>
<SDL2/SDL.h>

View File

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

View File

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