3 Commits
master ... mac

Author SHA1 Message Date
Leander
9afb9191ff New profile for mac created 2016-09-09 10:07:37 +02:00
Leander
83a9f7df12 Forgot to commit 2016-09-08 11:47:48 +02:00
Leander
ef55f75b33 Finally compiling on mac 2016-09-08 11:40:16 +02:00
26 changed files with 704 additions and 1060 deletions

6
.gitignore vendored
View File

@@ -24,9 +24,9 @@
#*.lib
# Executables
*.exe
*.out
*.app
#*.exe
#*.out
#*.app
# ---> C
# Object files

View File

@@ -1,121 +0,0 @@
<svg viewBox="19 98 883 423" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill: rgb(116, 237, 104); stroke-width: 2; stroke: rgb(0, 0, 0);">
<rect x="100" y="100" width="80" height="60"/>
<rect x="160" y="220" width="100" height="80"/>
<rect x="300" y="217" width="120" height="86"/>
<rect x="300" y="440" width="100" height="80"/>
<rect x="460" y="220" width="120" height="80"/>
<rect x="480" y="360" width="80" height="60"/>
<rect x="619.1" y="220" width="121.8" height="80"/>
<rect x="780" y="220" width="120" height="80"/>
</g>
<g style="fill: none; stroke-width: 2; stroke: rgb(0, 0, 0);">
<polyline points="400,460 520,460 520,431"/>
<polyline points="411,500 840,500 840,311"/>
<polyline points="449,280 439,280 439,460 460,460"/>
<polyline points="89,130 60,130 60,220 40,220"/>
</g>
<g style="fill: none; stroke-width: 2; stroke: rgb(0, 0, 0);">
<line x1="260" y1="260" x2="289" y2="260"/>
<line x1="580" y1="260" x2="608.1" y2="260"/>
<line x1="740.9" y1="260" x2="769" y2="260"/>
<line x1="520" y1="360" x2="520" y2="311"/>
<line x1="420" y1="260" x2="449" y2="260"/>
<line x1="149" y1="260" x2="20" y2="260"/>
<line x1="140" y1="160" x2="140" y2="249"/>
<line x1="289" y1="480" x2="71" y2="480"/>
<line x1="120" y1="160" x2="120" y2="469"/>
<line x1="60" y1="260" x2="60" y2="480"/>
<line x1="20" y1="220" x2="49" y2="220"/>
</g>
<g style="fill: rgb(0, 0, 0); stroke-width: 2; stroke: rgb(0, 0, 0);">
<polygon points="289,265 299,260 289,255"/>
<polygon points="608.1,265 618.1,260 608.1,255"/>
<polygon points="769,265 779,260 769,255"/>
<polygon points="525,431 520,421 515,431"/>
<polygon points="525,311 520,301 515,311"/>
<polygon points="411,495 401,500 411,505"/>
<polygon points="845,311 840,301 835,311"/>
<polygon points="449,285 459,280 449,275"/>
<polygon points="449,265 459,260 449,255"/>
<polygon points="149,265 159,260 149,255"/>
<polygon points="135,249 140,259 145,249"/>
<polygon points="289,485 299,480 289,475"/>
<polygon points="71,475 61,480 71,485"/>
<polygon points="115,469 120,479 125,469"/>
<polygon points="40,265 50,260 40,255"/>
<polygon points="40,225 50,220 40,215"/>
<polygon points="89,135 99,130 89,125"/>
</g>
<switch>
<g systemLanguage="es" font-size="12.8" style="fill: rgb(0, 0, 0); text-anchor: middle; font-family: sans-serif; font-style: normal; font-weight: 700;">
<text>
<tspan x="140" y="125.9">Lista</tspan>
<tspan x="140" y="141.9">Display</tspan>
</text>
<text>
<tspan x="210" y="263.9">Evaluación</tspan>
</text>
<text>
<tspan x="360" y="239.9">Operaciones</tspan>
<tspan x="360" y="255.9">por vértices</tspan>
<tspan x="360" y="271.9">Ensamblado</tspan>
<tspan x="360" y="287.9">de primitivas</tspan>
</text>
<text>
<tspan x="350" y="475.9">Operaciones</tspan>
<tspan x="350" y="491.9">de píxeles</tspan>
</text>
<text>
<tspan x="520" y="263.9">Rasterización</tspan>
</text>
<text>
<tspan x="520" y="378.9">Memoria</tspan>
<tspan x="520" y="394.9">de</tspan>
<tspan x="520" y="410.9">Texturas</tspan>
</text>
<text>
<tspan x="680" y="255.9">Operaciones</tspan>
<tspan x="680" y="271.9">por fragmentos</tspan>
</text>
<text>
<tspan x="840" y="255.9">Frame</tspan>
<tspan x="840" y="271.9">Buffer</tspan>
</text>
</g>
<g font-size="12.8" style="fill: rgb(0, 0, 0); text-anchor: middle; font-family: sans-serif; font-style: normal; font-weight: 700;">
<text>
<tspan x="140" y="125.9">Display</tspan>
<tspan x="140" y="141.9">List</tspan>
</text>
<text>
<tspan x="210" y="263.9">Evaluator</tspan>
</text>
<text>
<tspan x="360" y="239.9">Per-Vertex</tspan>
<tspan x="360" y="255.9">Operations</tspan>
<tspan x="360" y="271.9">Primitive</tspan>
<tspan x="360" y="287.9">Assembly</tspan>
</text>
<text>
<tspan x="350" y="475.9">Pixel</tspan>
<tspan x="350" y="491.9">Operations</tspan>
</text>
<text>
<tspan x="520" y="263.9">Rasterization</tspan>
</text>
<text>
<tspan x="520" y="385.9">Texture</tspan>
<tspan x="520" y="401.9">Memory</tspan>
</text>
<text>
<tspan x="680" y="255.9">Per-Fragment</tspan>
<tspan x="680" y="271.9">Operations</tspan>
</text>
<text>
<tspan x="840" y="255.9">Frame</tspan>
<tspan x="840" y="271.9">Buffer</tspan>
</text>
</g>
</switch>
</svg>

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 768 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 876 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -1,10 +0,0 @@
#ifndef LOADERS_H
#define LOADERS_H
#define GLEW_STATIC
#include <GL/glew.h>
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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,56 @@
class Libiconv < Formula
desc "Conversion library"
homepage "https://www.gnu.org/software/libiconv/"
url "https://ftpmirror.gnu.org/libiconv/libiconv-1.14.tar.gz"
mirror "https://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz"
sha256 "72b24ded17d687193c3366d0ebe7cde1e6b18f0df8c55438ac95be39e8a30613"
bottle do
sha256 "64d8a9383ba42ba3e41422bb8548ebc8f296f67fdda6e6d6a324f990b03c6db0" => :el_capitan
sha256 "a0d9ff36269bc908fde4a039d2083152202055a2e053b6582ad2c9063c85ebc2" => :yosemite
sha256 "456a816a94427c963fa3cb90257830aa33268f22443cf5a8a4cf1be3e3ed3bb9" => :mavericks
end
keg_only :provided_by_osx
option :universal
patch do
url "https://raw.githubusercontent.com/Homebrew/patches/9be2793af/libiconv/patch-Makefile.devel"
sha256 "ad9b6da1a82fc4de27d6f7086a3382993a0b16153bc8e8a23d7b5f9334ca0a42"
end
patch do
url "https://raw.githubusercontent.com/Homebrew/patches/9be2793af/libiconv/patch-utf8mac.diff"
sha256 "e8128732f22f63b5c656659786d2cf76f1450008f36bcf541285268c66cabeab"
end
patch :DATA
def install
ENV.universal_binary if build.universal?
ENV.j1
system "./configure", "--disable-debug",
"--disable-dependency-tracking",
"--prefix=#{prefix}",
"--enable-extra-encodings"
system "make", "-f", "Makefile.devel", "CFLAGS=#{ENV.cflags}", "CC=#{ENV.cc}"
system "make", "install"
end
end
__END__
diff --git a/lib/flags.h b/lib/flags.h
index d7cda21..4cabcac 100644
--- a/lib/flags.h
+++ b/lib/flags.h
@@ -14,6 +14,7 @@
#define ei_ascii_oflags (0)
#define ei_utf8_oflags (HAVE_ACCENTS | HAVE_QUOTATION_MARKS | HAVE_HANGUL_JAMO)
+#define ei_utf8mac_oflags (HAVE_ACCENTS | HAVE_QUOTATION_MARKS | HAVE_HANGUL_JAMO)
#define ei_ucs2_oflags (HAVE_ACCENTS | HAVE_QUOTATION_MARKS | HAVE_HANGUL_JAMO)
#define ei_ucs2be_oflags (HAVE_ACCENTS | HAVE_QUOTATION_MARKS | HAVE_HANGUL_JAMO)
#define ei_ucs2le_oflags (HAVE_ACCENTS | HAVE_QUOTATION_MARKS | HAVE_HANGUL_JAMO)

