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/doku/OpenGL-Funktionsweise.svg b/doku/OpenGL-Funktionsweise.svg
new file mode 100644
index 0000000..63fd150
--- /dev/null
+++ b/doku/OpenGL-Funktionsweise.svg
@@ -0,0 +1,121 @@
+
\ No newline at end of file
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/img/tests/flieger.jpg b/img/tests/flieger.jpg
new file mode 100644
index 0000000..201e21b
Binary files /dev/null and b/img/tests/flieger.jpg differ
diff --git a/img/tests/flieger2.jpg b/img/tests/flieger2.jpg
new file mode 100644
index 0000000..402cc26
Binary files /dev/null and b/img/tests/flieger2.jpg differ
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 8603c2d..0000000
Binary files a/opengl-test-two/bin/Debug/opengl-test-two.exe and /dev/null differ
diff --git a/opengl-test-two/include/loaders.h b/opengl-test-two/include/loaders.h
new file mode 100644
index 0000000..257b499
--- /dev/null
+++ b/opengl-test-two/include/loaders.h
@@ -0,0 +1,10 @@
+#ifndef LOADERS_H
+#define LOADERS_H
+
+#define GLEW_STATIC
+#include
+
+int InitLoaders();
+GLuint LoadTexture(char *filename,int *textw,int *texth);
+GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path);
+#endif // LOADERS_H
diff --git a/opengl-test-two/main.cpp b/opengl-test-two/main.cpp
index d884579..b2911a2 100644
--- a/opengl-test-two/main.cpp
+++ b/opengl-test-two/main.cpp
@@ -4,172 +4,15 @@
#include
#include
#include
-#include
-#include
-#include
#include
-#include
#include
-
-GLuint LoadTexture(char *filename,int *textw,int *texth) {
- SDL_Surface *surface;
- GLuint textureid;
- int mode;
- surface = IMG_Load(filename);
- // Or if you don't use SDL_image you can use SDL_LoadBMP here instead:
- // surface = SDL_LoadBMP(filename);
-
- // could not load filename
- if (!surface) {
- return 0;
- }
-
- // work out what format to tell glTexImage2D to use...
- if (surface->format->BytesPerPixel == 3) { // RGB 24bit
- mode = GL_RGB;
-
- } else if (surface->format->BytesPerPixel == 4) { // RGBA 32bit
- mode = GL_RGBA;
- } else {
- SDL_FreeSurface(surface);
- return 0;
- }
-
- *textw=surface->w;
- *texth=surface->h;
- // create one texture name
- glGenTextures(1, &textureid);
- // tell opengl to use the generated texture name
- glBindTexture(GL_TEXTURE_2D, textureid);
- // this reads from the sdl surface and puts it into an opengl texture
- glTexImage2D(GL_TEXTURE_2D, 0, mode, surface->w, surface->h, 0, mode, GL_UNSIGNED_BYTE, surface->pixels);
- // these affect how this texture is drawn later on...glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // clean up
- SDL_FreeSurface(surface);
- return textureid;
-
-}
-
-void DrawTexture(int x, int y, GLuint textureid,int textw,int texth) {
- //printf("x: %d\ty: %d\tw: %d\th: %d\n", x, y, textw, texth);
- //int textw,texth;
- // tell opengl to use the generated texture name
- glBindTexture(GL_TEXTURE_2D, textureid);
- glEnable(GL_TEXTURE_2D);
- // make a rectangle
- glBegin(GL_QUADS);
- glTexCoord2d(0.0,0.0); glVertex2f(-1, -1);
- glTexCoord2d(1.0,0.0); glVertex2f(1, -1);
- glTexCoord2d(1.0,1.0); glVertex2f(1, 1);
- glTexCoord2d(0.0,1.0); glVertex2f(-1, 1);
- glEnd();
- glDisable(GL_TEXTURE_2D);
-}
-
-GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){
-
- // Create the shaders
- GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
- GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
-
- // Read the Vertex Shader code from the file
- std::string VertexShaderCode;
- std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
- if(VertexShaderStream.is_open()){
- std::string Line = "";
- while(getline(VertexShaderStream, Line))
- VertexShaderCode += "\n" + Line;
- VertexShaderStream.close();
- }else{
- printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
- getchar();
- return 0;
- }
-
- // Read the Fragment Shader code from the file
- std::string FragmentShaderCode;
- std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
- if(FragmentShaderStream.is_open()){
- std::string Line = "";
- while(getline(FragmentShaderStream, Line))
- FragmentShaderCode += "\n" + Line;
- FragmentShaderStream.close();
- }
-
- GLint Result = GL_FALSE;
- int InfoLogLength;
-
-
- // Compile Vertex Shader
- printf("Compiling shader : %s\n", vertex_file_path);
- char const * VertexSourcePointer = VertexShaderCode.c_str();
- glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
- glCompileShader(VertexShaderID);
-
- // Check Vertex Shader
- glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
- glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
- if ( InfoLogLength > 0 ){
- std::vector VertexShaderErrorMessage(InfoLogLength+1);
- glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
- printf("%s\n", &VertexShaderErrorMessage[0]);
- }
-
-
-
- // Compile Fragment Shader
- printf("Compiling shader : %s\n", fragment_file_path);
- char const * FragmentSourcePointer = FragmentShaderCode.c_str();
- glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
- glCompileShader(FragmentShaderID);
-
- // Check Fragment Shader
- glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
- glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
- if ( InfoLogLength > 0 ){
- std::vector FragmentShaderErrorMessage(InfoLogLength+1);
- glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
- printf("%s\n", &FragmentShaderErrorMessage[0]);
- }
-
-
-
- // Link the program
- printf("Linking program\n");
- GLuint ProgramID = glCreateProgram();
- glAttachShader(ProgramID, VertexShaderID);
- glAttachShader(ProgramID, FragmentShaderID);
- glLinkProgram(ProgramID);
-
- // Check the program
- glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
- glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
- if ( InfoLogLength > 0 ){
- std::vector ProgramErrorMessage(InfoLogLength+1);
- glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
- printf("%s\n", &ProgramErrorMessage[0]);
- }
-
-
- glDetachShader(ProgramID, VertexShaderID);
- glDetachShader(ProgramID, FragmentShaderID);
-
- glDeleteShader(VertexShaderID);
- glDeleteShader(FragmentShaderID);
-
- return ProgramID;
-}
-
-
+#include "loaders.h"
int main(int argc, char* args[]) {
GLFWwindow* window;
- GLuint tex_jpe;
+ GLuint texFG, texBG;
int textw, texth;
+ int textw2, texth2;
/* Initialize the library */
@@ -194,25 +37,21 @@ int main(int argc, char* args[]) {
GLenum error = glGetError();
if (error != GL_NO_ERROR)
{
- std::cout << "OpenGL Error: " << error << std::endl;
+ printf("OpenGL Error: %d",error);
}
GLenum glewinit = glewInit();
if (glewinit != GLEW_OK) {
- std::cout << "Glew not okay! " << glewinit;
+ printf("Glew not okay! %d",glewinit);
return 1;
}
/* SDL */
- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ if (InitLoaders() < 0) {
printf("SDL Error");
return 1;
}
// INIT
-
- GLuint VertexArrayID;
- glGenVertexArrays(1, &VertexArrayID);
- glBindVertexArray(VertexArrayID);
// An array of 3 vectors which represents 3 vertices
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f, // (bottom - left ) TRIANGLE 1
@@ -245,22 +84,66 @@ 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);
- tex_jpe = LoadTexture("../img/tests/test.png",&textw,&texth);
- glfwSetWindowSize (window, textw, texth);
+
+
+ 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're going to render to
+ GLuint renderedTexture;
+ glGenTextures(1, &renderedTexture);
+ glBindTexture(GL_TEXTURE_2D, renderedTexture);
+
+ glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, textw, texth, 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+ // Set "renderedTexture" as our colour attachement #2
+ glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, renderedTexture, 0);
+ // Set the list of draw buffers.
+ GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT2};
+ glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers
+
+ // Always check that our framebuffer is ok
+ if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+ return false;
+
+
GLuint programID = LoadShaders("trimap.vertexshader", "trimap.fragmentshader");
- GLint textureLocation = glGetUniformLocation(programID, "myTextureSampler");
- GLint widthLocation = glGetUniformLocation(programID, "pixWidth");
- GLint heigthLocation = glGetUniformLocation(programID, "pixHeight");
+ GLuint programRefineID = LoadShaders("refinement.vertexshader", "refinement.fragmentshader");
+ GLint textureLoc1 = glGetUniformLocation(programID, "myTextureSampler");
+ GLint widthLoc = glGetUniformLocation(programID, "pixWidth");
+ GLint heigthLoc = glGetUniformLocation(programID, "pixHeight");
+
+
+ GLint textureLocTri = glGetUniformLocation(programRefineID, "trimap");
+ GLint textureLocFore = glGetUniformLocation(programRefineID, "foreground");
+ GLint textureLocBack = glGetUniformLocation(programRefineID, "background");
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, texFG);
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, texBG);
+ glActiveTexture(GL_TEXTURE2);
+ glBindTexture(GL_TEXTURE_2D, renderedTexture);
+
printf("Shader program ID: %d\n", programID);
- printf("textureLocation: %d\n", textureLocation);
- printf("widthLocation: %d\n", widthLocation);
- printf("heigthLocation: %d\n", heigthLocation);
+ printf("textureLoc1: %d\n", textureLoc1);
+ printf("textureLocTri: %d\n", textureLocTri);
+ //printf("textureLocFore: %d\n", textureLocFore);
+ printf("widthLoc: %d\n", widthLoc);
+ printf("heigthLoc: %d\n", heigthLoc);
printf("Width: %f\n", 1.0f/textw);
printf("Height: %f\n", 1.0f/texth);
@@ -270,11 +153,58 @@ int main(int argc, char* args[]) {
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window)) {
/* Render here */
+ // Render to our framebuffer
+ glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
+ //glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ //glViewport(0,0,textw,texth); // Render on the whole framebuffer, complete from the lower left corner to the upper right
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programID);
- glUniform1f(widthLocation, 1.0f/textw);
- glUniform1f(heigthLocation, 1.0f/texth);
+ glUniform1f(widthLoc, 1.0f/textw);
+ glUniform1f(heigthLoc, 1.0f/texth);
+ glUniform1i(textureLoc1, 0);
+
+ // 1rst attribute buffer : vertices
+ glEnableVertexAttribArray(0);
+ glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
+ glVertexAttribPointer(
+ 0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
+ 3, // size
+ GL_FLOAT, // type
+ GL_FALSE, // normalized?
+ 0, // stride
+ (void*)0 // array buffer offset
+ );
+ // 2nd attribute buffer : colors
+ 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
+ );
+
+
+ // Draw the triangle !
+ glDrawArrays(GL_TRIANGLES, 0, 2*3); // 2*3 indices starting at 0 -> 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(textureLocBack, 1);
+ glUniform1i(textureLocFore, 0);
+
+
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
diff --git a/opengl-test-two/opengl-test-two.cbp b/opengl-test-two/opengl-test-two.cbp
index 10a334b..9c101ae 100644
--- a/opengl-test-two/opengl-test-two.cbp
+++ b/opengl-test-two/opengl-test-two.cbp
@@ -13,6 +13,7 @@
+
@@ -22,6 +23,7 @@
+
@@ -44,7 +46,9 @@
+
+
diff --git a/opengl-test-two/opengl-test-two.depend b/opengl-test-two/opengl-test-two.depend
index ee465f0..9e3caa7 100644
--- a/opengl-test-two/opengl-test-two.depend
+++ b/opengl-test-two/opengl-test-two.depend
@@ -2,16 +2,13 @@
1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp
-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
@@ -368,3 +365,387 @@
+1473412967 source:d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\main.cpp
+
+
+
+
+
+
+ "loaders.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\gl\glew.h
+
+
+
+
+
+
+
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl.h
+ "SDL_main.h"
+ "SDL_stdinc.h"
+ "SDL_assert.h"
+ "SDL_atomic.h"
+ "SDL_audio.h"
+ "SDL_clipboard.h"
+ "SDL_cpuinfo.h"
+ "SDL_endian.h"
+ "SDL_error.h"
+ "SDL_events.h"
+ "SDL_filesystem.h"
+ "SDL_joystick.h"
+ "SDL_gamecontroller.h"
+ "SDL_haptic.h"
+ "SDL_hints.h"
+ "SDL_loadso.h"
+ "SDL_log.h"
+ "SDL_messagebox.h"
+ "SDL_mutex.h"
+ "SDL_power.h"
+ "SDL_render.h"
+ "SDL_rwops.h"
+ "SDL_system.h"
+ "SDL_thread.h"
+ "SDL_timer.h"
+ "SDL_version.h"
+ "SDL_video.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_main.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_stdinc.h
+ "SDL_config.h"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ "begin_code.h"
+
+
+
+
+
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_config.h
+ "SDL_platform.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_platform.h
+ "AvailabilityMacros.h"
+ "TargetConditionals.h"
+
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\begin_code.h
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\close_code.h
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_assert.h
+ "SDL_config.h"
+ "begin_code.h"
+
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_atomic.h
+ "SDL_stdinc.h"
+ "SDL_platform.h"
+ "begin_code.h"
+
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_audio.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_endian.h"
+ "SDL_mutex.h"
+ "SDL_thread.h"
+ "SDL_rwops.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_error.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_endian.h
+ "SDL_stdinc.h"
+
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_mutex.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_thread.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_atomic.h"
+ "SDL_mutex.h"
+ "begin_code.h"
+
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_rwops.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_clipboard.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_cpuinfo.h
+ "SDL_stdinc.h"
+
+
+
+
+
+
+
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_events.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_video.h"
+ "SDL_keyboard.h"
+ "SDL_mouse.h"
+ "SDL_joystick.h"
+ "SDL_gamecontroller.h"
+ "SDL_quit.h"
+ "SDL_gesture.h"
+ "SDL_touch.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_video.h
+ "SDL_stdinc.h"
+ "SDL_pixels.h"
+ "SDL_rect.h"
+ "SDL_surface.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_pixels.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_rect.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_pixels.h"
+ "SDL_rwops.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_surface.h
+ "SDL_stdinc.h"
+ "SDL_pixels.h"
+ "SDL_rect.h"
+ "SDL_blendmode.h"
+ "SDL_rwops.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_blendmode.h
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_keyboard.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_keycode.h"
+ "SDL_video.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_keycode.h
+ "SDL_stdinc.h"
+ "SDL_scancode.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_scancode.h
+ "SDL_stdinc.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_mouse.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_video.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_joystick.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_gamecontroller.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_rwops.h"
+ "SDL_joystick.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_quit.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_gesture.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_video.h"
+ "SDL_touch.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_touch.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_video.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_filesystem.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_haptic.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "SDL_joystick.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_hints.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_loadso.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_log.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_messagebox.h
+ "SDL_stdinc.h"
+ "SDL_video.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_power.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_render.h
+ "SDL_stdinc.h"
+ "SDL_rect.h"
+ "SDL_video.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_system.h
+ "SDL_stdinc.h"
+ "SDL_keyboard.h"
+ "SDL_render.h"
+ "SDL_video.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_timer.h
+ "SDL_stdinc.h"
+ "SDL_error.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_version.h
+ "SDL_stdinc.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_image.h
+ "SDL.h"
+ "SDL_version.h"
+ "begin_code.h"
+ "close_code.h"
+
+1473412852 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\loaders.h
+
+
+1473412967 source:d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\src\loaders.cpp
+
+
+
+
+ "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..09a7857
--- /dev/null
+++ b/opengl-test-two/refinement.fragmentshader
@@ -0,0 +1,55 @@
+#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;
+uniform sampler2D background;
+
+
+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;
+}
+
+vec3 getBackColor(vec2 uvCoord) {
+ return texture(background, 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;
+ } else if (status==IS_BACKGROUND) {
+ color = getBackColor(UV).rgb;
+ } else {
+ // render undefined area
+ }
+}
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/src/loaders.cpp b/opengl-test-two/src/loaders.cpp
new file mode 100644
index 0000000..7faf808
--- /dev/null
+++ b/opengl-test-two/src/loaders.cpp
@@ -0,0 +1,146 @@
+#include
+#include
+#include
+#include
+#include "loaders.h"
+
+int InitLoaders(){
+ return SDL_Init(SDL_INIT_VIDEO);
+}
+
+GLuint LoadTexture(char *filename,int *textw,int *texth) {
+ SDL_Surface *surface;
+ GLuint textureid;
+ int mode;
+ surface = IMG_Load(filename);
+ // Or if you don't use SDL_image you can use SDL_LoadBMP here instead:
+ // surface = SDL_LoadBMP(filename);
+
+ // could not load filename
+ if (!surface) {
+ return 0;
+ }
+
+ // work out what format to tell glTexImage2D to use...
+ if (surface->format->BytesPerPixel == 3) { // RGB 24bit
+ mode = GL_RGB;
+
+ } else if (surface->format->BytesPerPixel == 4) { // RGBA 32bit
+ mode = GL_RGBA;
+ } else {
+ SDL_FreeSurface(surface);
+ return 0;
+ }
+
+ *textw=surface->w;
+ *texth=surface->h;
+ // create one texture name
+ glGenTextures(1, &textureid);
+ // tell opengl to use the generated texture name
+ glBindTexture(GL_TEXTURE_2D, textureid);
+ // this reads from the sdl surface and puts it into an opengl texture
+ glTexImage2D(GL_TEXTURE_2D, 0, mode, surface->w, surface->h, 0, mode, GL_UNSIGNED_BYTE, surface->pixels);
+ // these affect how this texture is drawn later on...glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ // clean up
+ SDL_FreeSurface(surface);
+ return textureid;
+
+}
+
+GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){
+
+ // Create the shaders
+ GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
+ GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
+
+ // Read the Vertex Shader code from the file
+ std::string VertexShaderCode;
+ std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
+ if(VertexShaderStream.is_open()){
+ std::string Line = "";
+ while(getline(VertexShaderStream, Line))
+ VertexShaderCode += "\n" + Line;
+ VertexShaderStream.close();
+ }else{
+ printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
+ getchar();
+ return 0;
+ }
+
+ // Read the Fragment Shader code from the file
+ std::string FragmentShaderCode;
+ std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
+ if(FragmentShaderStream.is_open()){
+ std::string Line = "";
+ while(getline(FragmentShaderStream, Line))
+ FragmentShaderCode += "\n" + Line;
+ FragmentShaderStream.close();
+ }
+
+ GLint Result = GL_FALSE;
+ int InfoLogLength;
+
+
+ // Compile Vertex Shader
+ printf("Compiling shader : %s\n", vertex_file_path);
+ char const * VertexSourcePointer = VertexShaderCode.c_str();
+ glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
+ glCompileShader(VertexShaderID);
+
+ // Check Vertex Shader
+ glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
+ glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
+ if ( InfoLogLength > 0 ){
+ std::vector VertexShaderErrorMessage(InfoLogLength+1);
+ glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
+ printf("%s\n", &VertexShaderErrorMessage[0]);
+ }
+
+
+
+ // Compile Fragment Shader
+ printf("Compiling shader : %s\n", fragment_file_path);
+ char const * FragmentSourcePointer = FragmentShaderCode.c_str();
+ glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
+ glCompileShader(FragmentShaderID);
+
+ // Check Fragment Shader
+ glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
+ glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
+ if ( InfoLogLength > 0 ){
+ std::vector FragmentShaderErrorMessage(InfoLogLength+1);
+ glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
+ printf("%s\n", &FragmentShaderErrorMessage[0]);
+ }
+
+
+
+ // Link the program
+ printf("Linking program\n");
+ GLuint ProgramID = glCreateProgram();
+ glAttachShader(ProgramID, VertexShaderID);
+ glAttachShader(ProgramID, FragmentShaderID);
+ glLinkProgram(ProgramID);
+
+ // Check the program
+ glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
+ glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
+ if ( InfoLogLength > 0 ){
+ std::vector ProgramErrorMessage(InfoLogLength+1);
+ glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
+ printf("%s\n", &ProgramErrorMessage[0]);
+ }
+
+
+ glDetachShader(ProgramID, VertexShaderID);
+ glDetachShader(ProgramID, FragmentShaderID);
+
+ glDeleteShader(VertexShaderID);
+ glDeleteShader(FragmentShaderID);
+
+ return ProgramID;
+}
diff --git a/opengl-test-two/trimap.fragmentshader b/opengl-test-two/trimap.fragmentshader
index 4811416..75da72f 100644
--- a/opengl-test-two/trimap.fragmentshader
+++ b/opengl-test-two/trimap.fragmentshader
@@ -4,7 +4,8 @@
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;
@@ -20,15 +21,22 @@ 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;
}
bool isBackground(vec3 c) {
- // 49,206, 11
+ /*// 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)))
+ all(greaterThanEqual(c, vec3(47.0f/255.0f, 204.0f/255.0f, 9.0f/255.0f)))*/
+ // 0, 255, 0
+ if (all( lessThanEqual(c, greenValue+difference)) &&
+ all(greaterThanEqual(c, greenValue-difference))
) {
return true;
} else {
@@ -39,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 {
@@ -66,10 +74,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;