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 index 8603c2d..cba839f 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 d884579..1250b2c 100644 --- a/opengl-test-two/main.cpp +++ b/opengl-test-two/main.cpp @@ -54,22 +54,6 @@ GLuint LoadTexture(char *filename,int *textw,int *texth) { } -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 @@ -168,8 +152,9 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path int main(int argc, char* args[]) { GLFWwindow* window; - GLuint tex_jpe; + GLuint tex1, tex2; int textw, texth; + int textw2, texth2; /* Initialize the library */ @@ -209,10 +194,6 @@ int main(int argc, char* args[]) { } // 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 @@ -247,20 +228,31 @@ int main(int argc, char* args[]) { - tex_jpe = LoadTexture("../img/tests/test.png",&textw,&texth); - glfwSetWindowSize (window, textw, texth); + tex1 = LoadTexture("../img/tests/flieger.jpg",&textw,&texth); + printf("Tex1: %d", tex1); + tex2 = LoadTexture("../img/tests/flieger2.jpg",&textw2,&texth2); + printf("Tex2: %d", tex2); + glfwSetWindowSize(window, textw, texth); glViewport(0, 0, textw, texth); glfwSetWindowSizeLimits(window, textw, texth, textw, texth); GLuint programID = LoadShaders("trimap.vertexshader", "trimap.fragmentshader"); - GLint textureLocation = glGetUniformLocation(programID, "myTextureSampler"); - GLint widthLocation = glGetUniformLocation(programID, "pixWidth"); - GLint heigthLocation = glGetUniformLocation(programID, "pixHeight"); + GLint textureLoc1 = glGetUniformLocation(programID, "myTextureSampler"); + GLint textureLoc2 = glGetUniformLocation(programID, "myTextureSampler2"); + GLint widthLoc = glGetUniformLocation(programID, "pixWidth"); + GLint heigthLoc = glGetUniformLocation(programID, "pixHeight"); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, tex1); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, tex2); + 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("textureLoc2: %d\n", textureLoc2); + printf("widthLoc: %d\n", widthLoc); + printf("heigthLoc: %d\n", heigthLoc); printf("Width: %f\n", 1.0f/textw); printf("Height: %f\n", 1.0f/texth); @@ -273,8 +265,11 @@ 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); + glUniform1f(widthLoc, 1.0f/textw); + glUniform1f(heigthLoc, 1.0f/texth); + glUniform1i(textureLoc1, 0); + glUniform1i(textureLoc2, 1); + // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); diff --git a/opengl-test-two/trimap.fragmentshader b/opengl-test-two/trimap.fragmentshader index 4811416..eb87cfa 100644 --- a/opengl-test-two/trimap.fragmentshader +++ b/opengl-test-two/trimap.fragmentshader @@ -8,6 +8,7 @@ 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; @@ -22,13 +23,16 @@ int UNSET = -1; vec3 getColor(vec2 uvCoord) { - return texture(myTextureSampler, uvCoord).rgb; + return texture(myTextureSampler2, 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, vec3(2.0f/255.0f, 255.0f/255.0f, 2.0f/255.0f))) && + all(greaterThanEqual(c, vec3(0.0f/255.0f, 253.0f/255.0f, 0.0f/255.0f))) ) { return true; } else {