View File

@@ -4,15 +4,177 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <stdexcept>
#include "loaders.h"
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_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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<char> 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<char> 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<char> 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;
}
int main(int argc, char* args[]) {
GLFWwindow* window;
GLuint texFG, texBG;
GLuint tex_jpe;
GLuint tex_jpg;
GLuint tex_gif;
GLuint tex_png;
GLuint tex_bmp;
int textw, texth;
int textw2, texth2;
int timer = 0;
/* Initialize the library */
@@ -23,11 +185,10 @@ int main(int argc, char* args[]) {
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;
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
@@ -37,203 +198,48 @@ int main(int argc, char* args[]) {
GLenum error = glGetError();
if (error != GL_NO_ERROR)
{
printf("OpenGL Error: %d",error);
std::cout << "OpenGL Error: " << error << std::endl;
}
GLenum glewinit = glewInit();
if (glewinit != GLEW_OK) {
printf("Glew not okay! %d",glewinit);
std::cout << "Glew not okay! " << glewinit;
return 1;
}
/* SDL */
if (InitLoaders() < 0) {
if (SDL_Init(SDL_INIT_VIDEO) < 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);
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;
tex_jpe=LoadTexture("../img/tests/test.jpeg",&textw,&texth);
tex_jpg=LoadTexture("../img/tests/test.jpg",&textw,&texth);
tex_png=LoadTexture("../img/tests/test.png",&textw,&texth);
tex_bmp=LoadTexture("../img/tests/test.bmp",&textw,&texth);
GLuint programID = LoadShaders("trimap.vertexshader", "trimap.fragmentshader");
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("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);
printf("%d", programID);
// INIT END
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window)) {
timer += 1;
if (timer==800)
timer = 0;
/* 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(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);
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
if (timer<200)
DrawTexture(50,50,tex_jpe,textw,texth);
else if (timer<400)
DrawTexture(50,50,tex_jpg,textw,texth);
else if (timer<600)
DrawTexture(50,50,tex_png,textw,texth);
else
DrawTexture(50,50,tex_bmp,textw,texth);
// RENDER END
/* Swap front and back buffers */

View File

@@ -13,7 +13,6 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="include" />
</Compiler>
</Target>
<Target title="Release">
@@ -23,12 +22,38 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
<Add directory="include" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
<Target title="Debug Mac">
<Option platforms="Mac;" />
<Option output="bin/Debug/opengl-test-two" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
<Linker>
<Add option="-framework AudioUnit" />
<Add option="-framework Carbon" />
<Add option="-framework Cocoa" />
<Add option="-framework CoreAudio" />
<Add option="-framework CoreFoundation" />
<Add option="-framework CoreVideo" />
<Add option="-framework ForceFeedback" />
<Add option="-framework IOKit" />
<Add option="-framework OpenGL" />
<Add library="GLEW" />
<Add library="glfw3" />
<Add library="iconv" />
<Add library="SDL2main" />
<Add library="SDL2" />
<Add library="SDL2_image" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
@@ -36,21 +61,24 @@
<Add directory="include" />
</Compiler>
<Linker>
<Add library="glew32" />
<Add option="-framework AudioUnit" />
<Add option="-framework Carbon" />
<Add option="-framework Cocoa" />
<Add option="-framework CoreAudio" />
<Add option="-framework CoreFoundation" />
<Add option="-framework CoreVideo" />
<Add option="-framework ForceFeedback" />
<Add option="-framework IOKit" />
<Add option="-framework OpenGL" />
<Add library="GLEW" />
<Add library="glfw3" />
<Add library="gdi32" />
<Add library="opengl32" />
<Add library="mingw32" />
<Add library="iconv" />
<Add library="SDL2main" />
<Add library="SDL2" />
<Add library="SDL2_image" />
<Add directory="lib" />
</Linker>
<Unit filename="include/loaders.h" />
<Unit filename="main.cpp" />
<Unit filename="refinement.fragmentshader" />
<Unit filename="refinement.vertexshader" />
<Unit filename="src/loaders.cpp" />
<Unit filename="trimap.fragmentshader" />
<Unit filename="trimap.vertexshader" />
<Extensions>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
glew32 -> GLEW

View File

@@ -1,55 +0,0 @@
#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
}
}

View File

@@ -1,17 +0,0 @@
#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;
}

View File

@@ -1,146 +0,0 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <fstream>
#include <vector>
#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<char> 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<char> 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<char> 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;
}

