24 Commits
mac ... opengl

Author SHA1 Message Date
Caesar2011
e309f5369e Added better test image; improved parameter 2016-12-07 23:20:58 +01:00
Joshua
5129eb207b squared distance function 2016-09-23 14:31:05 +02:00
Joshua
22f7af4cf7 Merged branch opengl into opengl 2016-09-23 14:29:36 +02:00
Caesar2011
82d1cb97a1 Loop counter depending on time 2016-09-23 14:19:11 +02:00
Joshua
c538021666 updated refinement shader 2016-09-23 13:27:34 +02:00
Joshua
b749254426 Refinementshader complete; Linear alpha value by distance 2016-09-23 12:35:31 +02:00
Joshua
ceb538aafe First version of fragment shader 2016-09-19 09:59:39 +02:00
Caesar2011
34eca0d0af Removing debug text output 2016-09-14 18:19:35 +02:00
Caesar2011
9cb2b0f8e8 Clean up code; adding comments 2016-09-14 18:18:01 +02:00
Caesar2011
449060a463 Animated pictures; FPS counter 2016-09-13 16:11:01 +02:00
Caesar2011
f99b8dab83 CPB updated 2016-09-12 19:18:54 +02:00
Caesar2011
afb288cbf3 Added background to refinement shader 2016-09-12 19:13:19 +02:00
Caesar2011
a1c76d1e7f Framebuffer working; Trimap renders to FB; Refinem. use Trimap to Screen 2016-09-12 18:18:32 +02:00
Benjamin Petsch
7588c0d27b added overview of OpenGL functionality 2016-09-09 17:08:40 +02:00
Benjamin Petsch
1b03cfe32b loader functions moved to external file 2016-09-09 11:55:56 +02:00
Caesar2011
4f347a6ef5 Loading of multiple textures 2016-09-07 13:06:48 +02:00
Caesar2011
364ed31d8e Clean up project 2016-09-06 08:20:12 +02:00
Caesar2011
b1c6dcfecb Merged trimap into opengl 2016-09-05 22:21:21 +02:00
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
Caesar2011
aed54bd694 Coloring triangles with texture 2016-09-05 19:45:14 +02:00
Caesar2011
433983e4ff Colored triangles with VAO and VBO 2016-09-05 18:38:53 +02:00
Caesar2011
866fabdf45 Preparing to add texture to quad 2016-09-05 17:49:15 +02:00
38 changed files with 1346 additions and 251 deletions

6
.gitignore vendored
View File

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

View File

@@ -0,0 +1,121 @@
<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>

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
img/backgrounds/sky.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

View File

