From cf3f284a5f24bd02006e9ff929cc29d10c428a3e Mon Sep 17 00:00:00 2001 From: knolax <1339802534.kk@gmail.com> Date: Tue, 28 Feb 2017 11:05:31 -0500 Subject: textures loaded properly now but without functional alpha layer. --- example/fragmentshader.glsl | 8 +++++++- example/main | Bin 49568 -> 54072 bytes example/makefile | 2 +- example/textures/elev.bmp | Bin 0 -> 4000138 bytes example/textures/elev.png | Bin 0 -> 198073 bytes example/textures/tex.bmp | Bin 0 -> 4000138 bytes example/textures/tex.png | Bin 0 -> 164345 bytes example/vertexshader.glsl | 3 +++ 8 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 example/textures/elev.bmp create mode 100644 example/textures/elev.png create mode 100644 example/textures/tex.bmp create mode 100644 example/textures/tex.png (limited to 'example') diff --git a/example/fragmentshader.glsl b/example/fragmentshader.glsl index 70c55b5..6e8c4c5 100644 --- a/example/fragmentshader.glsl +++ b/example/fragmentshader.glsl @@ -2,11 +2,15 @@ out vec4 outpix; uniform vec3 campos; uniform vec3 lightpos; +uniform sampler2D tex; +uniform sampler2D elev; //varing blends them it is transformed to world space varying vec4 fragpos; varying vec4 fragnormal; +varying vec2 fragtexcoord; void main() { + vec4 elevpix = texture(elev, fragtexcoord); vec3 lightnormal = normalize((lightpos - vec3(fragpos.x, fragpos.y, fragpos.z))); float diffuse = dot(lightnormal, vec3(fragnormal.x, fragnormal.y, fragnormal.z)); if (diffuse < 0.0) { @@ -17,9 +21,11 @@ void main() diffuse = pow(diffuse, 2.0); reflect = pow(reflect, 2.0); float light = .4 * reflect + .6 * diffuse; + vec4 texpix = texture(tex, fragtexcoord); //this should be the vertex in camera space without the w value //outpix = gl_FragCoord; - outpix = vec4(light * 1.0,light * 1.0,light * 1.0, 1.0); + outpix = texpix; + //outpix = vec4(light * 1.0,light * 1.0,light * 1.0, 1.0); //outpix = vec4(fragpos.x ,fragpos.y ,fragpos.z, 0.5); //outpix = vec4(fragnormal.x, fragnormal.y, fragnormal.z, 0.5); } diff --git a/example/main b/example/main index 51bb73a..14fd1e1 100755 Binary files a/example/main and b/example/main differ diff --git a/example/makefile b/example/makefile index 578059f..4a86980 100644 --- a/example/makefile +++ b/example/makefile @@ -1,5 +1,5 @@ main : main.o - g++ main.o -o main -L/home/knolax/code/cpp/gfx -lgui -lgfx -lSDL2 -lSDL2_ttf -L/home/knolax/code/cpp/glgfx -lglgfx -lGLEW -lGL + g++ main.o -o main -L/home/knolax/code/cpp/gfx -lgui -lgfx -lSDL2 -lSDL2_ttf -L/home/knolax/code/cpp/glgfx -lglgfx -lGLEW -lGL -lSOIL main.o : main.cpp g++ -c main.cpp -I/home/knolax/code/cpp/gfx -I/home/knolax/code/cpp/glgfx clean : diff --git a/example/textures/elev.bmp b/example/textures/elev.bmp new file mode 100644 index 0000000..cb9fec6 Binary files /dev/null and b/example/textures/elev.bmp differ diff --git a/example/textures/elev.png b/example/textures/elev.png new file mode 100644 index 0000000..68c4308 Binary files /dev/null and b/example/textures/elev.png differ diff --git a/example/textures/tex.bmp b/example/textures/tex.bmp new file mode 100644 index 0000000..620d364 Binary files /dev/null and b/example/textures/tex.bmp differ diff --git a/example/textures/tex.png b/example/textures/tex.png new file mode 100644 index 0000000..79d9a1c Binary files /dev/null and b/example/textures/tex.png differ diff --git a/example/vertexshader.glsl b/example/vertexshader.glsl index f60ec9f..8ba8228 100644 --- a/example/vertexshader.glsl +++ b/example/vertexshader.glsl @@ -5,12 +5,15 @@ uniform mat4 cam; uniform mat4 rot; in vec3 position; in vec3 vnormal; +in vec3 texcoord; varying vec4 fragpos; varying vec4 fragnormal; // if this needs to not be blended jsut have all vertexes in a poly be the same +varying vec2 fragtexcoord; void main() { //this is the actual position gl_Position = proj * cam * tran * vec4(position, 1.0f);// - vec4(gl_Normal, 1.0f); fragpos = tran * vec4(position, 1.0f); fragnormal = (tran * vec4(vnormal, 1.0f)) - (tran * vec4(0.0, 0.0, 0.0, 1.0)); + fragtexcoord = texcoord.xy; } -- cgit v1.1