View File

@@ -1,83 +1,8 @@
#version 330 core
// Interpolated values from the vertex shaders
in vec2 UV;
// Ouput data
layout(location = 0) out vec3 color;
//out vec3 color;
// Values that stay constant for the whole mesh.
uniform sampler2D myTextureSampler;
// Relative width/height of a pixel
uniform float pixWidth;
uniform float pixHeight;
// Pixel state
int IS_BACKGROUND = 0;
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
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)))*/
// 0, 255, 0
if (all( lessThanEqual(c, greenValue+difference)) &&
all(greaterThanEqual(c, greenValue-difference))
) {
return true;
} else {
return false;
}
}
out vec4 color;
void main(){
int status = UNSET;
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 {
status = IS_FOREGROUND;
}
} else { // other pixels
if (isBackground(getColor(UV+vec2(pixWidth*w, pixHeight*h)))) {
if (status != IS_BACKGROUND) {
status = IS_UNDEFINED;
w=100000;
break;
}
} else {
if (status != IS_FOREGROUND) {
status = IS_UNDEFINED;
w=100000;
break;
}
}
}
}
}
if (status == IS_BACKGROUND) {
color = vec3(0.0f);
} else if (status == IS_FOREGROUND) {
color = vec3(1.0f);
} else {
color = vec3(0.5f);
}
color = vec3(0.5,0,0);
}

View File

@@ -1,17 +1,8 @@
#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.x, -1*vertexPosition_modelspace.y, vertexPosition_modelspace.z, 1);
// UV of the vertex. No special space for this one.
UV = vertexUV;
gl_Position.xyz = vertexPosition_modelspace;
gl_Position.w = 1.0;
}