@@ -0,0 +1,138 @@
<!doctype html>
<html>
<head>
<title>Imgur</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="copyright" content="Copyright 2016 Imgur, Inc." />
<meta id="viewport" name="viewport" content="width=1280, user-scalable=yes" />
<link rel="stylesheet" type="text/css" href="//s.imgur.com/min/sharePlayer.css?1473720239" />
<style type="text/css">
#content, #video {
width: 1280px;
height: 720px;
}
#chrome, #progress {
width: 1280px;
}
</style>
<link rel="alternate" type="application/json+oembed" href="http://api.imgur.com/oembed.json?url=http://i.imgur.com/9C2DZaI.gifv" title="Imgur GIF" />
<link rel="alternate" type="application/xml+oembed" href="http://api.imgur.com/oembed.xml?url=http://i.imgur.com/9C2DZaI.gifv" title="Imgur GIF" />
<link rel="canonical" href="http://i.imgur.com/9C2DZaI.gifv" />
<meta property="og:site_name" content="Imgur" />
<meta property="og:title" content="Imgur GIF" />
<meta property="og:type" content="video.other" />
<meta property="og:url" content="https://i.imgur.com/9C2DZaI.mp4" />
<meta property="og:image" content="https://i.imgur.com/9C2DZaIh.jpg" />
<meta property="og:description" content="Imgur: The most awesome images on the Internet." />
<meta property="og:video:width" content="1280" />
<meta property="og:video:height" content="720" />
<meta property="og:video" content="https://i.imgur.com/9C2DZaI.mp4" />
<meta property="og:video:secure_url" content="https://i.imgur.com/9C2DZaI.mp4" />
<meta property="og:video:type" content="video/mp4" />
<meta name="twitter:site" content="@imgur" />
<meta name="twitter:domain" content="imgur.com" />
<meta name="twitter:app:id:googleplay" content="com.imgur.mobile" />
<meta name="twitter:card" content="player" />
<meta name="twitter:title" content="Imgur GIF" />
<meta name="twitter:description" content="Imgur: The most awesome images on the Internet." />
<meta name="twitter:image" content="https://i.imgur.com/9C2DZaIh.jpg" />
<meta name="twitter:player" content="https://i.imgur.com/9C2DZaI.gifv?twitter#t" />
<meta name="twitter:player:width" content="1280" />
<meta name="twitter:player:height" content="720" />
<meta name="twitter:player:stream" content="https://i.imgur.com/9C2DZaI.mp4" />
<meta name="twitter:player:stream:content_type" content="video/mp4">
<!--[if lte IE 8]><script type="text/javascript" src="//s.imgur.com/min/iepoly.js?1473720239"></script>
<![endif]-->
</head>
<body id="body">
<div id="content">
<script type="text/javascript">
window.image = '9C2DZaI';
window.image_size = '30908885';
window.image_width = '1280';
window.image_height = '720';
window.cdn_url = '//i.imgur.com';
if(navigator.userAgent.match(/Firefox/)) {
document.body.className = document.body.className + ' firefox';
}
</script>
<div class="vid-container">
<div class="post-image">
<div class="video-container">
<script type="text/javascript">
var videoItem = {
looping: true,
width: 1280,
height: 720,
size: 30908885,
gifUrl: '//i.imgur.com/9C2DZaI.gif',
forceGif: false,
prefer_video: true,
hash: '9C2DZaI'
}
</script>
<video poster="//i.imgur.com/9C2DZaIh.jpg" preload="auto" autoplay="autoplay" muted="muted" loop="loop" webkit-playsinline></video>
<div class="video-elements">
<source src="//i.imgur.com/9C2DZaI.mp4" type="video/mp4">
</div>
<progress value="0" max="100" min="0"></progress>
<div class="video-loader"></div>
<script id="script9C2DZaI" type="text/javascript" src="//s.imgur.com/min/imageViewerInline.js?1473720239"></script>
<meta itemprop="thumbnailUrl" content="https://i.imgur.com/9C2DZaIh.jpg" />
<meta itemprop="contentURL" content="https://i.imgur.com/9C2DZaI.mp4" />
<meta itemprop="embedURL" content="https://i.imgur.com/9C2DZaI.gifv" />
</div>
</div>
</div>
<script type="text/javascript">
var pixel_url = '//i.imgur.com/imageview.gif?a=9C2DZaI&r=' + encodeURIComponent(document.referrer);
var pixel = document.createElement('img');
pixel.src = pixel_url;
</script>
<div id="chrome">
<div class="icon">
<a href="//imgur.com/9C2DZaI"><img src="//i.imgur.com/favicon.ico" /></a>
</div>
<div class="imgur">
<a href="//imgur.com/9C2DZaI">Imgur</a>
</div>
<div class="controls">
<a href="//imgur.com/download/9C2DZaI">download</a>
</div>
<div class="clear"></div>
</div>
</div>
<script type="text/javascript" src="//s.imgur.com/min/sharePlayer.js?1473720239"></script>
<script type="text/javascript">
var _comscore = _comscore || [];
_comscore.push({ c1: "2", c2: "7770950" });
(function() {
var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true;
s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js";
el.parentNode.insertBefore(s, el);
})();
</script>
<noscript>
<img src="http://b.scorecardresearch.com/p?c1=2&c2=7770950&cv=2.0&cj=1" />
</noscript>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
img/foregrounds/surfing.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
img/tests/flieger.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
img/tests/flieger2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 768 KiB

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 876 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

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

View File

