// http://stackoverflow.com/questions/6005076/building-glew-on-windows-with-mingw #define GLEW_STATIC #include #include #include #include #include #include "loaders.h" int main(int argc, char* args[]) { GLFWwindow* window; GLuint tex1, tex2; int textw, texth; int textw2, texth2; /* Initialize the library */ /* GLFW */ if (!glfwInit()) { printf("GLFW Error"); return 1; } /* Create a windowed mode window and its OpenGL context */ glfwSetWindowSizeLimits(window, 640, 480, 640, 480); window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL); if (!window) { glfwTerminate(); return 1; } /* Make the window's context current */ glfwMakeContextCurrent(window); /* GLEW */ glewExperimental = GL_FALSE; GLenum error = glGetError(); if (error != GL_NO_ERROR) { printf("OpenGL Error: %d",error); } GLenum glewinit = glewInit(); if (glewinit != GLEW_OK) { printf("Glew not okay! %d",glewinit); return 1; } /* SDL */ if (InitLoaders() < 0) { printf("SDL Error"); return 1; } // INIT // 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 1.0f, -1.0f, 0.0f, // (bottom - right) -1.0f, 1.0f, 0.0f, // (top - left ) 1.0f, 1.0f, 0.0f, // (top - right) TRIANGLE 2 1.0f, -1.0f, 0.0f, // (bottom - right) -1.0f, 1.0f, 0.0f, // (top - left ) }; // One color for each vertex. They were generated randomly. static const GLfloat g_uv_buffer_data[] = { 0.0f, 1.0f-0.0f, // (bottom - left ) TRIANGLE 1 1.0f, 1.0f-0.0f, // (bottom - right) 0.0f, 1.0f-1.0f, // (top - left ) 1.0f, 1.0f-1.0f, // (top - right) TRIANGLE 2 1.0f, 1.0f-0.0f, // (bottom - right) 0.0f, 1.0f-1.0f, // (top - left ) }; // Identify our vertex buffer GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); // Identify our color buffer GLuint colorbuffer; glGenBuffers(1, &colorbuffer); 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\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); 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 END /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); } glfwTerminate(); return 0; }