@@ -1,180 +1,17 @@
// http://stackoverflow.com/questions/6005076/building-glew-on-windows-with-mingw
#define GLEW_STATIC
#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>
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;
}
#include <dirent.h>
#include "loaders.h"
int main(int argc, char* args[]) {
GLFWwindow* window;
GLuint tex_jpe;
GLuint tex_jpg;
GLuint tex_gif;
GLuint tex_png;
GLuint tex_bmp;
GLuint texBG;
int textw, texth;
int timer = 0;
int textw2, texth2;
/* Initialize the library */
@@ -188,7 +25,7 @@ int main(int argc, char* args[]) {
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
return 1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
@@ -198,48 +35,256 @@ 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
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");
printf("%d", programID);
// 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 texture coordinate 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 one texture, and zero depth buffer.
GLuint FramebufferName;
glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
// load foreground and background textures
int lenTexFG = 1;
GLint texFGs[lenTexFG];
char buffer[50];
texBG = LoadTexture("../img/backgrounds/sky.jpg",&textw2,&texth2);
for (int i=0; i<lenTexFG; i++) {
snprintf(buffer, sizeof(buffer), "../img/foregrounds/original-reference/%d.jpg", i);
texFGs[i] = LoadTexture(buffer,&textw,&texth);
}
// Generate texture for frame buffer
GLuint renderedTexture;
glGenTextures(1, &renderedTexture);
glBindTexture(GL_TEXTURE_2D, renderedTexture);
// Load texture and set filtering
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 color attachment #2 (render to location 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 frame buffer is ok
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
return false;
// Set window size to texture size (window size, opengl context size, resize constraints)
glfwSetWindowSize(window, textw, texth);
glViewport(0, 0, textw, texth);
glfwSetWindowSizeLimits(window, textw, texth, textw, texth);
// Load shader programs
GLuint progTrimapID = LoadShaders("trimap.vertexshader", "trimap.fragmentshader");
GLuint progRefineID = LoadShaders("refinement.vertexshader", "refinement.fragmentshader");
// Get shader locations for trimap shader
GLint locTriTexForeground = glGetUniformLocation(progTrimapID, "foreground");
GLint locTriPixWidth = glGetUniformLocation(progTrimapID, "pixWidth");
GLint locTriPixHeight = glGetUniformLocation(progTrimapID, "pixHeight");
// Get shader locations for refinement shader
GLint locRefTexTrimap = glGetUniformLocation(progRefineID, "trimap");
GLint locRefTexForeground = glGetUniformLocation(progRefineID, "foreground");
GLint locRefTexBackground = glGetUniformLocation(progRefineID, "background");
GLint locRefPixWidth = glGetUniformLocation(progRefineID, "pixWidth");
GLint locRefPixHeight = glGetUniformLocation(progRefineID, "pixHeight");
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texBG);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, renderedTexture);
// INIT END
int loopNumber = -1;
double lastTime = glfwGetTime();
double lastTimeLoop = glfwGetTime();
int nbFrames = 0;
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window)) {
timer += 1;
if (timer==800)
timer = 0;
/* Render here */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programID);
// 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);
// Measure speed
double currentTime = glfwGetTime();
nbFrames++;
if ( currentTime - lastTime >= 1.0 ){
// If last prinf() was more than 1 sec ago
// printf and reset timer
printf("%f ms/frame\n", 1000.0/double(nbFrames));
nbFrames = 0;
lastTime += 1.0;
}
// Foreground texture counter
if ( currentTime - lastTimeLoop >= 0.08 ){
loopNumber++;
if (loopNumber >= lenTexFG) {
loopNumber = 0;
}
lastTimeLoop += 0.08;
}
// Set current foreground texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texFGs[loopNumber]);
/* RENDER TO FRAMEBUFFER */
// Render to our framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
// Clear buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Init trimap shader program
glUseProgram(progTrimapID);
glUniform1f(locTriPixWidth, 1.0f/textw);
glUniform1f(locTriPixHeight, 1.0f/texth);
glUniform1i(locTriTexForeground, 0);
// 1st 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 triangles (and render trimap shaders) to framebuffer/texture
glDrawArrays(GL_TRIANGLES, 0, 2*3); // 2*3 indices starting at 0 -> 2 triangles -> 1 square
glDisableVertexAttribArray(0);
glUseProgram(0);
// Render to the screen
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// Init refinement shader program
glUseProgram(progRefineID);
glUniform1i(locRefTexForeground, 0);
glUniform1i(locRefTexBackground, 1);
glUniform1i(locRefTexTrimap, 2);
glUniform1f(locRefPixWidth, 1.0f/textw);
glUniform1f(locRefPixHeight, 1.0f/texth);
// 1st 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 : texture coordinates
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 triangles (and render refinement shaders) to screen
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 */

View File

@@ -13,6 +13,7 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="include" />
</Compiler>
</Target>
<Target title="Release">
@@ -22,6 +23,7 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
<Add directory="include" />
</Compiler>
<Linker>
<Add option="-s" />
@@ -44,7 +46,11 @@
<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>

View File

@@ -2,18 +2,16 @@
1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp
<iostream>
1473007864 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\main.cpp
1473869767 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\main.cpp
<GL/glew.h>
<GLFW/glfw3.h>
<SDL2/SDL.h>
<SDL2/SDL_image.h>
<stdio.h>
<iostream>
<fstream>
<vector>
<stdexcept>
<dirent.h>
"loaders.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h
<stddef.h>
<stdint.h>
<OpenGL/gl3.h>
@@ -34,7 +32,7 @@
<GL/glext.h>
<GL/glu.h>
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl.h
"SDL_main.h"
"SDL_stdinc.h"
"SDL_assert.h"
@@ -65,12 +63,12 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_main.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_main.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_stdinc.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_stdinc.h
"SDL_config.h"
<sys/types.h>
<stdio.h>
@@ -99,34 +97,34 @@
<stdlib.h>
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_config.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_config.h
"SDL_platform.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_platform.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_platform.h
"AvailabilityMacros.h"
"TargetConditionals.h"
<winapifamily.h>
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\begin_code.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\begin_code.h
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\close_code.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\close_code.h
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_assert.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_assert.h
"SDL_config.h"
"begin_code.h"
<signal.h>
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_atomic.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_atomic.h
"SDL_stdinc.h"
"SDL_platform.h"
"begin_code.h"
<mbarrier.h>
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_audio.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_audio.h
"SDL_stdinc.h"
"SDL_error.h"
"SDL_endian.h"
@@ -136,24 +134,24 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_error.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_error.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_endian.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_endian.h
"SDL_stdinc.h"
<endian.h>
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_mutex.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_mutex.h
"SDL_stdinc.h"
"SDL_error.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_thread.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_thread.h
"SDL_stdinc.h"
"SDL_error.h"
"SDL_atomic.h"
@@ -162,18 +160,18 @@
<process.h>
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_rwops.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_rwops.h
"SDL_stdinc.h"
"SDL_error.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_clipboard.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_clipboard.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_cpuinfo.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_cpuinfo.h
"SDL_stdinc.h"
<intrin.h>
<intrin.h>
@@ -185,7 +183,7 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_events.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_events.h
"SDL_stdinc.h"
"SDL_error.h"
"SDL_video.h"
@@ -199,7 +197,7 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_video.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_video.h
"SDL_stdinc.h"
"SDL_pixels.h"
"SDL_rect.h"
@@ -207,12 +205,12 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_pixels.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_pixels.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_rect.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_rect.h
"SDL_stdinc.h"
"SDL_error.h"
"SDL_pixels.h"
@@ -220,7 +218,7 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_surface.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_surface.h
"SDL_stdinc.h"
"SDL_pixels.h"
"SDL_rect.h"
@@ -229,11 +227,11 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_blendmode.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_blendmode.h
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_keyboard.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_keyboard.h
"SDL_stdinc.h"
"SDL_error.h"
"SDL_keycode.h"
@@ -241,27 +239,27 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_keycode.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_keycode.h
"SDL_stdinc.h"
"SDL_scancode.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_scancode.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_scancode.h
"SDL_stdinc.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_mouse.h
1473011642 d:\owncloud\documents\programmierung\cpp\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"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_joystick.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_joystick.h
"SDL_stdinc.h"
"SDL_error.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_gamecontroller.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_gamecontroller.h
"SDL_stdinc.h"
"SDL_error.h"
"SDL_rwops.h"
@@ -269,11 +267,11 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_quit.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_quit.h
"SDL_stdinc.h"
"SDL_error.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_gesture.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_gesture.h
"SDL_stdinc.h"
"SDL_error.h"
"SDL_video.h"
@@ -281,60 +279,60 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_touch.h
1473011642 d:\owncloud\documents\programmierung\cpp\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"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_filesystem.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_filesystem.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_haptic.h
1473011642 d:\owncloud\documents\programmierung\cpp\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"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_hints.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_hints.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_loadso.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_loadso.h
"SDL_stdinc.h"
"SDL_error.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_log.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_log.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_messagebox.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_messagebox.h
"SDL_stdinc.h"
"SDL_video.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_power.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_power.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_render.h
1473011642 d:\owncloud\documents\programmierung\cpp\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"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_system.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_system.h
"SDL_stdinc.h"
"SDL_keyboard.h"
"SDL_render.h"
@@ -342,24 +340,24 @@
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_timer.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_timer.h
"SDL_stdinc.h"
"SDL_error.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_version.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_version.h
"SDL_stdinc.h"
"begin_code.h"
"close_code.h"
1472737758 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_image.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\sdl2\sdl_image.h
"SDL.h"
"SDL_version.h"
"begin_code.h"
"close_code.h"
1472927170 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\gl\glew.h
1473011642 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\gl\glew.h
<stddef.h>
<inttypes.h>
<stdint.h>
@@ -368,3 +366,387 @@
<OpenGL/glu.h>
<GL/glu.h>
1473412967 source:d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\main.cpp
<GL/glew.h>
<GLFW/glfw3.h>
<iostream>
<fstream>
<vector>
<stdexcept>
"loaders.h"
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\gl\glew.h
<stddef.h>
<inttypes.h>
<stdint.h>
<inttypes.h>
<Availability.h>
<OpenGL/glu.h>
<GL/glu.h>
1473141855 d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h
<stddef.h>
<stdint.h>
<OpenGL/gl3.h>
<OpenGL/gl3ext.h>
<OpenGL/gl.h>
<OpenGL/glu.h>
<GL/glcorearb.h>
<GLES/gl.h>
<GLES/glext.h>
<GLES2/gl2.h>
<GLES2/gl2ext.h>
<GLES3/gl3.h>
<GLES2/gl2ext.h>
<GLES3/gl31.h>
<GLES2/gl2ext.h>
<vulkan/vulkan.h>
<GL/gl.h>
<GL/glext.h>
<GL/glu.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"
<sys/types.h>
<stdio.h>
<stdlib.h>
<stddef.h>
<stdarg.h>
<stdlib.h>
<malloc.h>
<stddef.h>
<stdarg.h>
<memory.h>
<string.h>
<strings.h>
<inttypes.h>
<stdint.h>
<ctype.h>
<math.h>
<float.h>
<iconv.h>
<sal.h>
"begin_code.h"
<alloca.h>
<malloc.h>
<malloc.h>
<malloc.h>
<stdlib.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"
<winapifamily.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"
<signal.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"
<mbarrier.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"
<endian.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"
<process.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"
<intrin.h>
<intrin.h>
<altivec.h>
<mmintrin.h>
<mm3dnow.h>
<xmmintrin.h>
<emmintrin.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
<GL/glew.h>
1473412967 source:d:\profile\ksy\eigene dateien\git\imanox-chroma-matting\opengl-test-two\src\loaders.cpp
<SDL2/SDL.h>
<SDL2/SDL_image.h>
<fstream>
<vector>
"loaders.h"
1473700459 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\src\loaders.cpp
<SDL2/SDL.h>
<SDL2/SDL_image.h>
<fstream>
<vector>
"loaders.h"
1473700459 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\loaders.h
<GL/glew.h>

View File

@@ -0,0 +1,153 @@
#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;
// Relative width/height of a pixel
uniform float pixWidth;
uniform float pixHeight;
int IS_BACKGROUND = 0;
int IS_UNDEFINED = 1;
int IS_FOREGROUND = 2;
int UNSET = -1;
float M_PI= 3.14159;
int suchbreich=10; //die anzahl der Pixel, die maximal in eine Richtung gegangen wird um einen Sicheren Pixel zu finden
vec4 SicheresPixel[50]; //Speichert die das nachste Sichere Pixel, Array grosse=anzahl der Richtungen
int anzahl_richtungen=50; //Speichert anzahl der Richtungen muss gleich der Array grosse von SicheresPixel sein
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;
}
}
vec4 suche_Pixel_nach_winkel (vec2 uv, float winkel){
vec2 pix;
float i=1;
vec3 color_sichers_Pixel;
while(i<suchbreich){
pix.x=uv.x+ sin(winkel)*pixWidth*i;
pix.y=uv.y+ cos(winkel)*pixWidth*i;
color_sichers_Pixel = getTriColor(pix);
int status = getState(color_sichers_Pixel);
if (status==IS_FOREGROUND) {
return vec4(getForeColor(pix), i);
//return vec4(1f, 1f, 1f, i);
} else if (status==IS_BACKGROUND) {
return vec4(getBackColor(pix), i);
//return vec4(0f, 0f, 0f, i);
}else{
i++;
}
}
return vec4(0.0f, 0.0f, 0.0f, -1.0f);
}
float Farbabstand(int i){
float d=sqrt(pow(color.x-SicheresPixel[i].x,2)+pow(color.y-SicheresPixel[i].y,2)+pow(color.z-SicheresPixel[i].z, 2));//sqr((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)
return d;
}
vec3 Pruefe_Pixel_in_Umgebung (vec2 start){
float winkel=2*M_PI/anzahl_richtungen;
int i=0;
float gefundene_pixel=0.0f;
float maximal=0;
float gesamt_abstand=0.0f;
while(i<anzahl_richtungen){
SicheresPixel[i]=suche_Pixel_nach_winkel(start, winkel*i);
if(SicheresPixel[i].w!=-1){
gesamt_abstand+=SicheresPixel[i].w;
gefundene_pixel++;
if(maximal<SicheresPixel[i].w)
maximal=SicheresPixel[i].w;
}
i=i+1;
}
maximal++;
//float d = Farbabstand(1);//eigene Funktion
/*float d1=distance(SicheresPixel[1].xyz, color);//mitgelieferte Funktion
if (d1==d ){
return SicheresPixel[1];
}else{
return vec3(0.5f);
}*/
float nenner=0.0f;
i=0;
while(i<anzahl_richtungen){
if(SicheresPixel[i].w!=-1){
SicheresPixel[i].w=pow(maximal-SicheresPixel[i].w,2);
nenner+=SicheresPixel[i].w;
}
i++;
}
i=0;
vec3 kombiniert=vec3(0.0f);
while(i<anzahl_richtungen){
if(SicheresPixel[i].w!=-1)
kombiniert+=SicheresPixel[i].xyz*SicheresPixel[i].w/nenner;
i++;
}
return kombiniert;
}
void main(){
color = getTriColor(UV);
int status = getState(color);
if (status==IS_FOREGROUND) {
color = getForeColor(UV).rgb;
//color = vec3(1.0f, 0.0f, 0.0f);
//color = vec3(1.0f);
} else if (status==IS_BACKGROUND) {
color = getBackColor(UV).rgb;
//color = vec3(0.0f, 1.0f, 0.0f);
//color = vec3(0.0f);
} else {
color = Pruefe_Pixel_in_Umgebung(UV);
//color = vec3(0.0f, 0.0f, 1.0f);
//color = Pruefe_Pixel_in_Umgebung(UV);
}
}

View File

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

View File

@@ -0,0 +1,143 @@
#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
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
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
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,8 +1,79 @@
#version 330 core
out vec4 color;
// 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 foreground;
// 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(73.0f/255.0f, 129.0f/255.0f, 24.0f/255.0f);
vec3 difference = vec3(40.0f/255.0f);
int radius = 2;
vec3 getColor(vec2 uvCoord) {
return texture(foreground, uvCoord).rgb;
}
bool isBackground(vec3 c) {
if (all( lessThanEqual(c, greenValue+difference)) &&
all(greaterThanEqual(c, greenValue-difference))
) {
return true;
} else {
return false;
}
}
void main(){
color = vec3(0.5,0,0);
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); // black
} else if (status == IS_FOREGROUND) {
color = vec3(1.0f); // white
} else {
color = vec3(0.5f); // gray
}
}

View File

@@ -1,8 +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(){
gl_Position.xyz = vertexPosition_modelspace;
gl_Position.w = 1.0;
// 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;
}