Initial commit

This commit is contained in:
lewa_j 2019-08-07 04:06:06 +03:00
commit beea0baeed
204 changed files with 16080 additions and 0 deletions

21
.gitignore vendored Normal file
View File

@ -0,0 +1,21 @@
# Binaries
*.o
*.so
*.a
*.exe
*.dll
# Qt Creator
*.user*
*.config
*.creator
*.includes
*.files
bin
obj
obj_lin
*.mdl
*.vtx
*.vvd

26
README.md Normal file
View File

@ -0,0 +1,26 @@
=nenuzhno engine=
This repository contains the old discontinued codebase of my training engine/framework. I'm currently working on a new iteration of an engine, with better architecture (that's what i'm counting on).
I put it here so as not to lose by accident.
Writen in C++. Uses OpenGL/ES 2.
==Dependencies==
MinGW-W64
GLFW 3.3
GLM 0.9.9.0
GLEW 2.0
==demos==
StarFleet - space battles "game". With basic fighter AI, but withous gameplay
tpsGame - atempt to make real game. With bullet phisics, text map format, even menu
VolLight - Volumetric lighting
gravity - 2D simulation "game"
skinning - loads mdl files (Source engine) and renders some animation
SSR - kinda screen space reflections
path_tracing - uses glsl shader for ray trace
blur-test - atempt to do bokeh
cube - just wireframe cube
ComprTex - demonstrates some compressed texture formats

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
assets/base/models/cube.nmf Normal file

Binary file not shown.

View File

@ -0,0 +1,12 @@
#version 100
precision highp float;
varying vec4 v_col;
uniform sampler2D u_coreTex;
void main()
{
//vec4 col = texture2D(u_coreTex, gl_PointCoord.xy);
vec4 col = vec4(length(gl_PointCoord.xy-0.5)<0.5);
gl_FragColor = col*v_col;
}

View File

@ -0,0 +1,44 @@
#version 100
precision highp float;
attribute vec4 a_position;
uniform mat4 u_mvpMtx;
uniform sampler2D u_texture;
uniform float u_size;
varying vec4 v_col;
//const float bright = 0.1;
//const float size = 21.5;
const float ndofstart = 1.0;
const float ndofdist = 2.0;
const float fdofstart = 1.0;
const float fdofdist = 3.0;
void main()
{
float depth = abs(a_position.x*3.0);
float fDepth = 1.5;
float a = depth-fDepth; //focal plane
float b = (a-fdofstart)/fdofdist; //far DoF
float c = (-a-ndofstart)/ndofdist; //near Dof
float size = (a>0.0)?b:c;
size = clamp(size,0.0,1.0) *20.0+1.0;
//float size = length(a_position.xy-0.5)*20.0+1.0;
//float size = abs(a_position.x-u_size*0.01-0.4)*64.5+5.0;
//float size=7.0;
//size = u_size;//*0.5+3.0;
//4/PI
float bright = 1.273239/(size*size);
bright = clamp(bright,0.007,1.0);
gl_Position = vec4(a_position.xyz*2.0-1.0,1.0);
v_col = texture2D(u_texture,a_position.xy)*bright;
if(length(v_col)<0.01)
gl_Position.z=-999.9;
gl_PointSize = size;
//gl_PointSize = a_position.x*34.5+5.0;
}

View File

@ -0,0 +1,12 @@
#version 100
precision highp float;
varying vec2 v_uv;
uniform sampler2D u_texture;
uniform vec4 u_color;
void main()
{
vec4 col = texture2D(u_texture, v_uv);
gl_FragColor = col * u_color;
}

View File

@ -0,0 +1,23 @@
#version 100
precision highp float;
attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_uv;
varying vec3 v_normal;
varying vec2 v_uv;
varying vec3 v_viewDir;
uniform mat4 u_mvpMtx;
uniform mat4 u_modelMtx;
uniform vec3 u_camPos;
void main()
{
gl_Position = u_mvpMtx * a_position;
gl_PointSize = 4.0;
v_normal = normalize(mat3(u_modelMtx)*a_normal);
v_uv = a_uv;
v_viewDir = u_camPos-(u_modelMtx*a_position).xyz;
}

View File

@ -0,0 +1,32 @@
#version 100
precision highp float;
varying vec3 v_normal;
varying vec2 v_uv;
varying vec3 v_viewDir;
uniform sampler2D u_tex;
uniform vec3 u_lightDir;
const float specPower = 40.0;
vec3 calcLight(vec3 dir, vec3 norm, vec3 lcol, vec3 col){
vec3 reflectVec = reflect(-dir, norm);
float diffuse = max(0.0,dot(norm,dir));
vec3 vd = normalize(v_viewDir);
float specular = 0.5*pow(max(dot(vd, reflectVec), 0.0), specPower);
return col*diffuse*lcol + specular*lcol;
}
void main()
{
vec4 col = texture2D(u_tex, v_uv);
vec3 normal = normalize(v_normal);
gl_FragColor = vec4(0.0);
//float diffuse = max(0.0,dot(normal,u_lightDir));
gl_FragColor.rgb = calcLight(u_lightDir,normal,vec3(1.0),col.rgb);
//gl_FragColor = col;
gl_FragColor.rgb+=0.1;
}

View File

@ -0,0 +1,43 @@
#version 100
precision highp float;
varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_uv;
uniform sampler2D u_texture;
uniform vec3 u_lightColor;
uniform vec3 u_lightPos;
uniform float u_lightSize;
varying vec3 v_viewDir;
const float specPower = 10.0;
vec3 calcLight(vec3 dir, vec3 norm, vec3 lcol, vec3 col){
vec3 reflectVec = reflect(-dir, norm);
float diffuse = max(0.0,dot(norm,dir));
vec3 vd = normalize(v_viewDir);
float specular = 0.3*pow(max(dot(vd, reflectVec), 0.0), specPower);
return col*diffuse*lcol + specular*lcol;
}
vec3 calcPointLight(vec3 pos, vec3 norm, vec3 lcol, vec3 col){
//float atten = 1.0 - pow(clamp(length(pos-v_position)/u_lightSize, 0.0, 1.0), 1.5);
float atten = 1.0-clamp(length(pos-v_position)/u_lightSize, 0.0, 1.0);
return calcLight(normalize(pos-v_position),norm,lcol,col)*atten;
}
void main()
{
//if(length(u_lightPos-v_position)>u_lightSize)
// discard;
vec4 col = texture2D(u_texture, v_uv);
vec3 norm = normalize(v_normal);
vec4 outc = vec4(0.0,0.0,0.0,1.0);
outc.rgb += calcPointLight(u_lightPos,norm,u_lightColor,col.rgb);
gl_FragColor = outc;
}

View File

@ -0,0 +1,25 @@
#version 100
precision highp float;
attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_uv;
varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_uv;
varying vec3 v_viewDir;
uniform mat4 u_mvpMtx;
uniform mat4 u_modelMtx;
uniform vec3 u_camPos;
void main()
{
gl_Position = u_mvpMtx * a_position;
gl_PointSize = 4.0;
v_normal = normalize(mat3(u_modelMtx)*a_normal);
v_position = (u_modelMtx*a_position).xyz;
v_uv = a_uv;
v_viewDir = u_camPos-(u_modelMtx*a_position).xyz;
}

View File

@ -0,0 +1,6 @@
#version 100
precision highp float;
void main(){
gl_FragColor = vec4(1.0);
}

View File

@ -0,0 +1,10 @@
precision highp float;
varying vec2 v_uv;
uniform sampler2D u_tex;
void main()
{
gl_FragColor.rgb = vec3(0.5);
gl_FragColor.a = 0.2;//texture2D(u_tex,v_uv);
}

View File

@ -0,0 +1,13 @@
#version 100
precision highp float;
attribute vec4 a_position;
varying vec2 v_uv;
uniform vec4 u_transform;
void main()
{
gl_Position = a_position;
gl_Position.xy = a_position.xy*u_transform.zw+u_transform.xy;
v_uv = a_position.xy*0.5+0.5;
}

View File

@ -0,0 +1,7 @@
#version 100
precision highp float;
void main()
{
gl_FragColor = vec4(1.0, 0.5, 0.2, 1.0);
}

View File

@ -0,0 +1,12 @@
#version 100
precision highp float;
attribute vec4 a_position;
uniform mat4 u_mvpMtx;
void main()
{
gl_Position = u_mvpMtx * a_position;
gl_PointSize = 4.0;
}

View File

@ -0,0 +1,11 @@
#version 100
precision highp float;
varying vec3 v_dir;
uniform samplerCube u_tex;
void main()
{
vec4 col = textureCube(u_tex, v_dir);
gl_FragColor = col;
}

View File

@ -0,0 +1,10 @@
#version 100
attribute vec4 a_position;
varying vec3 v_dir;
uniform mat4 u_mvpMtx;
void main()
{
gl_Position = u_mvpMtx * a_position;
v_dir = a_position.xyz;
}

View File

@ -0,0 +1,2 @@
1
base

View File

@ -0,0 +1,14 @@
#version 100
precision highp float;
varying vec2 v_uv;
uniform sampler2D u_texture;
void main()
{
float a=0.0;
//a=length(v_uv-0.5)*5.0;//+4.0;
a=v_uv.x*2.0+3.5;
vec4 col = texture2D(u_texture, v_uv,a);
gl_FragColor = col;
}

View File

@ -0,0 +1,2 @@
1
base

View File

@ -0,0 +1,7 @@
#version 100
precision highp float;
varying vec2 v_uv;
uniform sampler2D u_tex;
void main(){
gl_FragColor = texture2D(u_tex,v_uv);
}

View File

@ -0,0 +1,8 @@
#version 100
precision highp float;
attribute vec4 a_position;
varying vec2 v_uv;
void main(){
gl_Position = a_position;
v_uv = a_position.xy*0.5+0.5;
}

View File

@ -0,0 +1,138 @@
#version 100
precision highp float;
varying vec2 v_uv;
uniform float u_textureWeight;
uniform sampler2D texture;
uniform sampler2D u_worldTex;
uniform float u_timeSinceStart;
uniform int u_numCubes;
const float glossiness = 0.8;
float intersectSphere(vec3 origin, vec3 ray, vec4 sphereCenter)
{
vec3 toSphere = origin - sphereCenter.xyz;
float a = dot(ray, ray);
float b = 2.0 * dot(toSphere, ray);
float c = dot(toSphere, toSphere) - sphereCenter.w*sphereCenter.w;
float discriminant = b*b - 4.0*a*c;
if(discriminant > 0.0){
float t = (-b - sqrt(discriminant)) / (2.0 * a);
if(t > 0.0) return t;
}
return 9999.9;
}
vec2 intersectCube(vec3 origin, vec3 ray, vec3 cubeMin, vec3 cubeMax){
vec3 tMin = (cubeMin - origin) / ray;
vec3 tMax = (cubeMax - origin) / ray;
vec3 t1 = min(tMin, tMax);
vec3 t2 = max(tMin, tMax);
float tNear = max(max(t1.x, t1.y), t1.z);
float tFar = min(min(t2.x, t2.y), t2.z);
return vec2(tNear, tFar);
}
vec3 normalForCube(vec3 hit, vec3 cubeMin, vec3 cubeMax){
if(hit.x < cubeMin.x + 0.0001) return vec3(-1.0, 0.0, 0.0);
else if(hit.x > cubeMax.x - 0.0001) return vec3(1.0, 0.0, 0.0);
else if(hit.y < cubeMin.y + 0.0001) return vec3(0.0, -1.0, 0.0);
else if(hit.y > cubeMax.y - 0.0001) return vec3(0.0, 1.0, 0.0);
else if(hit.z < cubeMin.z + 0.0001) return vec3(0.0, 0.0, -1.0);
else return vec3(0.0, 0.0, 1.0);
}
float random(vec3 scale, float seed){
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
}
vec3 cosineWeightedDirection(float seed, vec3 normal){
float u = random(vec3(12.9898, 78.233, 151.7182), seed);
float v = random(vec3(63.7264, 10.873, 623.6736), seed);
float r = sqrt(u);
float angle = 6.283185307179586 * v;
vec3 sdir, tdir;
if (abs(normal.x)<.5){
sdir = cross(normal, vec3(1,0,0));
}else{
sdir = cross(normal, vec3(0,1,0));
}
tdir = cross(normal, sdir);
return r*cos(angle)*sdir + r*sin(angle)*tdir + sqrt(1.-u)*normal;
}
vec3 uniformlyRandomDirection(float seed){
float u = random(vec3(12.9898, 78.233, 151.7182), seed);
float v = random(vec3(63.7264, 10.873, 623.6736), seed);
float z = 1.0 - 2.0 * u;
float r = sqrt(1.0 - z * z);
float angle = 6.283185307179586 * v;
return vec3(r * cos(angle), r * sin(angle), z);
}
vec3 uniformlyRandomVector(float seed){
return uniformlyRandomDirection(seed) * sqrt(random(vec3(36.7539, 50.3658, 306.2759), seed));
}
float shadow(vec3 origin, vec3 ray) {
for(int c = 0; c<u_numCubes;c++){
vec3 cubemin = texture2D(u_worldTex,vec2(0.0,float(c)/float(u_numCubes-1))).xyz;
vec3 cubemax = texture2D(u_worldTex,vec2(1.0,float(c)/float(u_numCubes-1))).xyz;
vec2 tCube1 = intersectCube(origin, ray, cubemin,cubemax);
if(tCube1.x > 0.0 && tCube1.x < 1.0 && tCube1.x < tCube1.y)
return 0.0;
}
return 1.0;
}
const vec3 lightPos = vec3(-1.3,0.1,0.05);
vec3 calculateColor(vec3 origin, vec3 ray, vec3 light,float seed){
vec3 colorMask = vec3(1.0);
vec3 result = vec3(0.0);
for(int bounce = 0; bounce < 4; bounce++){
float t = 9999.9;
vec3 normal;
vec2 tRoom = intersectCube(origin, ray, vec3(-1.5,-1.0,-1.0), vec3(1.0));
if(tRoom.x < tRoom.y) t = tRoom.y;
vec3 hit = origin + ray * t;
for(int c = 0; c < u_numCubes;c++){
vec3 cubemin = texture2D(u_worldTex,vec2(0.0,float(c)/float(u_numCubes-1))).xyz;
vec3 cubemax = texture2D(u_worldTex,vec2(1.0,float(c)/float(u_numCubes-1))).xyz;
vec2 tCube1 = intersectCube(origin, ray, cubemin,cubemax);
if(tCube1.x > 0.0 && tCube1.x < t && tCube1.x < tCube1.y)
{
t = tCube1.x;
hit = origin + ray * t;
normal = normalForCube(hit, cubemin,cubemax);
}
}
float lth = intersectSphere(origin,ray,vec4(lightPos,0.1));
if(lth<t)
return vec3(1.0);
vec3 surfaceColor = vec3(0.75);
if(t == tRoom.y){
normal = -normalForCube(hit, vec3(-1.5,-1.0,-1.0), vec3(1.0));
if(hit.x < -1.4999) surfaceColor = vec3(1.0, 0.3, 0.1);
else if(hit.x > 0.9999) surfaceColor = vec3(0.3, 1.0, 0.1);
ray = cosineWeightedDirection(seed + float(bounce), normal);
//ray = reflect(ray, normal);
//ray = normalize(reflect(ray, normal)) + uniformlyRandomVector(seed + float(bounce)) * glossiness;
}else if(t == 9999.9){
break;
}else{
ray = normalize(reflect(ray, normal)) + uniformlyRandomVector(seed + float(bounce)) * glossiness;
surfaceColor = vec3(0.5, 0.5, 0.9);
}
vec3 toLight = light - hit;
float diffuse = max(0.0, dot(normalize(toLight), normal));
float shadowIntensity = shadow(hit + normal * 0.0001, toLight);
colorMask *= surfaceColor;
//if(bounce>0)
result += colorMask*diffuse*0.5*shadowIntensity;
origin = hit;
}
return result;
}
void main(){
vec3 dir = normalize(vec3(v_uv,-1.0));
vec3 newLight = lightPos + uniformlyRandomVector(u_timeSinceStart - 53.0) * 0.1;
vec3 sample1 = calculateColor(vec3(-0.2,0.15,1.5), dir, newLight,u_timeSinceStart);
//newLight = vec3(-1.4,0.1,-0.1) + uniformlyRandomVector(u_timeSinceStart - 27.4) * 0.1;
//sample1 = 0.5*(sample1+calculateColor(vec3(-0.2,0.15,1.5), dir, newLight,u_timeSinceStart+65.3));
vec3 textureCol = texture2D(texture, v_uv*0.5+0.5).rgb;
gl_FragColor = vec4(mix(sample1, textureCol, u_textureWeight), 1.0);
//gl_FragColor = vec4(sample1,1.0);
}

View File

@ -0,0 +1,8 @@
#version 100
precision highp float;
attribute vec4 a_position;
varying vec2 v_uv;
void main(){
gl_Position = a_position;
v_uv = a_position.xy;
}

9
assets/pt/shaders/tex.fs Normal file
View File

@ -0,0 +1,9 @@
#version 100
precision highp float;
varying vec2 v_uv;
uniform sampler2D u_tex;
void main(){
gl_FragColor = texture2D(u_tex,v_uv);
}

16
assets/pt/shaders/tex.vs Normal file
View File

@ -0,0 +1,16 @@
#version 100
precision highp float;
attribute vec4 a_position;
attribute vec2 a_uv;
varying vec2 v_uv;
uniform mat4 u_mvpMtx;
void main()
{
gl_Position = u_mvpMtx * a_position;
v_uv = a_uv;
gl_PointSize = 4.0;
}

View File

@ -0,0 +1,3 @@
1
base

View File

@ -0,0 +1,11 @@
scale 0.03 0.03 0.03
model models/turret.mdl
anim 0
#model models/Antlion.mdl
#model models/Alyx.mdl
#model models/personality_sphere.mdl
#model models/elevator_b.mdl
#model models/player.mdl
#model models/player_animations.mdl
#model models/headcrabclassic.mdl
#model models/male_07.mdl

View File

@ -0,0 +1,17 @@
#version 100
precision highp float;
varying vec3 v_normal;
varying vec2 v_uv;
varying vec3 v_bones;
uniform sampler2D u_texture;
uniform vec4 u_color;
void main()
{
vec4 col = texture2D(u_texture, v_uv);
col *= max(0.2,dot(v_normal,normalize(vec3(1.0))));
gl_FragColor = col * u_color;
//gl_FragColor = mix(gl_FragColor,v_bones.xxxx*0.1,0.99);
}

View File

@ -0,0 +1,32 @@
#version 100
precision highp float;
attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_uv;
attribute vec3 a_weight;
attribute vec3 a_bones;
varying vec3 v_normal;
varying vec2 v_uv;
//varying vec3 v_viewDir;
varying vec3 v_bones;
uniform mat4 u_mvpMtx;
uniform mat4 u_modelMtx;
uniform mat4 u_bonesMtx[77];
//uniform vec3 u_camPos;
void main(){
/*int bi = int(a_bones.x);
if(bi>76)bi=0;
mat4 boneMtx = u_bonesMtx[bi];//*a_weight.x;*/
mat4 boneMtx = u_bonesMtx[int(a_bones.x)]*a_weight.x+u_bonesMtx[int(a_bones.y)]*a_weight.y+u_bonesMtx[int(a_bones.z)]*a_weight.z;
gl_Position = u_mvpMtx * boneMtx * a_position;
gl_PointSize = 4.0;
v_normal = normalize(mat3(u_modelMtx * boneMtx)*a_normal);
v_uv = a_uv;
//v_viewDir = u_camPos-(u_modelMtx*a_position).xyz;
v_bones=a_bones;
}

View File

@ -0,0 +1,2 @@
1
base

170
assets/ssr/shaders/ssr.fs Normal file
View File

@ -0,0 +1,170 @@
#version 100
precision highp float;
varying vec4 v_scrpos;
varying vec4 v_position;
varying vec3 v_normal;
uniform sampler2D u_tex;
uniform sampler2D u_depthTex;
uniform mat4 u_mvpMtx;
uniform mat4 u_invMVPMtx;
uniform vec3 u_eyePos;// = vec3(0.0, 0.6, 1.0);
vec3 GetPos(vec2 uv, float depth)
{
vec4 pos = u_invMVPMtx*(vec4(uv,depth,1.0)*2.0-1.0);
pos.xyz /= pos.w;
return pos.xyz;
}
vec3 GetUV(vec3 apos)
{
vec4 pVP = u_mvpMtx*vec4(apos,1.0);
pVP.xy = vec2(0.5,0.5)+vec2(0.5,0.5)*pVP.xy / pVP.w;
return vec3(pVP.xy,pVP.z/pVP.w);
}
vec4 u_camera = vec4(0.1,2.0,0.5,1.0);//near far fov aspect
float GetDepth(vec2 uv)
{
float depth = texture2D(u_depthTex,uv).r;
depth = 2.0 * u_camera.x * u_camera.y /
(u_camera.y + u_camera.x -
(depth*2.0-1.0)*(u_camera.y-u_camera.x));
return depth;
}
const float rayStepSize = 0.1;
vec2 v_uv;
vec3 raytrace(in vec3 reflectionVector, in float startDepth)
{
vec3 color = vec3(0.0);
float stepSize = rayStepSize;
float size = length(reflectionVector.xy);
reflectionVector = normalize(reflectionVector/size);
reflectionVector = reflectionVector * stepSize;
//Current sampling position is at current fragment
vec2 sampledPosition = v_uv;
//Current depth at current fragment
float currentDepth = startDepth;
//The sampled depth at the current sampling position
//float sampledDepth = linearizeDepth(texture2D(u_depthTexture, sampledPosition).x);
float sampledDepth = GetDepth(sampledPosition);
// Raytrace as long as in texture space of depth buffer (between 0 and 1)
while(sampledPosition.x <= 1.0 && sampledPosition.x >= 0.0 && sampledPosition.y <= 1.0 && sampledPosition.y >= 0.0)
{
//Update sampling position by adding reflection vector's xy and y components
sampledPosition = sampledPosition + reflectionVector.xy;
//Updating depth values
currentDepth = currentDepth + reflectionVector.z * startDepth;
//float sampledDepth = linearizeDepth( texture2D(u_depthTexture, sampledPosition).x);
float sampledDepth = GetDepth(sampledPosition);
//If current depth is greater than sampled depth of depth buffer, intersection is found
if(currentDepth > sampledDepth)
{
//Delta is for stop the raytracing after the first intersection is found
//Not using delta will create "repeating artifacts"
float delta = (currentDepth - sampledDepth);
if(delta < 0.003)
{
color = texture2D(u_tex, v_uv).rgb;
break;
}
}
}
return color;
}
#if 0
vec4 ssr()
{
vec3 reflectedColor = vec3(0.0);
//vec3 normal = normalize( texture2D(u_normalTexture, v_uv).xyz*2.0-1.0 );
vec3 normal = v_normal;
//Depth at current fragment
//float currDepth = linearizeDepth( texture2D(u_depthTex, v_uv).x );
float currDepth = GetDepth(v_uv);
vec3 pos = GetPos(v_uv,currDepth);
//Eye position, camera is at (0, 0, 0), we look along negative z, add near plane to correct parallax
vec3 eyePosition = normalize(pos-u_eyePos);// vec3(0.0, 0.0, 0.01) );
vec3 reflectionVector = reflect(eyePosition, normal);
reflectionVector= GetUV(reflectionVector);
//Call raytrace to get reflected color
reflectedColor = raytrace(reflectionVector, currDepth);
float nl = max(-dot(normal, eyePosition),0.0);
float fresnel = pow(1.0-nl,0.82);
return vec4(reflectedColor, 1.0);
}
#else
vec4 ssr()
{
//todo: normal buffer
vec3 normal = v_normal;
//vec3 pos = GetPos(uv, depth);
vec3 pos = v_position.xyz;
vec3 viewDir = normalize(pos-u_eyePos);
vec3 reflectDir = normalize(reflect(viewDir, normal));
vec3 currentRay = vec3(0.0);
vec3 nuv = vec3(0.0);
float L = 0.06;//???
for(int i = 0; i<10; i++){
currentRay = pos+reflectDir*L;
nuv = GetUV(currentRay);
float nd = texture2D(u_depthTex, nuv.xy).x;
vec3 newPos = GetPos(nuv.xy, nd);//2???
L = length(pos-newPos);
}
if(L>0.4)
return vec4(0.0);
vec4 cnuv = vec4(0.0);
cnuv = texture2D(u_tex, nuv.xy);
/*for(float x = -0.1; x<=0.1; x+=0.025){
cnuv += texture2D(u_tex, nuv.xy+vec2(x*L,0.0))*0.1;
}*/
float nl = max(-dot(normal, viewDir),0.0);
float fresnel = pow(1.0-nl,0.82);
//return vec4(normalize(currentRay),1.0);
//return vec4(vec3(pow(nuv.z,0.4)),1.0);
//return vec4(L*4.0);
return cnuv*fresnel*(1.0-L*2.0);
// return vec4(L*4.0);
}
#endif
void main()
{
vec2 uv = v_scrpos.xy/v_scrpos.w*0.5+0.5;
v_uv = uv;
vec4 col = texture2D(u_tex, uv);
//float depth = texture2D(u_depthTex, uv).x;
float depth = gl_FragCoord.z;
vec4 reflect = vec4(0.0);
if(depth<(texture2D(u_depthTex, uv).x+0.002))
{
reflect = ssr();
}
gl_FragColor = col+reflect;
//gl_FragColor = reflect;
//gl_FragColor = col*pow(depth, 10.0);
//gl_FragColor = vec4(reflectDir, 1.0);
}

19
assets/ssr/shaders/ssr.vs Normal file
View File

@ -0,0 +1,19 @@
#version 100
precision highp float;
attribute vec4 a_position;
attribute vec3 a_normal;
uniform mat4 u_mvpMtx;
varying vec4 v_scrpos;
varying vec4 v_position;
varying vec3 v_normal;
void main()
{
v_scrpos = u_mvpMtx * a_position;
v_position = a_position;
v_normal = a_normal;
gl_Position = u_mvpMtx * a_position;
}

View File

@ -0,0 +1,2 @@
1
base

Binary file not shown.

View File

@ -0,0 +1,3 @@
1
base

Binary file not shown.

View File

@ -0,0 +1,2 @@
light
basetexture.vtf

View File

@ -0,0 +1,2 @@
light
basetexture.vtf

View File

@ -0,0 +1,3 @@
light
materials/metal_patterned_01-l-color.dds
materials/metal_patterned_01-l-normal.dds

View File

@ -0,0 +1,2 @@
light
basetexture.vtf

Binary file not shown.

Binary file not shown.

Binary file not shown.

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,156 @@
1
-1 3 8 0 50 0
33
StaticModel sphere.nmf 30 40 70 0 0 0 0
Button
-2 1.5 3
enter_ship enter_ship
tp -20 0 3.5 15 20 0
Button
-19.5 1.5 8
leave_ship leave_ship
tp -8 1 3 15 270 0
Door
-20 1.2 4.65
door1 1 1.2 0.08
Button
-20 1.5 4.5
open_door1 open_door1
use door1
Light 2
-20.4 1.6 3.5
0.8 0.8 1
7
StaticModel sship1_s.nmf -16 0 -22 0 130 0 0
Light 2
-14 1 -25
1 0.55 0.4
8
Collider
-16.3 1 -21.6 0 130 0
1 1.8 0.8 3.5
StaticModel spaceport1_p.nmf -16 0 -14 0 90 0
0
StaticModel spaceport1_r.nmf -16 0 -14 0 90 0
0
Collider
-16 -0.1 -19.5 0 0 0
1 6 0.1 6.5
StaticModel map02.nmf
0 0 0 0 0 0
0
Collider
0 -0.1 0 0 0 0
1 10 0.1 10
Collider
-5 2 -6 0 0 0
1 2 2 3
Collider
6 2.5 -3 0 0 0
1 3 2.5 6
StaticModel map02.nmf
0 0 -20 0 0 0
0
Collider
0 -0.1 -20 0 0 0
1 10 0.1 10
Collider
-5 2 -26 0 0 0
1 2 2 3
Collider
6 2.5 -23 0 0 0
1 3 2.5 6
StaticModel cube.nmf
1 -0.1 -2.5 20 0 0
1 1 1 1
StaticModel bridge1.nmf
-20 0 0 0 0 0
0
StaticModel map01.nmf
-21 0 8.7 0 0 0
0
Collider
-20 -0.1 14 0 0 0
1 3 0.1 14
Collider
-20 2.1 14 0 0 0
1 3 0.1 14
Collider
-20 2 1 0 0 0
1 3 2 0.1
Collider
-20 0.5 2.5 0 0 0
1 0.5 0.5 0.5
Collider
-23 2 3 0 0 0
1 0.1 2 2
Collider
-17 2 3 0 0 0
1 0.1 2 2
Collider
-18 2 9.5 0 0 0
1 1 2 5
Collider
-22 2 9.5 0 0 0
1 1 2 5
Collider
-20 2 15 0 0 0
1 3 2 0.1
#stairs
StaticModel cube.nmf
-2.5 -0.8 0 0 0 0
1 1 1 1
StaticModel cube.nmf
-2.51 -0.6 -0.8 0 0 0
1 1 1 1
StaticModel cube.nmf
-2.52 -0.4 -1.6 0 0 0
1 1 1 1
StaticModel cube.nmf
-2.53 -0.2 -2.4 0 0 0
1 1 1 1
StaticModel cube.nmf
-2.54 0 -3.2 0 0 0
1 1 1 1
StaticModel cube.nmf
-4.5 -0.7 0 0 0 0
1 1 1 1
StaticModel cube.nmf
-4.51 -0.4 -0.8 0 0 0
1 1 1 1
StaticModel cube.nmf
-4.52 -0.1 -1.6 0 0 0
1 1 1 1
StaticModel cube.nmf
-4.53 0.2 -2.4 0 0 0
1 1 1 1
StaticModel cube.nmf
-4.54 0.5 -3.2 0 0 0
1 1 1 1
-20 0 3.5 15 60 0
5
StaticModel map02.nmf
0 0 0 0 0 0
0
StaticModel map02.nmf
0 0 -13.8 0 0 0
0
StaticModel city1.nmf
13 0 -13.8 0 0 0
0
StaticModel house-small.nmf
0 -1 -26 0 0 0
0

View File

@ -0,0 +1,8 @@
view tps
drawTouch 1
debugPhysics 0
drawBbox 0
startScene test
screenScale 1
pistOffs 0.1 -0.3 -0.3

View File

@ -0,0 +1,3 @@
1
base

View File

@ -0,0 +1,19 @@
modelName bridge1.nmf
modelPos 0 1 0
lightPos 1.1 7.1 -4
lightTarget 0 2 2
lightFOV 40
lightAspect 1
lightFar 12
lightNear 4
cameraPos 2.9 2.5 1.5
cameraRot 10 100 0
lightRes 512
volScale 1
debug 0
lightPos 0.4 3.1 -2
lightFOV 60
lightAspect 1.2
lightNear 0.2
lightFar 8

View File

@ -0,0 +1,114 @@
#version 100
precision highp float;
varying vec4 v_position;
varying vec3 v_viewDir;
varying vec4 v_coord;
uniform sampler2D u_lightDepth;
uniform sampler2D u_sceneDepth;
uniform mat4 u_lightMtx;
uniform mat4 u_invVPMtx;
uniform vec4 u_lightPosSize;
vec3 GetPos(vec2 uv, float depth)
{
vec4 pos = u_invVPMtx*(vec4(uv,depth,1.0)*2.0-1.0);
pos.xyz /= pos.w;
return pos.xyz;
}
vec3 GetLightUV(vec3 pos){
vec4 v = u_lightMtx * vec4(pos,1.0);
v.xyz /= v.w;
v.xyz = v.xyz*0.5+0.5;
return v.xyz;
}
float GetDist(vec3 pos){
vec3 luv = GetLightUV(pos);
float lightDepth = texture2D(u_lightDepth,luv.xy).r;
return luv.z-lightDepth;
}
float GetShadow(vec3 pos){
float shadow = GetDist(pos);
float atten = 1.0-clamp(length(u_lightPosSize.xyz-pos)/u_lightPosSize.w, 0.0, 1.0);
return float(shadow<0.001)*atten;
}
float GetPCF(vec3 pos){
vec3 luv = GetLightUV(pos);
float shadow = 25.0;
for(int x=-2; x<3; x++){
for(int y=-2; y<2; y++){
float lightDepth = texture2D(u_lightDepth,luv.xy+vec2(x,y)*0.002).r;
shadow -= float((luv.z-lightDepth)<0.003);
}
}
return shadow/25.0;
}
#define STEPS 128.0
float rand(float n){
return fract(sin(n) * 43758.5453123);
}
float rand(vec2 n) {
return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
return mix(rand(fl), rand(fl + 1.0), fc);
}
float noise(vec2 n) {
const vec2 d = vec2(0.0, 1.0);
vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}
void main(){
vec3 scr = v_coord.xyz/v_coord.w;
scr.xyz = scr.xyz*0.5+0.5;
float sceneDepth = texture2D(u_sceneDepth,scr.xy).r;
if(sceneDepth<scr.z)
discard;
vec3 start = v_position.xyz/v_position.w;
vec3 end = GetPos(scr.xy,sceneDepth);
float shadow = 0.0;
vec3 step = (end-start)/STEPS;
vec3 curPos = start;
for(int i=0;i<int(STEPS);i++){
curPos += step;
shadow += GetShadow(curPos);
}
shadow /= STEPS;
//if(GetShadow(end)<0.1)
// shadow-=0.3;
//shadow -= GetPCF(end)*0.4;
vec4 outc = vec4(shadow*0.5);
/*vec4 outc = vec4(shadow*0.5)*vec4(1.0,0.0,0.0,0.0)*(abs(noise(end.xy*3.0))*0.7+0.3);
if(abs(GetDist(end))<0.002){
outc = vec4(1.0,-1.0,-1.0,0.0)*10.0;
}*/
//gl_FragColor = vec4((sceneDepth-scr.z)*5.0);
//gl_FragColor = vec4(pow(scr.z,5.0));
//gl_FragColor = vec4(start,1.0);
//gl_FragColor = vec4(end,1.0);
//gl_FragColor = vec4(pow(sceneDepth,5.0));
//gl_FragColor = vec4(luv.zzz,1.0);
gl_FragColor = outc;
//gl_FragColor = vec4(pow(lightDepth,5.0));
//gl_FragColor = vec4(distance(start,end)*0.1);
}

View File

@ -0,0 +1,20 @@
#version 100
precision highp float;
attribute vec4 a_position;
varying vec4 v_position;
varying vec3 v_viewDir;
varying vec4 v_coord;
varying vec4 v_cameraPos;
uniform mat4 u_mvpMtx;
uniform mat4 u_modelMtx;
uniform vec3 u_cameraPos;
void main(){
gl_Position = u_mvpMtx * a_position;
v_coord = gl_Position;
v_position = (u_modelMtx*a_position);
v_viewDir = u_cameraPos - v_position.xyz;
}

View File

@ -0,0 +1,114 @@
#version 100
precision highp float;
varying vec4 v_position;
varying vec3 v_viewDir;
varying vec4 v_coord;
uniform sampler2D u_lightDepth;
uniform sampler2D u_sceneDepth;
uniform mat4 u_lightMtx;
uniform mat4 u_invVPMtx;
uniform vec4 u_lightPosSize;
uniform vec3 u_cameraPos;
vec3 GetPos(vec2 uv, float depth)
{
vec4 pos = u_invVPMtx*(vec4(uv,depth,1.0)*2.0-1.0);
pos.xyz /= pos.w;
return pos.xyz;
}
vec3 GetLightUV(vec3 pos){
vec4 v = u_lightMtx * vec4(pos,1.0);
v.xyz /= v.w;
v.xyz = v.xyz*0.5+0.5;
return v.xyz;
}
float GetDist(vec3 pos){
vec3 luv = GetLightUV(pos);
float lightDepth = texture2D(u_lightDepth,luv.xy).r;
return luv.z-lightDepth;
}
float GetShadow(vec3 pos){
float shadow = GetDist(pos);
float atten = 1.0-clamp(length(u_lightPosSize.xyz-pos)/u_lightPosSize.w, 0.0, 1.0);
return float(shadow<0.001)*atten;
}
float GetPCF(vec3 pos){
vec3 luv = GetLightUV(pos);
float shadow = 25.0;
for(int x=-2; x<3; x++){
for(int y=-2; y<2; y++){
float lightDepth = texture2D(u_lightDepth,luv.xy+vec2(x,y)*0.002).r;
shadow -= float((luv.z-lightDepth)<0.003);
}
}
return shadow/25.0;
}
#define STEPS 128.0
float rand(float n){
return fract(sin(n) * 43758.5453123);
}
float rand(vec2 n) {
return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
return mix(rand(fl), rand(fl + 1.0), fc);
}
float noise(vec2 n) {
const vec2 d = vec2(0.0, 1.0);
vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}
void main(){
vec3 scr = v_coord.xyz/v_coord.w;
scr.xyz = scr.xyz*0.5+0.5;
float sceneDepth = texture2D(u_sceneDepth,scr.xy).r;
vec3 start = u_cameraPos;
vec3 end = GetPos(scr.xy,sceneDepth);
float shadow = 0.0;
vec3 step = (end-start)/STEPS;
vec3 curPos = start;
for(int i=0;i<int(STEPS);i++){
curPos += step;
shadow += GetShadow(curPos);
}
shadow /= STEPS;
//if(GetShadow(end)<0.1)
// shadow-=0.3;
//shadow -= GetPCF(end)*0.4;
vec4 outc = vec4(shadow*0.5);
/*vec4 outc = vec4(shadow*0.5)*vec4(1.0,0.0,0.0,0.0)*(abs(noise(end.xy*3.0))*0.7+0.3);
if(abs(GetDist(end))<0.002){
outc = vec4(1.0,-1.0,-1.0,0.0)*10.0;
}*/
//gl_FragColor = vec4((sceneDepth-scr.z)*5.0);
//gl_FragColor = vec4(pow(scr.z,5.0));
//gl_FragColor = vec4(start,1.0);
//gl_FragColor = vec4(end,1.0);
//gl_FragColor = vec4(pow(sceneDepth,5.0));
//gl_FragColor = vec4(luv.zzz,1.0);
gl_FragColor = outc;
//gl_FragColor = vec4(pow(lightDepth,5.0));
//gl_FragColor = vec4(distance(start,end)*0.1);
}

14
demos/ComprTex/Android.mk Normal file
View File

@ -0,0 +1,14 @@
LOCAL_PATH := $(call my-dir)
ENGINE_DIR =../../nenuzhno-engine/
include $(CLEAR_VARS)
LOCAL_MODULE := nenuzhno-engine
LOCAL_CFLAGS := -Wall
LOCAL_C_INCLUDES := . ../libs/glm ../nenuzhno-engine
LOCAL_SRC_FILES := $(ENGINE_DIR)android_backend.cpp $(ENGINE_DIR)log.cpp $(ENGINE_DIR)system/FileSystem.cpp $(ENGINE_DIR)game/IGame.cpp \
$(ENGINE_DIR)graphics/gl_utils.cpp $(ENGINE_DIR)graphics/gl_ext.cpp $(ENGINE_DIR)graphics/glsl_prog.cpp $(ENGINE_DIR)graphics/texture.cpp $(ENGINE_DIR)graphics/vbo.cpp $(ENGINE_DIR)graphics/vao.cpp \
ComprTex.cpp
LOCAL_LDLIBS := -llog -lGLESv2 -lm -lEGL
include $(BUILD_SHARED_LIBRARY)

177
demos/ComprTex/ComprTex.cpp Normal file
View File

@ -0,0 +1,177 @@
#include "stdint.h"
#include <gtc/type_ptr.hpp>
#include "log.h"
#include "graphics/platform_gl.h"
#include "graphics/gl_utils.h"
#include "graphics/gl_ext.h"
#include "graphics/glsl_prog.h"
#include "graphics/ArrayBuffer.h"
#include "graphics/vao.h"
#include "graphics/texture.h"
#ifdef ANDROID
#include "GLES2/gl2ext.h"
#else
#define GL_ETC1_RGB8_OES 0x8D64
#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
#endif
#include "game/IGame.h"
class ComprTexGame : public IGame{
public:
void Created();
void Changed(int w, int h);
void Draw();
const char *GetGamedir(){
return "base";
}
};
IGame *CreateGame(){
return new ComprTexGame();
}
float quadVerts[] =
{
1,-1,
1, 1,
-1, 1,
-1,-1
};
int scrWidth = 0;
int scrHeight = 0;
float aspect = 1.0f;
glslProg progQuadTexture;
GLint u_quad_transform;
Texture etc1Texture;
Texture pvrTex;
VertexBufferObject vboQuad;
VertexArrayObject vaoQuad;
void ComprTexGame::Created()
{
CheckGLError("pre Created", __FILE__, __LINE__);
GLExtensions::Init();
progQuadTexture.CreateFromFile("quad", "col_tex");
u_quad_transform = progQuadTexture.GetUniformLoc("u_transform");
progQuadTexture.u_color = progQuadTexture.GetUniformLoc("u_color");
progQuadTexture.Use();
glUniform4f(progQuadTexture.u_color,1,1,1,1);
glUseProgram(0);
CheckGLError("Created shaders", __FILE__, __LINE__);
vboQuad.Create();
vboQuad.Upload(2*4*4, quadVerts);
vaoQuad.Create();
vaoQuad.Bind();
vboQuad.Bind();
vaoQuad.SetAttribute(0,2,GL_FLOAT,GL_FALSE,8,0);
vaoQuad.Unbind();
vboQuad.Unbind();
CheckGLError("Created meshes", __FILE__, __LINE__);
#if 0
GLubyte testTexData[] =
{
0,0,0, 255,255,255, 0,0,0, 255,255,255,
255,255,255, 0,0,0, 255,255,255, 0,0,0,
0,0,0, 255,255,255, 0,0,0, 255,255,255,
255,255,255, 0,0,0, 255,255,255, 0,0,0
};
etc1Texture.Create(4,4);
etc1Texture.Upload(0, GL_RGB, testTexData);
#else
GLubyte etc1Data[]={
0b01110111,
0b01110111,
0b01110111,
0b11111100,
0b00000110,
0b10100010,
0b00001110,
0b11101110
};
etc1Texture.Create(4,4);
etc1Texture.UploadCompressed(GL_COMPRESSED_RGB8_ETC2, 8, etc1Data);//GL_ETC1_RGB8_OES
CheckGLError("Upload etc1", __FILE__, __LINE__);
#endif
#if 0
/*For PVRTC 4BPP formats the imageSize is calculated as:
( max(width, 8) * max(height, 8) * 4 + 7) / 8
For PVRTC 2BPP formats the imageSize is calculated as:
( max(width, 16) * max(height, 8) * 2 + 7) / 8*/
//pvrtc block word (reversed)
//1 col a mode, 555 col a, 1 col b mode, 554 col b, 1 mode, 32 modul table (2b per sample)
GLubyte pvrData[32]={
255,255,0,0,0b11111110,0b11111111,0b00000000,0b11111100,
255,255,0,0,0b11100000,0b11111111,0b11100000,0b10000011,
255,255,0,0,0b00011110,0b11111100,0b00011111,0b10000000,
255,255,0,0,0b11111110,0b10000011,0b00000000,0b10000000
/*
255,170,85,0,0b11111110,0b11111111,0b00000000,0b11111100,
0,85,170,255,0b11100000,0b11111111,0b11100000,0b10000011,
255,170,85,0,0b00011110,0b11111100,0b00011111,0b10000000,
0,85,170,255,0b11111110,0b10000011,0b00000000,0b10000000
*/
};
pvrTex.Create(8,8);
pvrTex.UploadCompressed(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 32, pvrData);
CheckGLError("Upload pvr", __FILE__, __LINE__);
#endif
glBindTexture(GL_TEXTURE_2D, 0);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
// glEnable(GL_CULL_FACE);
CheckGLError("Created", __FILE__, __LINE__);
}
void ComprTexGame::Changed(int w, int h)
{
scrWidth = w;
scrHeight = h;
glViewport(0, 0, w, h);
aspect = w/(float)h;
}
void ComprTexGame::Draw()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
CheckGLError("Clear", __FILE__, __LINE__);
vaoQuad.Bind();
CheckGLError("Bind plane", __FILE__, __LINE__);
progQuadTexture.Use();
glUniform4f(u_quad_transform, 0, 0, 0.8, 0.8*aspect);
CheckGLError("Use shader", __FILE__, __LINE__);
etc1Texture.Bind();
//pvrTex.Bind();
CheckGLError("Bind texture", __FILE__, __LINE__);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
CheckGLError("Draw plane", __FILE__, __LINE__);
vaoQuad.Unbind();
glBindTexture(GL_TEXTURE_2D, 0);
glDisableVertexAttribArray(0);
CheckGLError("Draw", __FILE__, __LINE__);
}

View File

@ -0,0 +1,17 @@
TARGET = ComprTex
ENGINE_DIR = ../../nenuzhno-engine
all: $(TARGET)
INCLUDES = -I. -I$(ENGINE_DIR) -I../../../../Libs/gl/glm/glm -I../../../../Libs/gl/glew-2.1.0/include
CPPFLAGS = -Wall -ggdb
LDFLAGS = -static-libgcc -static-libstdc++ -ggdb
LIBS = -lnenuzhno-engine -L$(ENGINE_DIR) -lGL -lglfw3 -lX11 -lXrandr -lXinerama -lXcursor -lpthread -ldl -lGLEW -L../../../../Libs/gl/glfw-3.2.1_src/lib -L../../../../Libs/gl/glew-2.1.0/lib
SRCS = ComprTex.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

View File

@ -0,0 +1,18 @@
TARGET = ../../assets/ComprTex.exe
ENGINE_DIR = ../..
LIBS_DIR = ../../../../../Libs
all: $(TARGET)
INCLUDES = -I. -I$(ENGINE_DIR)/src -I$(LIBS_DIR)/gl/glm/glm -I$(LIBS_DIR)/gl/glew-2.0.0/include
CPPFLAGS = -Wall -ggdb -m32
LDFLAGS = -static-libgcc -static-libstdc++ -ggdb -m32
LIBS = -lnenuzhno-engine -L$(ENGINE_DIR)/bin -lopengl32 -lglfw3 -lgdi32 -lglew32 -L$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/lib-mingw-w64 -L$(LIBS_DIR)/gl/glew-2.0.0/lib
SRCS = ComprTex.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/bin/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

15
demos/SSR/Android.mk Normal file
View File

@ -0,0 +1,15 @@
LOCAL_PATH := $(call my-dir)
ENGINE_DIR =../../nenuzhno-engine/
include $(CLEAR_VARS)
LOCAL_MODULE := nenuzhno-engine
LOCAL_CFLAGS := -Wall
LOCAL_C_INCLUDES := . ../libs/glm ../nenuzhno-engine
LOCAL_SRC_FILES := $(ENGINE_DIR)android_backend.cpp $(ENGINE_DIR)log.cpp $(ENGINE_DIR)system/FileSystem.cpp $(ENGINE_DIR)game/IGame.cpp $(ENGINE_DIR)/cull/frustum.cpp \
$(ENGINE_DIR)graphics/glsl_prog.cpp $(ENGINE_DIR)graphics/gl_utils.cpp $(ENGINE_DIR)graphics/texture.cpp $(ENGINE_DIR)graphics/vbo.cpp $(ENGINE_DIR)graphics/fbo.cpp \
$(ENGINE_DIR)resource/mesh_loader.cpp \
$(ENGINE_DIR)renderer/mesh.cpp $(ENGINE_DIR)renderer/camera.cpp \
ssr.cpp
LOCAL_LDLIBS := -llog -lGLESv2 -lm -lEGL
include $(BUILD_SHARED_LIBRARY)

23
demos/SSR/Makefile.mingw Normal file
View File

@ -0,0 +1,23 @@
TARGET = ../../assets/ssr.exe
ENGINE_DIR = ../..
LIBS_DIR = ../../../../../Libs
all: $(TARGET)
INCLUDES = -I. -I$(LIBS_DIR)/gl/glew-2.0.0/include -I$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/include -I$(LIBS_DIR)/gl/glm/glm -I$(ENGINE_DIR)/src
CPPFLAGS = -Wall -ggdb -m32
LIBS = -lnenuzhno-engine -lglfw3 -lglew32 -lopengl32 -lgdi32 -L$(ENGINE_DIR)/bin -L$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/lib-mingw-w64 -L$(LIBS_DIR)/gl/glew-2.0.0/lib
LDFLAGS = -static-libgcc -static-libstdc++ -m32
SRCS = ssr.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/bin/libnenuzhno-engine.a
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
clean:
$(RM) $(OBJS) $(TARGET)
rebuild: clean all

252
demos/SSR/ssr.cpp Normal file
View File

@ -0,0 +1,252 @@
#include <gtc/type_ptr.hpp>
#include "log.h"
#include "graphics/platform_gl.h"
#include "graphics/gl_utils.h"
#include "graphics/glsl_prog.h"
#include "graphics/ArrayBuffer.h"
#include "graphics/vao.h"
#include "renderer/mesh.h"
#include "graphics/texture.h"
#include "graphics/fbo.h"
#include "renderer/camera.h"
#include "game/IGame.h"
class SSRGame : public IGame{
public:
void Created();
void Changed(int w, int h);
void Draw();
const char *GetGamedir(){
return "ssr";
}
};
IGame *CreateGame(){
return new SSRGame();
}
GLfloat vertices[] =
{
0.5f, 0.0f, 0.5f, 0,1,0, 1,1,
0.5f, 0.0f, -0.5f, 0,1,0, 1,0,
-0.5f, 0.0f, -0.5f, 0,1,0, 0,0,
-0.5f, 0.0f, 0.5f, 0,1,0, 0,1
};
int scrWidth = 0;
int scrHeight = 0;
glslProg simpleProg;
glslProg texProg;
glslProg ssrProg;
int u_eyePos=-1;
Mesh *plane;
Mesh *cube;
VertexBufferObject *vboQuad;
VertexArrayObject vaoQuad;
VertexArrayObject vaoSO;
FrameBufferObject fbo1;
FrameBufferObject fboBack;
Texture testTex;
Camera camera;
glm::mat4 mvpMtx(1);
void UnbindFBO()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, scrWidth, scrHeight);
}
class SceneObject
{
public:
Mesh *mesh;
glm::mat4 modelMtx;
SceneObject(){}
SceneObject(Mesh *msh, glm::mat4 mtx)
{
mesh = msh;
modelMtx = mtx;
}
void Draw(GLint u_mvpMtx)
{
mvpMtx = camera.projMtx * camera.viewMtx * modelMtx;
glUniformMatrix4fv(u_mvpMtx,1,GL_FALSE,glm::value_ptr(mvpMtx));
mesh->Bind();
mesh->Draw();
mesh->Unbind();
}
};
SceneObject planeSO;
SceneObject cubeSO;
void SSRGame::Created()
{
simpleProg.CreateFromFile("simple", "simple");
simpleProg.u_mvpMtx = simpleProg.GetUniformLoc("u_mvpMtx");
if(texProg.CreateFromFile("generic", "col_tex"))
{
texProg.u_mvpMtx = texProg.GetUniformLoc("u_mvpMtx");
texProg.u_color = texProg.GetUniformLoc("u_color");
texProg.Use();
glUniform4f(texProg.u_color, 1,1,1,1);
}
ssrProg.CreateFromFile("ssr", "ssr");
ssrProg.u_mvpMtx = ssrProg.GetUniformLoc("u_mvpMtx");
ssrProg.u_invModelMtx = ssrProg.GetUniformLoc("u_invMVPMtx");
u_eyePos = ssrProg.GetUniformLoc("u_eyePos");
GLint u_depthTex = ssrProg.GetUniformLoc("u_depthTex");
ssrProg.Use();
glUniform1i(u_depthTex, 1);
glUseProgram(0);
CheckGLError("Created shaders", __FILE__, __LINE__);
plane = new MeshFBO_N3_T2(vertices, 4, GL_TRIANGLE_FAN);
cube = LoadMeshFile("cube", true);
vaoSO.Create();
float quadVerts[] ={
1,-1,1,0,
1, 1,1,1,
-1, 1,0,1,
-1,-1,0,0
};
vboQuad = new VertexBufferObject();
vboQuad->Create();
vboQuad->Upload(4*4*4, quadVerts);
vaoQuad.Create();
vaoQuad.Bind();
vboQuad->Bind();
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,16,0);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,16,(void*)8);
vboQuad->Unbind();
vaoQuad.Unbind();
CheckGLError("Created meshes", __FILE__, __LINE__);
testTex.Create(4,4);
GLubyte testTexData[] =
{
0,0,0, 255,255,255, 0,0,0, 255,255,255,
255,255,255, 0,0,0, 255,255,255, 0,0,0,
0,0,0, 255,255,255, 0,0,0, 255,255,255,
255,255,255, 0,0,0, 255,255,255, 0,0,0
};
testTex.Upload(0, GL_RGB, testTexData);
planeSO = SceneObject(plane,glm::mat4(1.0));
cubeSO = SceneObject(cube,glm::scale(glm::translate(glm::mat4(1.0),glm::vec3(0,0.1,0)),glm::vec3(0.2)));
camera.pos = glm::vec3(0,0.6f,1);
camera.rot = glm::vec3(30,0,0);
camera.UpdateView();
fbo1.Create();
fbo1.CreateTexture(64, 64, GL_LINEAR);
fbo1.CreateDepthTexture();
fboBack.Create();
fboBack.CreateTexture(256,256);
CheckGLError("Created fbo", __FILE__, __LINE__);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glEnable(GL_CULL_FACE);
CheckGLError("Created", __FILE__, __LINE__);
}
void SSRGame::Changed(int w, int h)
{
scrWidth = w;
scrHeight = h;
glViewport(0, 0, w, h);
float aspect = w/(float)h;
camera.UpdateProj(75.0f, aspect, 0.1f, 2.0f);
fbo1.Resize(w,h);
CheckGLError("Changed", __FILE__, __LINE__);
}
float a = 0;
void SSRGame::Draw()
{
a+=0.02;
camera.pos = glm::vec3(glm::sin(a),0.6f,glm::cos(a));
camera.rot = glm::vec3(30,glm::degrees(a),0);
camera.UpdateView();
fbo1.Bind();
CheckGLError("Bind fbo", __FILE__, __LINE__);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
CheckGLError("Clear", __FILE__, __LINE__);
vaoSO.Bind();
glEnableVertexAttribArray(0);
glEnable(GL_DEPTH_TEST);
glEnableVertexAttribArray(2);
texProg.Use();
testTex.Bind();
cubeSO.Draw(texProg.u_mvpMtx);
glDisableVertexAttribArray(2);
CheckGLError("Draw cube", __FILE__, __LINE__);
simpleProg.Use();
planeSO.Draw(simpleProg.u_mvpMtx);
CheckGLError("Draw plane", __FILE__, __LINE__);
vaoSO.Unbind();
#if 1
glDisable(GL_DEPTH_TEST);
//UnbindFBO();
fboBack.Bind();
glClear(GL_COLOR_BUFFER_BIT);
texProg.Use();
glUniformMatrix4fv(texProg.u_mvpMtx,1,GL_FALSE,glm::value_ptr(glm::mat4(1.0f)));
fbo1.BindTexture();
vaoQuad.Bind();
glDrawArrays(GL_TRIANGLE_FAN,0,4);
vaoQuad.Unbind();
ssrProg.Use();
glm::mat4 invMVPMtx = glm::inverse(camera.projMtx * camera.viewMtx);
glUniformMatrix4fv(ssrProg.u_invModelMtx,1,GL_FALSE,glm::value_ptr(invMVPMtx));
glUniform3fv(u_eyePos,1,&camera.pos.x);
glActiveTexture(GL_TEXTURE1);
fbo1.BindDepthTexture();
glActiveTexture(GL_TEXTURE0);
fbo1.BindTexture();
vaoSO.Bind();
glEnableVertexAttribArray(1);
planeSO.Draw(ssrProg.u_mvpMtx);
glDisableVertexAttribArray(1);
UnbindFBO();
glClear(GL_COLOR_BUFFER_BIT);
texProg.Use();
glUniformMatrix4fv(texProg.u_mvpMtx,1,GL_FALSE,glm::value_ptr(glm::mat4(1.0f)));
fboBack.BindTexture();
vboQuad->Bind();
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,16,0);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,16,(void*)8);
glEnableVertexAttribArray(2);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisableVertexAttribArray(2);
vboQuad->Unbind();
glBindTexture(GL_TEXTURE_2D, 0);
glDisableVertexAttribArray(0);
vaoSO.Unbind();
#endif
CheckGLError("Draw", __FILE__, __LINE__);
}

View File

@ -0,0 +1,18 @@
LOCAL_PATH := $(call my-dir)
ENGINE_DIR =../nenuzhno-engine/
include $(CLEAR_VARS)
LOCAL_MODULE := nenuzhno-engine
LOCAL_CFLAGS := -Wall
LOCAL_C_INCLUDES := . ../libs/glm ../nenuzhno-engine
LOCAL_SRC_FILES := $(ENGINE_DIR)android_backend.cpp $(ENGINE_DIR)log.cpp $(ENGINE_DIR)system/FileSystem.cpp $(ENGINE_DIR)game/IGame.cpp $(ENGINE_DIR)/cull/frustum.cpp $(ENGINE_DIR)/cull/BoundingBox.cpp $(ENGINE_DIR)scene/Scene.cpp \
$(ENGINE_DIR)graphics/gl_utils.cpp $(ENGINE_DIR)graphics/glsl_prog.cpp $(ENGINE_DIR)graphics/texture.cpp $(ENGINE_DIR)graphics/vbo.cpp $(ENGINE_DIR)graphics/fbo.cpp \
$(ENGINE_DIR)renderer/renderer.cpp $(ENGINE_DIR)renderer/camera.cpp $(ENGINE_DIR)renderer/mesh.cpp $(ENGINE_DIR)renderer/Model.cpp $(ENGINE_DIR)renderer/font.cpp \
$(ENGINE_DIR)resource/ResourceManager.cpp $(ENGINE_DIR)resource/vtf_loader.cpp $(ENGINE_DIR)resource/dds_loader.cpp $(ENGINE_DIR)resource/mesh_loader.cpp $(ENGINE_DIR)resource/nmf_loader.cpp \
star-fleet.cpp input.cpp Ship.cpp Explosion.cpp Projectile.cpp
# $(ENGINE_DIR)renderer/vtf_loader.cpp \
# renderer/progs_manager.cpp renderer/material.cpp renderer/render_list.cpp
LOCAL_LDLIBS := -llog -lGLESv2 -lm -lEGL
LOCAL_STATIC_LIBRARIES =
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,25 @@
#include <gtc/matrix_transform.hpp>
#include "entity.h"
Explosion::Explosion(glm::vec3 pos, float aSize): Entity(){
dynamic = true;
type=eExpl;
life=0;
position=pos;
size=aSize;
modelMtx = glm::translate(glm::mat4(1),position);
displayMtx = glm::scale(modelMtx,glm::vec3(size));
}
void Explosion::Update(float deltaTime){
life+=deltaTime;
if(life>1.0f){
remove = true;
return;
}
displayMtx = glm::scale(modelMtx,glm::vec3(size*pow((1.0-life),3.0)));
}

View File

@ -0,0 +1,29 @@
ENGINE_DIR = ../..
TARGET := $(ENGINE_DIR)/assets/StarFleet.exe
LIBS_DIR = ../../../../../Libs
all: $(TARGET)
INCLUDES = -I. -I$(LIBS_DIR)/gl/glm/glm -I$(LIBS_DIR)/gl/glew-2.0.0/include -I$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/include -I$(ENGINE_DIR)/src
CPPFLAGS = -Wall -ggdb -m32
LDFLAGS = -static-libgcc -static-libstdc++ -ggdb -m32
LIBS = -lnenuzhno-engine -lglfw3 -lglew32 -lopengl32 -lgdi32 -L$(ENGINE_DIR)/bin -L$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/lib-mingw-w64 -L$(LIBS_DIR)/gl/glew-2.0.0/lib
SRCS = star-fleet.cpp input.cpp Ship.cpp Explosion.cpp Projectile.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/bin/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
clean:
$(RM) $(OBJS) $(TARGET)
rebuild: clean all
obj/star-fleet.o: entity.h
obj/input.o: entity.h
obj/Ship.o: entity.h
obj/Explosion.o: entity.h
obj/Projectile.o: entity.h

View File

@ -0,0 +1,34 @@
#include <gtc/matrix_transform.hpp>
#include "entity.h"
void TraceLine(Projectile *proj, float deltaTime);
Projectile::Projectile(Entity *s,float aDamage): Entity()
{
dynamic = true;
type = eProj;
life = 0;
shooter = s;
damage = aDamage;
}
void Projectile::Update(float deltaTime)
{
if(remove)
return;
life+=deltaTime;
if(life>4)
{
remove = true;
CreateExplosion(this,0.5f);
return;
}
modelMtx = glm::translate(glm::mat4(1),position);
modelMtx = glm::rotate(modelMtx,glm::radians(angles.y),glm::vec3(0,1,0));
modelMtx = glm::rotate(modelMtx,glm::radians(angles.x),glm::vec3(1,0,0));
position += /*glm::mat3(modelMtx)**/velocity*deltaTime;
displayMtx = glm::scale(modelMtx,glm::vec3(0.02,0.02,0.1));
TraceLine(this,deltaTime);
}

126
demos/StarFleet/Ship.cpp Normal file
View File

@ -0,0 +1,126 @@
#include <gtc/matrix_transform.hpp>
#include <gtc/random.hpp>
#include "entity.h"
#include "log.h"
#include "renderer/renderer.h"
Ship::Ship(): Entity(),gun(10,6.5f,20,0.35f,0.05f){
dynamic = true;
type = eShip;
state = eShipState_Idle;
lastShot = 0;
hp = 100;
t = 0;
target = 0;
targetPos = glm::vec3(0);
isDead = false;
bbox = BoundingBox(glm::vec3(-0.6f,-0.5f,-0.8f),glm::vec3(0.6f,0.5f,0.8f));
}
void Ship::Update(float deltaTime){
lastShot += deltaTime;
t -= deltaTime;
if(hp <= 0.0f){
//isDead = true;
return;
}
modelMtx = glm::translate(glm::mat4(1),position);
modelMtx = glm::rotate(modelMtx,glm::radians(angles.y),glm::vec3(0,1,0));
modelMtx = glm::rotate(modelMtx,glm::radians(angles.x),glm::vec3(1,0,0));
if(state != eShipState_Idle){
glm::vec3 forward = glm::normalize(glm::mat3(modelMtx)[2]);
position += glm::mat3(modelMtx)*velocity*deltaTime;
glm::vec3 da;
if(target&&target->isDead)
target=0;
//todo find new target
if(target){
toEnemy = target->position - position;
float dist = glm::length(toEnemy);
if(dist > 2.0)
velocity = glm::vec3(0,0,2);
else
velocity = glm::vec3(0,0,1);
//advance aiming
toEnemy = glm::normalize(target->position+(normalize(glm::vec3(target->modelMtx[2]))*target->velocity.z*(dist/gun.speed))-position);
if(state==eShipState_Attack&&lastShot>gun.rate){
if(dist<gun.range && glm::dot(forward,toEnemy)>0.95){
Shoot();
lastShot=0;
}
}
newAngles.x = glm::degrees(glm::asin(-toEnemy.y));
newAngles.y = glm::degrees(glm::atan(toEnemy.x,toEnemy.z));
}else{
if(t<0){
t = glm::linearRand(2.0f,5.0f);
//newAngles = glm::sphericalRand(180.0f);
targetPos=glm::ballRand(50.0f);
glm::vec3 newDir = normalize(targetPos-position);
newAngles.x = glm::degrees(glm::asin(-newDir.y));
newAngles.y = glm::degrees(glm::atan(newDir.x,newDir.z));
newAngles.z = 0;
}
}
//angles = newAngles;
da = newAngles-angles;
/*if(da.y>180)
da.y-=180;
if(da.y<-180)
da.y+=180;*/
if(abs(da.y)>180){
da.y-= ((int)da.y)/180*180;
}
da = glm::clamp(da,glm::vec3(-5.0f),glm::vec3(5.0f));
//dy = glm::clamp(y-angles.y,-5.0f,+5.0f);
angles += da*deltaTime*20.0f;
//angles.y += dy*deltaTime*20.0f;
}
displayMtx = glm::rotate(glm::scale(modelMtx,glm::vec3(0.1)),glm::radians(-90.0f),glm::vec3(0,1,0));
}
void Ship::Shoot()
{
//pew
CreateProjectile(this,(toEnemy+glm::sphericalRand(gun.spread))*gun.speed,gun.damage);
}
void Ship::Hit(float d)
{
hp-=d;
if(hp<=0.0)
{
//Log("Ship %p dead\n",this);
CreateExplosion(this,2.0f);
//isDead = true;
//todo respawn
hp = 100;
position = glm::ballRand(12.0f);//glm::vec3(0.0f);
angles = glm::vec3(0.0f);
}
}
Asteroid::Asteroid(glm::vec3 pos,float s){
dynamic=true;
position = pos;
size = s;
ang = true;
modelMtx = glm::translate(glm::mat4(size),pos);
displayMtx = modelMtx;
}
using glm::abs;
void Asteroid::Update(float deltaTime){
position += velocity*deltaTime;
if(abs(position.x)>300||abs(position.y)>300||abs(position.z)>300){
position = glm::ballRand(250.0f);
}
angles.x += ang*deltaTime;
modelMtx = glm::translate(glm::mat4(size),position);
modelMtx = glm::rotate(modelMtx,glm::radians(angles.x),glm::vec3(0.8,0.3,0.5));
displayMtx = modelMtx;
}

20
demos/StarFleet/TODO.txt Normal file
View File

@ -0,0 +1,20 @@
UI
change font+
pause menu+
settings
HUD-
Gameplay
controll
better AI
more weapons
more ships
Graphics
better explosion
better models
environment
lighting
rework renderer-
Other
fix collision+
sounds

122
demos/StarFleet/entity.h Normal file
View File

@ -0,0 +1,122 @@
#pragma once
#include <mat4x4.hpp>
#include <vec3.hpp>
#include "cull/Boundingbox.h"
#include "scene/Scene.h"
class IRenderer;
class Entity;
void CreateProjectile(Entity *shooter,glm::vec3 dir,float damage);
void CreateExplosion(Entity *owner,float size);
enum entType{
eNone,
eExpl,
eProj,
eShip
};
class Entity: public SceneObject
{
public:
glm::mat4 displayMtx;
glm::vec3 velocity;
glm::vec3 position;
glm::vec3 angles;
bool remove;
int type;
Entity(){
type=eNone;
remove=false;
modelMtx=glm::mat4(1.0f);
displayMtx=glm::mat4(1.0f);
}
virtual ~Entity(){}
virtual void Update(float deltaTime){}
};
class Asteroid: public Entity{
public:
Asteroid(glm::vec3 pos, float size);
virtual void Update(float deltaTime);
virtual void Draw(IRenderer *r);
float size;
float ang;
};//in ship.cpp
class Explosion: public Entity
{
public:
Explosion(glm::vec3 pos, float aSize);
float life;
float size;
virtual void Update(float deltaTime);
virtual void Draw(IRenderer *r);
};
class Projectile: public Entity
{
public:
float life;
float damage;
Entity *shooter;
Projectile(Entity *s,float damage);
~Projectile(){}
virtual void Update(float deltaTime);
virtual void Draw(IRenderer *r);
};
struct shipGun_t{
float range;
float speed;
float damage;
float rate;
float spread;
shipGun_t(float aRange, float aSpeed,float aDamage,float aRate, float aSpread){
range = aRange;
speed = aSpeed;
damage = aDamage;
rate = aRate;
spread = aSpread;
}
};
enum eShipState
{
eShipState_Idle,
eShipState_Pursue,
eShipState_Attack,
//eShipState_LastEnum
};
class Ship: public Entity
{
public:
eShipState state;
float lastShot;
float hp;
float t;
Ship *target;
glm::vec3 targetPos;
glm::vec3 toEnemy;
bool isDead;
glm::vec3 newAngles;
BoundingBox bbox;
shipGun_t gun;
Ship();
~Ship(){}
virtual void Update(float deltaTime);
virtual void Draw(IRenderer *r);
void Shoot();
void Hit(float d);
};

70
demos/StarFleet/input.cpp Normal file
View File

@ -0,0 +1,70 @@
#include "button.h"
#include "log.h"
#include "star-fleet.h"
extern float aspect;
extern Button bPause;
extern Button bResume;
void Button::Update(){
if(!active || !func)
return;
if(pressed){
pressed = false;
func();
}
}
Button::Button(float nx, float ny, float nw, float nh, bool adjust):
x(nx),y(ny),w(nw),h(nh),text(0),active(true),pressed(false)
{
if(adjust){
if(aspect>1)
h*=aspect;
else
w/=aspect;
}
//Log("Created button %f %f %f %f\n",x,y,w,h);
}
Button::Button(float nx, float ny, float nw, float nh, const char *t, bool adjust):
x(nx),y(ny),w(nw),h(nh),text(t),active(true),pressed(false)
{
if(adjust)
w/=aspect;
//Log("Created text button %f %f %f %f %s\n",x,y,w,h,t);
}
/*
bool Button::Hit(float tx, float ty)
{
if(!active)
return false;
if(tx>x+w||tx<x)
return false;
if(ty>y+h||ty<y)
return false;
pressed = true;
return true;
}*/
#ifndef ANDROID
#include <GLFW/glfw3.h>
void StarFleetGame::OnKey(int key, int scancode, int action, int mods)
{
if(action==GLFW_PRESS){
if(key==GLFW_KEY_ESCAPE){
if(gameState==eGameState_Play)
bPause.pressed = true;
else if(gameState==eGameState_Pause)
bResume.pressed = true;
}
}
}
#else
void StarFleetGame::OnKey(int key, int scancode, int action, int mods)
{
}
#endif

View File

@ -0,0 +1,528 @@
#include <cstdlib>
#include <cstdio>
#include <vector>
using namespace std;
#include <mat4x4.hpp>
#include <gtc/type_ptr.hpp>
#include <gtc/random.hpp>
#include "log.h"
#include "engine.h"
#include "game/IGame.h"
#include "resource/ResourceManager.h"
#include "renderer/renderer.h"
#include "graphics/platform_gl.h"
#include "graphics/gl_utils.h"
#include "graphics/glsl_prog.h"
#include "renderer/mesh.h"
#include "graphics/texture.h"
#include "renderer/camera.h"
#include "renderer/font.h"
#include "renderer/Material.h"
#include "button.h"
#include "entity.h"
#include "star-fleet.h"
StarFleetGame *gGame=0;
IGame *CreateGame(){
gGame = new StarFleetGame();
return gGame;
}
eGameState gameState = eGameState_Menu;
glslProg starboxProg;
Texture starboxTex;
Model *modelShip;
Model *modelCube;
//Mesh *shipMesh;
Texture shipTex;
TexMaterial matLight(&shipTex,false);
#define SHIP_COUNT 10
Ship *ships[SHIP_COUNT];
vector<Entity *> entities;
//menu buttons
std::vector<Button*> buttons;
//start
Button bNewGame;
Button bQuit;
//game
Button bPause;
//pause
Button bResume;
void NewGame();
void Quit();
void Pause();
void Resume();
void UpdateButtons()
{
bNewGame = Button(0.1,0.3,0.5,0.1,"New game");
bQuit = Button(0.1,0.6,0.5,0.1,"Quit");
bPause = Button(0.75,0.02,0.2,0.1,"[=] Pause");
bResume = Button(0.1,0.3,0.5,0.1,"Resume");
bNewGame.func=NewGame;
bPause.func=Pause;
bQuit.func=Quit;
bResume.func=Resume;
}
void ChangeState(eGameState s){
gameState = s;
for(uint32_t i=0; i<buttons.size(); i++){
buttons[i]->active = false;
}
switch(s){
case eGameState_Menu:
bNewGame.active = true;
bQuit.active = true;
break;
case eGameState_Play:
bPause.active = true;
break;
case eGameState_Pause:
bQuit.active = true;
bResume.active = true;
break;
}
}
void StartMenu()
{
buttons.clear();
buttons.push_back(&bNewGame);
buttons.push_back(&bPause);
buttons.push_back(&bQuit);
buttons.push_back(&bResume);
//TODO remove!
gGame->renderer->AddButton(&bNewGame);
gGame->renderer->AddButton(&bPause);
gGame->renderer->AddButton(&bQuit);
gGame->renderer->AddButton(&bResume);
//UpdateButtons(); //in Changed()
ChangeState(eGameState_Menu);
}
void NewGame()
{
ChangeState(eGameState_Play);
if(!entities.empty())
EngineError("Game already started");
srand(time(0));
for(int i=0; i<SHIP_COUNT; i++)
{
Ship *ship = new Ship();
ship->position = glm::vec3(glm::sin(i*0.85f)*5.0,0,-i*1.5f);
ship->velocity = glm::vec3(0,0,2.0f);//glm::sphericalRand(0.2f);
ship->angles = glm::sphericalRand(180.0f);
ship->state = (eShipState)((i%2)+1);
if(i%2)
ship->target = ships[i-1];
entities.push_back(ship);
ships[i] = ship;
gGame->scene->AddObject(ship);
}
ships[1]->gun = shipGun_t(16,20.0f,4,0.04f,0.04f);
//ships[1]->target = entities[2];
gGame->camera.pos = glm::vec3(0,1.6f,2);
gGame->camera.rot = glm::vec3(30,0,0);
gGame->camera.UpdateView();
for(int i=0; i<1000; i++){
Asteroid *obj = new Asteroid(glm::ballRand(250.0f),glm::linearRand(0.05f,5.0f));
if(i<600){
obj->velocity = glm::ballRand(20.0f);
obj->ang = glm::linearRand(-40,40);
}
gGame->scene->AddObject(obj);
}
}
void Quit(){
exit(0);
}
void Pause(){
ChangeState(eGameState_Pause);
}
void Resume(){
ChangeState(eGameState_Play);
}
void StarFleetGame::Created()
{
Log("Init nenuzhno engine. StarFleet\n");
resMan = new ResourceManager();
resMan->Init();
renderer = CreateRenderer();
renderer->Init(RENDERER_GUI|RENDERER_LIGHT,resMan);
scene = new Scene();
renderer->SetScene(scene);
starboxProg.CreateFromFile("skybox","skybox");
starboxProg.u_mvpMtx = starboxProg.GetUniformLoc("u_mvpMtx");
glUseProgram(0);
CheckGLError("Created shaders", __FILE__, __LINE__);
GLubyte testTexData[] =
{
63,63, 255,255, 31,31, 255,255,
63,63, 255,255, 31,31, 255,255,
255,255, 63,63, 255,255, 31,31,
255,255, 63,63, 255,255, 31,31,
31,31, 255,255, 63,63, 255,255,
31,31, 255,255, 63,63, 255,255,
255,255, 31,31, 255,255, 63,63,
255,255, 31,31, 255,255, 63,63
};
shipTex.Create(8,8);
shipTex.SetFilter(GL_LINEAR, GL_LINEAR);
shipTex.Upload(0, GL_LUMINANCE, testTexData);
resMan->AddMaterial("light",&matLight);
GLubyte *starboxData = new GLubyte[64*64];
memset(starboxData,0,64*64);
starboxData[75]=255;
starboxData[130]=255;
starboxData[406]=255;
starboxData[625]=255;
starboxData[1307]=255;
starboxData[3506]=255;
starboxData[4002]=255;
starboxData[2383]=255;
starboxTex.target = GL_TEXTURE_CUBE_MAP;
starboxTex.Create(64,64);
starboxTex.SetFilter(GL_LINEAR, GL_LINEAR);
for(int i=0; i<6; i++)
{
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_LUMINANCE, 64, 64, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, starboxData);
}
delete[] starboxData;
//TODO: Move to StartGame?
scene->skyBox = &starboxTex;
CheckGLError("Created texture", __FILE__, __LINE__);
//shipMesh = new MeshFBO_N3_T2(vertices, 4, GL_TRIANGLE_FAN);
//shipMesh = LoadMeshFile("sship1", true);
modelCube = resMan->GetModel("cube.nmf");
modelShip = resMan->GetModel("sship1.nmf");
CheckGLError("Created meshes", __FILE__, __LINE__);
glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, 0);
glClearColor(0, 0, 0, 1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
CheckGLError("Created", __FILE__, __LINE__);
StartMenu();
oldTime=GetTime();
}
float aspect;//for input
void StarFleetGame::Changed(int w, int h)
{
renderer->Resize(w,h);
aspect = renderer->aspect;
camera.UpdateProj(85.0f, renderer->aspect, 0.1f, 1500.0f);
renderer->SetCamera(&camera);
UpdateButtons();
ChangeState(gameState);
}
void StarFleetGame::Update()
{
double startTime = GetTime();
deltaTime = float(startTime-oldTime);
oldTime = startTime;
for(uint32_t i=0; i<buttons.size();i++){
buttons[i]->Update();
}
if(gameState==eGameState_Play){
scene->Update(deltaTime);
//for(vector<Entity *>::iterator it=entities.begin();it<entities.end();it++)
for(uint32_t i=0;i<entities.size();i++){
Entity *ent = entities[i];
//ent->Update(deltaTime);
if(ent->remove){
entities.erase(entities.begin()+i);
gGame->scene->RemoveObject(ent);
delete ent;
i--;
}
}
camera.viewMtx = glm::lookAt(
//glm::vec3(3.2f,0,0),
entities[1]->position+glm::mat3(entities[1]->modelMtx)*glm::vec3(0.5,1.3,-1.6)+glm::vec3(0,0.2,0),
entities[1]->position+glm::mat3(entities[1]->modelMtx)*glm::vec3(0.4,1.0,0.8),
glm::vec3(0,1,0));
// camera.UpdateView();
}
}
void Ship::Draw(IRenderer *r){
r->DrawModel(modelShip, displayMtx);
}
void Projectile::Draw(IRenderer *r){
r->SetColor(1,0,0,1);
r->DrawModel(modelCube, displayMtx);
}
void Explosion::Draw(IRenderer *r){
r->SetColor(1,0.5,0,1);
r->DrawModel(modelCube, displayMtx);
}
void Asteroid::Draw(IRenderer *r){
r->SetColor(0.7,0.7,0.7,1);
r->DrawModel(modelCube, displayMtx);
}
/*
void DrawText(const char *t,float x,float y,float s)
{
//glEnable(GL_BLEND);
//glBlendFunc(1,1);
testFont.Print(t,x,y/renderer->aspect,s);
//glDisable(GL_BLEND);
}*/
/*
void DrawRect(float x, float y, float w, float h)
{
float lx=x;
float rx=(x+w);
float dy=(y+h);
float verts[] = {
lx, y, 0,0,
lx, dy, 0,1,
rx, dy, 1,1,
rx, y, 1,0
};
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 16, verts);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 16, verts+2);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
*/
/*
void StarFleetGame::DrawButton(Button *b)
{
if(b->text){
//testFont.Print(b->text,b->x*aspect+0.01,1-b->y-0.05,0.5);
//float x = b->x*2.0f-1.0f;
//float y = 1-(b->y*2.0f-1.0f);
renderer->DrawText(b->text,b->x+0.01,b->y-0.05f,0.5);
}//else
{
//DrawRect(b->x,b->y,b->w,b->h);
}
}*/
void StarFleetGame::Draw()
{
Update();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
CheckGLError("Clear", __FILE__, __LINE__);
glEnableVertexAttribArray(0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
renderer->Draw();
#if 0
glEnableVertexAttribArray(2);
texProg.Use();
glUniform4f(texProg.u_color,1,1,1,1);
if(gameState==eGameState_Play||gameState==eGameState_Pause){
shipMesh->Bind();
shipTex.Bind();
for(int i=0;i<SHIP_COUNT;i++)
{
if(((Ship*)entities[i])->isDead)
continue;
mvpMtx = camera.projMtx * camera.viewMtx * entities[i]->displayMtx;
glUniformMatrix4fv(texProg.u_mvpMtx,1,GL_FALSE,glm::value_ptr(mvpMtx));
shipMesh->Draw();
}
cubeMesh->Bind();
//proj
texWhite.Bind();
glUniform4f(texProg.u_color,1,0,0,1);
for(uint32_t i=SHIP_COUNT;i<entities.size();i++){
if(entities[i]->type!=eProj)
continue;
mvpMtx = camera.projMtx * camera.viewMtx * entities[i]->displayMtx;
glUniformMatrix4fv(texProg.u_mvpMtx,1,GL_FALSE,glm::value_ptr(mvpMtx));
cubeMesh->Draw();
}
//expl
glUniform4f(texProg.u_color,1,0.5f,0,1);
for(uint32_t i=SHIP_COUNT;i<entities.size();i++){
if(entities[i]->type!=eExpl)
continue;
mvpMtx = camera.projMtx * camera.viewMtx * entities[i]->displayMtx;
glUniformMatrix4fv(texProg.u_mvpMtx,1,GL_FALSE,glm::value_ptr(mvpMtx));
cubeMesh->Draw();
}
cubeMesh->Unbind();
glUniform4f(texProg.u_color,1,1,1,1);
}
#endif
renderer->SetColor(1,1,1,1);
//2D
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
//glm::mat4 mvpMtx = glm::scale(glm::mat4(1.0),glm::vec3(1.0f,renderer->aspect,1.0f));
//glUniformMatrix4fv(texProg.u_mvpMtx,1,GL_FALSE,glm::value_ptr(mvpMtx));
if(gameState==eGameState_Play){
//glUniform4f(texProg.u_color,1,1,1,1);
renderer->Set2DMode();
char str[64];
snprintf(str,64,"hp: %.0f",ships[1]->hp);
renderer->DrawText(str,0,0.1,0.48);
snprintf(str,64,"ents: %d",entities.size());
renderer->DrawText(str,0.4,0.1,0.48);
renderer->SetColor(0,1,0,1);
for(int i=0;i<SHIP_COUNT;i++){
if(((Ship*)entities[i])->isDead)
continue;
glm::mat4 tmtx = camera.projMtx * camera.viewMtx * entities[i]->modelMtx;
glm::vec4 p(0,0,0,1);
p=tmtx*p;
p/=p.w;
p.y = (-p.y/renderer->aspect*0.5+0.5);
p.x = p.x*0.5+0.5;
if(p.z>0&&p.z<1){
//DrawRect(p.x-0.15,p.y+0.2,0.3*ships[i]->hp*0.01,0.02);
renderer->DrawRect(p.x-0.15,p.y-0.2,0.3*ships[i]->hp*0.01,0.02);
}
}
}
renderer->SetColor(1,1,1,1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(2);
CheckGLError("Draw", __FILE__, __LINE__);
}
void StarFleetGame::OnTouch(float x, float y, int a, int tf)
{
float tx = x/renderer->width;
float ty = y/renderer->height;
if(a==0){
for(uint32_t i=0; i<buttons.size();i++){
if(buttons[i]->active)
buttons[i]->Hit(tx,ty);
}
}
}
bool Button::SetUniform(int loc)
{
glUniform4f(loc, x*2.0f-(1-w), -(y*2.0f-(1-h)), w, h);
return true;
}
class Projectile;
void TraceLine(Projectile *proj, float deltaTime);
void CreateExplosion(Entity *owner,float size){
Explosion *expl = new Explosion(owner->position,size);
expl->angles = owner->angles;
entities.push_back(expl);
gGame->scene->AddObject(expl);
}
void CreateProjectile(Entity *shooter, glm::vec3 dir,float damage)
{
Projectile *proj = new Projectile(shooter,damage);
proj->position = shooter->position;
proj->angles = shooter->angles;
//proj->velocity = glm::normalize(shooter->velocity)*2.0f;
proj->velocity = dir;
entities.push_back(proj);
gGame->scene->AddObject(proj);
//Log("CreateProjectile entities.size() %d\n",entities.size());
}
void TraceLine(Projectile *proj, float deltaTime)
{
for(int i=0;i<SHIP_COUNT;i++){
Ship *ent = (Ship *)entities[i];
if(ent->isDead||ent==proj->shooter)
continue;
glm::mat4 invmodelMtx = glm::inverse(ent->modelMtx);
glm::vec3 s = glm::vec3(invmodelMtx*(glm::vec4(proj->position,1.0f)));
glm::vec3 d = glm::vec3(invmodelMtx*(glm::vec4(proj->velocity*deltaTime,1.0f)));//proj->modelMtx[2];
#if 0
glm::vec3 p = glm::vec3(0.0f);
glm::vec3 e = glm::vec3(0.5f);
float hl = glm::length(d)*0.5f;
glm::vec3 m = s+d*0.5f;
glm::vec3 t = p-m;
if( (glm::abs(t.x)>e.x+hl+glm::abs(d.x)) ||
(glm::abs(t.y)>e.y+hl+glm::abs(d.y)) ||
(glm::abs(t.z)>e.z+hl+glm::abs(d.x)) )
continue;
float r = e.y*glm::abs(d.z)+e.z*glm::abs(d.y);
if(glm::abs(t.y*d.z-t.z*d.y)>r)
continue;
r = e.x*glm::abs(d.z)+e.z*glm::abs(d.x);
if(glm::abs(t.z*d.x-t.x*d.z)>r)
continue;
r = e.x*glm::abs(d.y)+e.y*glm::abs(d.x);
if(glm::abs(t.x*d.y-t.y*d.x)>r)
continue;
#endif
if(!ent->bbox.Intersect(s,d))
continue;
//Log("Ship %p hit %p\n",proj->shooter,ent);
CreateExplosion(proj,0.2f);
proj->remove = true;
ent->Hit(proj->damage);
return;
}
}

View File

@ -0,0 +1,41 @@
#pragma once
#include "game/IGame.h"
#include "renderer/camera.h"
class ResourceManager;
class IRenderer;
class Scene;
class StarFleetGame: public IGame{
public:
void Created();
void Changed(int w, int h);
void Draw();
const char *GetGamedir(){
return "star-fleet";
}
void OnKey(int key, int scancode, int action, int mods);
void OnTouch(float tx, float ty, int ta, int tf);
ResourceManager *resMan;
IRenderer *renderer;
Camera camera;
Scene *scene;
double oldTime;
float deltaTime;
void Update();
void DrawButton(Button *b);
};
enum eGameState
{
eGameState_Menu,
eGameState_Play,
eGameState_Pause
};
extern eGameState gameState;

19
demos/VolLight/Android.mk Normal file
View File

@ -0,0 +1,19 @@
LOCAL_PATH := $(call my-dir)
ENGINE_DIR =../../nenuzhno-engine/
include $(CLEAR_VARS)
LOCAL_MODULE := nenuzhno-engine
LOCAL_CFLAGS := -Wall
LOCAL_C_INCLUDES := . ../libs/glm ../nenuzhno-engine
LOCAL_SRC_FILES := $(ENGINE_DIR)android_backend.cpp $(ENGINE_DIR)log.cpp $(ENGINE_DIR)system/FileSystem.cpp $(ENGINE_DIR)system/config.cpp $(ENGINE_DIR)game/IGame.cpp \
$(ENGINE_DIR)renderer/renderer.cpp $(ENGINE_DIR)renderer/LightingForward.cpp $(ENGINE_DIR)renderer/font.cpp $(ENGINE_DIR)renderer/mesh.cpp $(ENGINE_DIR)renderer/Model.cpp $(ENGINE_DIR)renderer/camera.cpp \
$(ENGINE_DIR)graphics/vbo.cpp $(ENGINE_DIR)graphics/glsl_prog.cpp $(ENGINE_DIR)graphics/fbo.cpp $(ENGINE_DIR)graphics/texture.cpp $(ENGINE_DIR)graphics/gl_utils.cpp \
$(ENGINE_DIR)scene/Scene.cpp $(ENGINE_DIR)cull/BoundingBox.cpp $(ENGINE_DIR)cull/Frustum.cpp \
$(ENGINE_DIR)resource/ResourceManager.cpp $(ENGINE_DIR)resource/vtf_loader.cpp $(ENGINE_DIR)resource/dds_loader.cpp $(ENGINE_DIR)resource/nmf_loader.cpp $(ENGINE_DIR)resource/mesh_loader.cpp \
main.cpp Volumetrics.cpp
# $(ENGINE_DIR)graphics/gl_ext.cpp $(ENGINE_DIR)graphics/vao.cpp
LOCAL_LDLIBS := -llog -lGLESv2 -lm -lEGL
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,18 @@
TARGET = ../../assets/VolLight.exe
ENGINE_DIR = ../..
LIBS_DIR = ../../../../../Libs
all: $(TARGET)
INCLUDES = -I. -I$(ENGINE_DIR)/src -I$(LIBS_DIR)/gl/glm/glm -I$(LIBS_DIR)/gl/glew-2.0.0/include -I$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/include
CPPFLAGS = -Wall -ggdb -m32
LDFLAGS = -static-libgcc -static-libstdc++ -ggdb -m32
LIBS = -lnenuzhno-engine -L$(ENGINE_DIR)/bin -lopengl32 -lglfw3 -lglew32 -lgdi32 -L$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/lib-mingw -L$(LIBS_DIR)/gl/glew-2.0.0/lib
SRCS = main.cpp Volumetrics.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/bin/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

View File

@ -0,0 +1,66 @@
#include "Volumetrics.h"
#include "scene/Scene.h"
#include "renderer/renderer.h"
#include <vec4.hpp>
#include <mat4x4.hpp>
#include <gtc/type_ptr.hpp>
using glm::vec4;
using glm::mat4;
Volumetrics::Volumetrics(){
lightObj = 0;
}
void Volumetrics::Init(Scene *sc,vec3 pos,vec3 target,float fov, float aspect,float aNear,float aFar,int lightRes)
{
lightObj = new LightObject(ePoint,pos,vec3(1),aFar);
sc->AddLight(lightObj);
camera = Camera();
camera.LookAt(lightObj->pos,target,vec3(0,1,0));
camera.UpdateProj(fov,aspect,aNear,aFar);
camera.UpdateFrustum();
depthFBO.Create();
depthFBO.CreateDepthTexture(lightRes,lightRes);
FrameBufferObject::Unbind();
}
void Volumetrics::AddToDepth(IRenderer *rend){
mat4 mtx = scale(glm::inverse(camera.projMtx*camera.viewMtx),vec3(2));
rend->SetModelMtx(mtx);
rend->DrawCube();
}
void Volumetrics::Prepare(IRenderer *rend){
depthFBO.Bind();
depthFBO.SetupViewport();
depthFBO.Clear(2);
rend->RenderDepth(&camera);
depthFBO.Unbind();
rend->ResetViewport();
}
void Volumetrics::Draw(IRenderer *rend,int u_lightMtx,int u_invVPMtx, int u_lightPosSize){
mat4 lightMtx = camera.projMtx*camera.viewMtx;
//progVolLight.UniformMat4(u_lightMtx,lightMtx);
glUniformMatrix4fv(u_lightMtx,1,false,glm::value_ptr(lightMtx));
lightMtx = scale(glm::inverse(lightMtx),vec3(2));
rend->SetModelMtx(lightMtx);
//progVolLight.UniformMat4(u_invVPMtx,glm::inverse(rend->vpMtx));
glUniformMatrix4fv(u_invVPMtx,1,false,glm::value_ptr(glm::inverse(rend->vpMtx)));
glUniform4f(u_lightPosSize,lightObj->pos.x,lightObj->pos.y,lightObj->pos.z,lightObj->radius);
glActiveTexture(GL_TEXTURE1);
depthFBO.BindDepthTexture();
glActiveTexture(GL_TEXTURE2);
rend->GetFBO()->BindDepthTexture();
glActiveTexture(GL_TEXTURE0);
rend->DrawCube();
}
bool Volumetrics::CheckPoint(glm::vec3 pos){
return camera.frustum.Contains(vec4(pos,0.02));
}

View File

@ -0,0 +1,24 @@
#pragma once
class Scene;
class IRenderer;
class LightObject;
#include "renderer/camera.h"
#include "graphics/fbo.h"
#include <vec3.hpp>
using glm::vec3;
class Volumetrics{
public:
Volumetrics();
void Init(Scene *sc,vec3 pos,vec3 target,float fov, float aspect,float aNear,float aFar,int lightRes);
void AddToDepth(IRenderer *rend);
void Prepare(IRenderer *rend);
void Draw(IRenderer *rend,int u_lightMtx,int u_invVPMtx, int u_lightPosSize);
bool CheckPoint(vec3 pos);
LightObject *lightObj;
Camera camera;
FrameBufferObject depthFBO;
};

283
demos/VolLight/main.cpp Normal file
View File

@ -0,0 +1,283 @@
#include <vector>
#include "graphics/platform_gl.h"
#include "log.h"
#include "engine.h"
#include "button.h"
#include "game/IGame.h"
#include "system/config.h"
#include "resource/ResourceManager.h"
#include "renderer/renderer.h"
#include "renderer/mesh.h"
#include "renderer/material.h"
#include "renderer/model.h"
#include "graphics/texture.h"
#include "graphics/fbo.h"
#include "graphics/glsl_prog.h"
#include "Volumetrics.h"
#include <vec2.hpp>
#include <gtc/random.hpp>
#include <gtc/matrix_transform.hpp>
#include <gtc/type_ptr.hpp>
#include <common.hpp>
#include <geometric.hpp>
using glm::vec2;
using glm::vec3;
using glm::vec4;
using glm::linearRand;
using glm::clamp;
using glm::abs;
using glm::normalize;
using glm::translate;
using glm::scale;
class VolLightGame: public IGame{
public:
VolLightGame(){}
void Created();
void Changed(int w, int h);
void Draw();
const char *GetGamedir(){
return "vol_light";
}
void OnTouch(float tx, float ty, int ta, int tf);
void OnKey(int key, int scancode, int action, int mods);
IRenderer *rend;
ResourceManager *resMan;
ConfigFile cfg;
Camera cam;
Scene scene;
Texture texWhite;
TexMaterial *matWhite;
Volumetrics lightVol;
FrameBufferObject volFBO;
float volScale;
glslProg progVolLight;
int u_lightMtx;
int u_invVPMtx;
int u_lightPosSize;
glslProg progVolLightIn;
int u_lightMtxIn;
int u_invVPMtxIn;
int u_lightPosSizeIn;
Joystick joyL;
KeyJoystick joyM;
int frame;
double oldTime;
};
IGame *CreateGame(){
return new VolLightGame();
}
void VolLightGame::Created(){
Log("VolLight test Created()\n");
resMan = new ResourceManager();
resMan->Init();
rend = CreateRenderer();
rend->Init(RENDERER_GUI|RENDERER_LIGHT|RENDERER_BACKBUFFER, resMan);
uint8_t whiteData[]={255,255,255};
texWhite.Create(1,1);
texWhite.Upload(0,GL_RGB,whiteData);
matWhite = new TexMaterial(&texWhite,true);
progVolLight.CreateFromFile("volLight","volLight");
progVolLight.u_mvpMtx = progVolLight.GetUniformLoc("u_mvpMtx");
progVolLight.u_modelMtx = progVolLight.GetUniformLoc("u_modelMtx");
progVolLight.u_cameraPos = progVolLight.GetUniformLoc("u_cameraPos");
u_lightMtx = progVolLight.GetUniformLoc("u_lightMtx");
u_invVPMtx = progVolLight.GetUniformLoc("u_invVPMtx");
u_lightPosSize = progVolLight.GetUniformLoc("u_lightPosSize");
progVolLight.UniformTex("u_lightDepth",1);
progVolLight.UniformTex("u_sceneDepth",2);
progVolLightIn.CreateFromFile("volLight","volLightIn");
progVolLightIn.u_mvpMtx = progVolLightIn.GetUniformLoc("u_mvpMtx");
progVolLightIn.u_modelMtx = progVolLightIn.GetUniformLoc("u_modelMtx");
progVolLightIn.u_cameraPos = progVolLightIn.GetUniformLoc("u_cameraPos");
u_lightMtxIn = progVolLightIn.GetUniformLoc("u_lightMtx");
u_invVPMtxIn = progVolLightIn.GetUniformLoc("u_invVPMtx");
u_lightPosSizeIn = progVolLightIn.GetUniformLoc("u_lightPosSize");
progVolLightIn.UniformTex("u_lightDepth",1);
progVolLightIn.UniformTex("u_sceneDepth",2);
cfg.Load("config.txt");
Model *mdl = resMan->GetModel(cfg["modelName"].c_str());
mdl->materials[0].mat = matWhite;
scene = Scene();
StaticModel *obj1 = new StaticModel();
obj1->mdl = mdl;
vec3 obj1Pos = cfg.GetVec3("modelPos");
obj1->modelMtx = translate(mat4(1.0f),obj1Pos);
scene.AddObject(obj1);
lightVol.Init(&scene,cfg.GetVec3("lightPos"),cfg.GetVec3("lightTarget"),atof(cfg["lightFOV"].c_str()),
atof(cfg["lightAspect"].c_str()),atof(cfg["lightNear"].c_str()),atof(cfg["lightFar"].c_str()),cfg.GetInt("lightRes"));
volScale = atof(cfg["volScale"].c_str());
volFBO.Create();
volFBO.CreateTexture(64,64,GL_LINEAR);
FrameBufferObject::Unbind();
rend->SetScene(&scene);
cam = Camera();
cam.pos = cfg.GetVec3("cameraPos");
cam.rot = cfg.GetVec3("cameraRot");
cam.UpdateView();
rend->SetCamera(&cam);
rend->debug = cfg["debug"]!="0";
joyL = Joystick(0,0.5,0.5,0.5);
//joyM = Joystick(0.5,0.5,0.5,0.5);
joyM = KeyJoystick(IN_KEY_W,IN_KEY_S,IN_KEY_D,IN_KEY_A);
frame = 0;
oldTime = GetTime();
}
void VolLightGame::Changed(int w, int h){
if(!w||!h)
return;
rend->Resize(w,h);
cam.UpdateProj(80.0f,rend->aspect,0.02f,20.0f);
//cam.SetOrtho(aspect,bScroll.pos);
volFBO.Resize(w*volScale,h*volScale);
frame = 0;
}
void VolLightGame::Draw(){
double startTime = GetTime();
float deltaTime = (startTime-oldTime);
oldTime = startTime;
cam.pos += glm::inverse(glm::mat3(cam.viewMtx))*vec3(joyM.vel.x,0,-joyM.vel.y)*2.0f*deltaTime;
cam.rot += vec3(-joyL.vel.y*rend->aspect,-joyL.vel.x,0)*60.0f*deltaTime;
cam.UpdateView();
rend->Draw();
bool drawVolumetricLight = true;
bool isInsideVolume = lightVol.CheckPoint(cam.pos);
//drawVolumetricLight = !isInsideVolume;
//Add light box to depth
if(drawVolumetricLight){
rend->GetFBO()->Bind();
rend->Set2DMode(false);
glColorMask(0,0,0,0);
//UseProg depth
lightVol.AddToDepth(rend);
glColorMask(1,1,1,1);
rend->GetFBO()->Unbind();
}
#if 0
//display scene depth
rend->Set2DMode(true);
rend->SetModelMtx(mat4(1));
rend->GetFBO()->BindDepthTexture();
rend->DrawRect(0.02,0.02,0.5,0.5);
#else
//prepare depth texture
if(drawVolumetricLight){
if(frame%128==0)
lightVol.Prepare(rend);
//Display light depth
/*lightFBO.BindDepthTexture();
rend->SetModelMtx(mat4(1));
rend->Set2DMode();
rend->DrawRect(0.02,0.02,0.5,0.5);*/
volFBO.Bind();
volFBO.Clear(1);
rend->Set2DMode(false);
if(!isInsideVolume){
glCullFace(GL_FRONT);
rend->UseProg(&progVolLight);
lightVol.Draw(rend,u_lightMtx,u_invVPMtx,u_lightPosSize);
glCullFace(GL_BACK);
}else{
rend->UseProg(&progVolLightIn);
lightVol.Draw(rend,u_lightMtxIn,u_invVPMtxIn,u_lightPosSizeIn);
}
//clean up
glActiveTexture(GL_TEXTURE1);
texWhite.Bind();
glActiveTexture(GL_TEXTURE2);
texWhite.Bind();
glActiveTexture(GL_TEXTURE0);
volFBO.Unbind();
rend->ResetViewport();
//draw effect additive
rend->Set2DMode(true);
glEnable(GL_BLEND);
glBlendFunc(1,1);
volFBO.BindTexture();
rend->DrawRect(0.0,0.0,1.0,1.0);
glDisable(GL_BLEND);
}
texWhite.Bind();
#endif
char temp[256];
snprintf(temp,256,"volumetric light: %s",drawVolumetricLight?"On":"Off");
rend->DrawText(temp,0.02,0.9,0.2*rend->aspect);
frame++;
}
Button::Button(float nx, float ny, float nw, float nh, bool adjust):
x(nx),y(ny),w(nw),h(nh),text(0),active(true),pressed(false)
{
}
Button::Button(float nx, float ny, float nw, float nh, const char *t, bool adjust):
x(nx),y(ny),w(nw),h(nh),text(t),active(true),pressed(false)
{
}
void Button::Update(){}
bool Button::SetUniform(int loc){return false;}
void VolLightGame::OnTouch(float tx, float ty, int ta, int tf){
float x = tx/rend->width;
#ifdef ANDROID
float y = (ty-64)/rend->height;
#else
float y = ty/rend->height;
#endif
if(ta==0){
joyL.Hit(x,y,tf);
joyM.Hit(x,y*rend->aspect,tf);
}else if(ta==1){
joyL.Release(tf);
joyM.Release(tf);
}else if(ta==2){
joyL.Move(x,y,tf);
joyM.Move(x,y*rend->aspect,tf);
}
}
void VolLightGame::OnKey(int key, int scancode, int action, int mods){
joyM.OnKey(key,action);
}

View File

@ -0,0 +1,16 @@
LOCAL_PATH := $(call my-dir)
ENGINE_DIR =../../nenuzhno-engine/
include $(CLEAR_VARS)
LOCAL_MODULE := nenuzhno-engine
LOCAL_CFLAGS := -Wall
LOCAL_C_INCLUDES := . ../libs/glm ../nenuzhno-engine
LOCAL_SRC_FILES = $(ENGINE_DIR)android_backend.cpp $(ENGINE_DIR)log.cpp $(ENGINE_DIR)file_system.cpp $(ENGINE_DIR)game/IGame.cpp \
$(ENGINE_DIR)graphics/gl_utils.cpp $(ENGINE_DIR)graphics/gl_ext.cpp $(ENGINE_DIR)graphics/glsl_prog.cpp $(ENGINE_DIR)graphics/texture.cpp $(ENGINE_DIR)graphics/fbo.cpp $(ENGINE_DIR)graphics/vbo.cpp \
$(ENGINE_DIR)resource/vtf_loader.cpp $(ENGINE_DIR)resource/dds_loader.cpp \
test.cpp $(ENGINE_DIR)renderer/BokehBlur.cpp
LOCAL_LDLIBS := -llog -lEGL -lGLESv2
# -lm -lOpenSLES -lz
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,26 @@
TARGET = ../../assets/blur-test.exe
ENGINE_DIR = ../..
LIBS_DIR = ../../../../../Libs
all: $(TARGET)
INCLUDES = -I. -I$(LIBS_DIR)/gl/glew-2.0.0/include -I$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/include -I$(LIBS_DIR)/gl/glm/glm -I$(ENGINE_DIR)/src
CPPFLAGS = -Wall -g -ggdb -m32 -gdwarf-2
LIBS = -lnenuzhno-engine -lglfw3 -lglew32 -lopengl32 -lgdi32 -L$(ENGINE_DIR)/bin -L$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/lib-mingw -L$(LIBS_DIR)/gl/glew-2.0.0/lib
LDFLAGS = -static-libgcc -static-libstdc++ -m32 -g -ggdb -gdwarf-2
SRCS = blur.cpp
OBJS := $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $(subst ..,_,$@) $(CPPFLAGS) $(INCLUDES)
obj/_/graphics/gl_ext.o: ../graphics/gl_ext.cpp
$(CXX) -c $< -o $(subst ..,_,$@) $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(subst ..,_,$(OBJS)) $(ENGINE_DIR)/bin/libnenuzhno-engine.a
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
clean:
$(RM) $(OBJS) $(TARGET)
rebuild: clean all

302
demos/blur-test/blur.cpp Normal file
View File

@ -0,0 +1,302 @@
#include <math.h>
#include <gtc/type_ptr.hpp>
#include "log.h"
#include "graphics/platform_gl.h"
#include "graphics/gl_utils.h"
#include "graphics/glsl_prog.h"
#include "graphics/ArrayBuffer.h"
#include "graphics/fbo.h"
#include "graphics/gl_ext.h"
#include "renderer/BokehBlur.h"
#include "game/IGame.h"
class BlurGame : public IGame{
public:
void Created();
void Changed(int w, int h);
void Draw();
const char *GetGamedir(){
return "blur";
}
void DrawBlur();
};
IGame *CreateGame(){
return new BlurGame();
}
#define min(x,y) (x<y?x:y)
//TODO: GL_OES_vertex_array_object
int scrWidth=0;
int scrHeight=0;
glslProg *progTex;
glslProg *progMip;
glslProg *progBin;
VertexBufferObject *vboQuad;
VertexBufferObject *vboTri;
Texture *tex1;
Texture *tex2;
Texture *texWhite;
FrameBufferObject *fbo1;
Texture *texFb1;
glm::mat4 mvpMtx(1.0f);
BokehBlur bokeh;
float bokehSize=20.0f;
void BlurGame::Created()
{
GLExtensions::Init();
progTex = new glslProg();
progTex->CreateFromFile("generic", "col_tex");
progTex->u_mvpMtx = progTex->GetUniformLoc("u_mvpMtx");
progTex->u_color = progTex->GetUniformLoc("u_color");
progTex->Use();
glUniform4f(progTex->u_color,1,1,1,1);
progMip = new glslProg();
progMip->CreateFromFile("generic", "tex_mip");
progMip->u_mvpMtx = progMip->GetUniformLoc("u_mvpMtx");
//
glslProg tempProg("#version 100\nattribute vec4 a_p;void main(){gl_Position = a_p;}",
"#version 100\nprecision highp float; void main(){gl_FragColor = vec4(0.5);}");
//"precision mediump float; attribute vec4 a_position;uniform mat4 u_mvpMtx; void main(){gl_Position = u_mvpMtx * a_position;gl_PointSize = 8.0;}",
//"precision highp float;void main(){gl_FragColor = vec4(0.5);}");
tempProg.Save("test");
char *tempData = 0;
int tempLen = 0;
int tempFmt = 0;
if(!tempProg.GetBinaryData(&tempFmt,&tempData,&tempLen)){
Log("Can't get shader prog data\n");
}else{
progBin = new glslProg();
progBin->CreateFromBinary(tempFmt,tempData,tempLen);
}
if(tempData)
delete[] tempData;
glUseProgram(0);
//*((int*)0)=42;
float quadVerts[] ={
1,-1,1,0,
1, 1,1,1,
-1, 1,0,1,
-1,-1,0,0
};
vboQuad = new VertexBufferObject();
vboQuad->Create();
vboQuad->Upload(4*4*4, quadVerts);
float triVerts[] =
{
0.8,-0.6,1,0,
0.2, 0.9,1,1,
-0.9,-0.5,0.1,0.3
};
vboTri = new VertexBufferObject();
vboTri->Create();
vboTri->Upload(3*4*4, triVerts);
GLubyte whiteTexData[]={
255
};
texWhite = new Texture();
texWhite->Create(1,1);
texWhite->Upload(0, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, whiteTexData);
GLushort testTexData[] =
{
0x0000,0x444F,0x888F,0xCCCF, 0x400F,0x800F,0xC00F,0xF00F, 0x040F,0x080F,0x0C0F,0x0F0F, 0x004F,0x008F,0x00CF,0x00FF,
0x0000,0x444F,0x888F,0xCCCF, 0x444F,0x844F,0xC44F,0xF44F, 0x444F,0x484F,0x4C4F,0x4F4F, 0x444F,0x448F,0x44CF,0x44FF,
0x0000,0x444F,0x888F,0xCCCF, 0x488F,0x888F,0xC88F,0xF88F, 0x848F,0x888F,0x8C8F,0x8F8F, 0x884F,0x888F,0x88CF,0x88FF,
0x0000,0x444F,0x888F,0xCCCF, 0x4ccF,0x8ccF,0xCccF,0xFccF, 0xc4cF,0xc8cF,0xcCcF,0xcFcF, 0xcc4F,0xcc8F,0xccCF,0xccFF,
0x0000,0x444F,0x888F,0xCCCF, 0x440F,0x840F,0xC40F,0xF40F, 0x440F,0x480F,0x4C0F,0x4F0F, 0x404F,0x408F,0x40CF,0x40FF,
0x0000,0x444F,0x888F,0xCCCF, 0x480F,0x880F,0xC80F,0xF80F, 0x840F,0x880F,0x8C0F,0x8F0F, 0x804F,0x808F,0x80CF,0x80FF,
0x0000,0x444F,0x888F,0xCCCF, 0x4c0F,0x8c0F,0xCc0F,0xFc0F, 0xc40F,0xc80F,0xcC0F,0xcF0F, 0xc04F,0xc08F,0xc0CF,0xc0FF,
0x0000,0x444F,0x888F,0xCCCF, 0x4f0F,0x8f0F,0xCf0F,0xFf0F, 0xf40F,0xf80F,0xfC0F,0xfF0F, 0xf04F,0xf08F,0xf0CF,0xf0FF,
0x0000,0x444F,0x888F,0xCCCF, 0x404F,0x804F,0xC04F,0xF04F, 0x044F,0x084F,0x0C4F,0x0F4F, 0x044F,0x048F,0x04CF,0x04FF,
0x0000,0x444F,0x888F,0xCCCF, 0x408F,0x808F,0xC08F,0xF08F, 0x048F,0x088F,0x0C8F,0x0F8F, 0x084F,0x088F,0x08CF,0x08FF,
0x0000,0x444F,0x888F,0xCCCF, 0x40cF,0x80cF,0xC0cF,0xF0cF, 0x04cF,0x08cF,0x0CcF,0x0FcF, 0x0c4F,0x0c8F,0x0cCF,0x0cFF,
0x0000,0x444F,0x888F,0xCCCF, 0x40fF,0x80fF,0xC0fF,0xF0fF, 0x04fF,0x08fF,0x0CfF,0x0FfF, 0x0f4F,0x0f8F,0x0fCF,0x0fFF,
0x0000,0x444F,0x888F,0xCCCF, 0x400F,0x800F,0xC00F,0xF00F, 0x040F,0x080F,0x0C0F,0x0F0F, 0x004F,0x008F,0x00CF,0x00FF,
0x0000,0x444F,0x888F,0xCCCF, 0x400F,0x800F,0xC00F,0xF00F, 0x040F,0x080F,0x0C0F,0x0F0F, 0x004F,0x008F,0x00CF,0x00FF,
0x0000,0x444F,0x888F,0xCCCF, 0x400F,0x800F,0xC00F,0xF00F, 0x040F,0x080F,0x0C0F,0x0F0F, 0x004F,0x008F,0x00CF,0x00FF,
0x0000,0x444F,0x888F,0xCCCF, 0x400F,0x800F,0xC00F,0xF00F, 0x040F,0x080F,0x0C0F,0x0F0F, 0x004F,0x008F,0x00CF,0x00FF
};
tex1 = new Texture();
tex1->Create(16,16);
tex1->SetWrap(GL_CLAMP_TO_EDGE);
//tex1->SetFilter(GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST);
tex1->SetFilter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
tex1->Upload(0, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, testTexData);
tex1->Upload(1, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, testTexData);
tex1->Upload(2, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, testTexData);
tex1->Upload(3, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, testTexData+9);
tex1->Upload(4, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, testTexData+38);
tex2 = new Texture();
tex2->Create(64,64);
tex2->Upload(0,GL_RGBA4,GL_RGBA,GL_UNSIGNED_SHORT_4_4_4_4,0);
/* tex2->SetFilter(GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST);
for(int i=1;i<7;i++){
tex2->Upload(i,GL_RGBA4,GL_RGBA,GL_UNSIGNED_SHORT_4_4_4_4,0);
}
tex2->Upload(2,GL_RGBA4,GL_RGBA,GL_UNSIGNED_SHORT_4_4_4_4,testTexData);
*/
texFb1 = new Texture();
texFb1->Create(64,64);
texFb1->SetFilter(GL_LINEAR, GL_LINEAR);
texFb1->Upload(0,GL_RGBA,GL_RGBA,GL_UNSIGNED_BYTE,0);
fbo1 = new FrameBufferObject();
fbo1->Create();
fbo1->AttachTexture(tex2, 0);
bokeh.Init(64,64,tex2);
glBindTexture(GL_TEXTURE_2D,0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#ifndef ANDROID
//TODO: add defines to header
if(!(GLExtensions::extFlags&eGLES)){
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
glEnable(GL_POINT_SPRITE);
}
#endif
CheckGLError("Created", __FILE__, __LINE__);
Log("Init done\n");
}
void BlurGame::Changed(int w, int h)
{
scrWidth=w;
scrHeight=h;
CheckGLError("Changed", __FILE__, __LINE__);
}
float a=0;
void BlurGame::Draw()
{
a+=0.02f;
progTex->Use();
glUniformMatrix4fv(progTex->u_mvpMtx,1,GL_FALSE,glm::value_ptr(mvpMtx));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(2);
DrawBlur();
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(2);
glBindTexture(GL_TEXTURE_2D,0);
CheckGLError("Draw", __FILE__, __LINE__);
}
void BlurGame::DrawBlur()
{
bokehSize=(sin(a)+1.0f)*10.0f+0.1f;
//Log("boken size %f\n",bokehSize);
#if 1
fbo1->Bind();
fbo1->AttachTexture(tex2, 0);
fbo1->SetupViewport();
glClear(GL_COLOR_BUFFER_BIT);
tex1->Bind();
vboTri->Bind();
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,16,0);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,16,(void*)8);
glDrawArrays(GL_TRIANGLES,0,3);
vboTri->Unbind();
#if RENDER_TO_MIP
glBindFramebuffer(GL_FRAMEBUFFER, 0);
fbo1->Bind();
fbo1->AttachTexture(tex2, 3);
glClear(GL_COLOR_BUFFER_BIT);
#endif
#if WHITE_LINE
texWhite->Bind();
float lineVerts[]={
-1,0.5,0,0,
1,-0.5,0,0
};
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,16,lineVerts);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,16,lineVerts+2);
glDrawArrays(GL_LINES,0,2);
#endif
Texture *outTex=tex2;
#define POSTPROCESS 1
#if POSTPROCESS
fbo1->AttachTexture(texFb1, 0);
fbo1->SetupViewport();
glClear(GL_COLOR_BUFFER_BIT);
glDisableVertexAttribArray(2);
bokeh.Render(bokehSize);
glEnableVertexAttribArray(2);
outTex=texFb1;
#endif
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//glViewport(0,0,scrWidth,scrHeight);
int d = min(scrWidth,scrHeight);
glViewport(0,0,d,d);
glClear(GL_COLOR_BUFFER_BIT);
progTex->Use();
vboQuad->Bind();
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,16,0);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,16,(void*)8);
//tex2->Bind();
//glDrawArrays(GL_TRIANGLE_FAN,0,4);
outTex->Bind();
//glEnable(GL_BLEND);
glBlendFunc(1,1);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisable(GL_BLEND);
vboQuad->Unbind();
#else
int d = min(scrWidth,scrHeight);
glViewport(0,0,d,d);
progTex->Use();
bokeh.texCore->Bind();
vboQuad->Bind();
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,16,0);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,16,(void*)8);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
vboQuad->Unbind();
#endif
#if SHOW_MIPS
progMip->Use();
glUniformMatrix4fv(progMip->u_mvpMtx,1,GL_FALSE,glm::value_ptr(mvpMtx));
tex2->Bind();
vboQuad->Bind();
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,16,0);
glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,16,(void*)8);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
vboQuad->Unbind();
#endif
}

13
demos/cube/Android.mk Normal file
View File

@ -0,0 +1,13 @@
LOCAL_PATH := $(call my-dir)
ENGINE_DIR =../../nenuzhno-engine/
include $(CLEAR_VARS)
LOCAL_MODULE := nenuzhno-engine
LOCAL_CFLAGS := -Wall
LOCAL_C_INCLUDES := . ../libs/glm ../nenuzhno-engine
LOCAL_SRC_FILES := $(ENGINE_DIR)android_backend.cpp $(ENGINE_DIR)log.cpp $(ENGINE_DIR)system/FileSystem.cpp $(ENGINE_DIR)game/IGame.cpp $(ENGINE_DIR)renderer/camera.cpp $(ENGINE_DIR)/cull/frustum.cpp \
$(ENGINE_DIR)graphics/gl_utils.cpp $(ENGINE_DIR)graphics/glsl_prog.cpp $(ENGINE_DIR)resource/mesh_loader.cpp $(ENGINE_DIR)renderer/mesh.cpp $(ENGINE_DIR)graphics/vbo.cpp \
cube.cpp
LOCAL_LDLIBS := -llog -lGLESv2 -lm -lEGL
include $(BUILD_SHARED_LIBRARY)

17
demos/cube/Makefile.linux Normal file
View File

@ -0,0 +1,17 @@
TARGET = cube
ENGINE_DIR = ../../nenuzhno-engine
all: $(TARGET)
INCLUDES = -I. -I$(ENGINE_DIR) -I../../../../Libs/gl/glm/glm -I../../../../Libs/gl/glew-2.1.0/include
CPPFLAGS = -Wall -ggdb
LDFLAGS = -static-libgcc -static-libstdc++ -ggdb
LIBS = -lnenuzhno-engine -L$(ENGINE_DIR) -lGL -lglfw3 -lX11 -lXrandr -lXinerama -lXcursor -lpthread -ldl -lGLEW -L../../../../Libs/gl/glfw-3.2.1_src/lib -L../../../../Libs/gl/glew-2.1.0/lib
SRCS = cube.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

18
demos/cube/Makefile.mingw Normal file
View File

@ -0,0 +1,18 @@
TARGET = ../../assets/cube.exe
ENGINE_DIR = ../..
LIBS_DIR = ../../../../../Libs
all: $(TARGET)
INCLUDES = -I. -I$(ENGINE_DIR)/src -I$(LIBS_DIR)/gl/glm/glm -I$(LIBS_DIR)/gl/glew-2.0.0/include
CPPFLAGS = -Wall -ggdb
LDFLAGS = -static-libgcc -static-libstdc++ -ggdb
LIBS = -lnenuzhno-engine -lglfw3 -lglew32 -lgdi32 -lopengl32 -L$(ENGINE_DIR)/bin -L$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/lib-mingw-w64 -L$(LIBS_DIR)/gl/glew-2.0.0/lib
SRCS = cube.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/bin/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

114
demos/cube/cube.cpp Normal file
View File

@ -0,0 +1,114 @@
#include <gtc/type_ptr.hpp>
#include "log.h"
#include "graphics/platform_gl.h"
#include "graphics/gl_utils.h"
#include "graphics/glsl_prog.h"
#include "graphics/ArrayBuffer.h"
#include "renderer/mesh.h"
#include "renderer/camera.h"
#include "game/IGame.h"
#include "engine.h"
class CubeGame : public IGame{
public:
void Created();
void Changed(int w, int h);
void Draw();
const char *GetGamedir(){
return "base";
}
};
IGame *CreateGame(){
return new CubeGame();
}
GLfloat vertices[] =
{
0.5f, -0.5f, 0.5f,
0.5f, -0.5f, -0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, -0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
0.5f, 0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, 0.5f, 0.5f
};
int inds[] =
{
0,1, 1,2, 2,3, 3,0,
4,5, 5,6, 6,7, 7,4,
0,4, 1,5, 2,6, 3,7
};
int ni=24;
int scrWidth = 0;
int scrHeight = 0;
glslProg simpleProg;
Mesh *cube;
glm::mat4 modelMtx;
Camera camera;
glm::mat4 mvpMtx(1);
void CubeGame::Created()
{
Log("%s\n",glGetString(GL_VERSION));
simpleProg.CreateFromFile("simple", "simple");
simpleProg.u_mvpMtx = simpleProg.GetUniformLoc("u_mvpMtx");
glUseProgram(0);
CheckGLError("Created shaders", __FILE__, __LINE__);
//cube = LoadMeshFile("cube", true);
cube = new Mesh(vertices,8,(GLushort*)inds,ni,GL_LINES);
modelMtx = glm::scale(glm::mat4(1.0),glm::vec3(1.2,1.0,0.5));
CheckGLError("Created meshes", __FILE__, __LINE__);
//glm::scale(glm::translate(glm::mat4(1.0),glm::vec3(0,0.1,0)),glm::vec3(0.2))
camera.pos = glm::vec3(0);
camera.rot = glm::vec3(30,30,0);
camera.UpdateView();
glBindTexture(GL_TEXTURE_2D, 0);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
// glEnable(GL_CULL_FACE);
CheckGLError("Created", __FILE__, __LINE__);
}
void CubeGame::Changed(int w, int h)
{
scrWidth = w;
scrHeight = h;
glViewport(0, 0, w, h);
float aspect = w/(float)h;
//camera.UpdateProj(75.0f, aspect, 0.1f, 2.0f);
camera.SetOrtho(aspect, 2.0f, 1.0f);
}
void CubeGame::Draw()
{
camera.UpdateView();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
CheckGLError("Clear", __FILE__, __LINE__);
glEnableVertexAttribArray(0);
simpleProg.Use();
mvpMtx = camera.projMtx * camera.viewMtx * modelMtx;
glUniformMatrix4fv(simpleProg.u_mvpMtx,1,GL_FALSE,glm::value_ptr(mvpMtx));
cube->Bind();
//cube->Draw();
glDrawElements(GL_LINES, ni, GL_UNSIGNED_INT, inds);
cube->Unbind();
if(CheckGLError("Draw cube", __FILE__, __LINE__))
EngineError("stop");
glBindTexture(GL_TEXTURE_2D, 0);
glDisableVertexAttribArray(0);
CheckGLError("Draw", __FILE__, __LINE__);
}

19
demos/gravity/Android.mk Normal file
View File

@ -0,0 +1,19 @@
LOCAL_PATH := $(call my-dir)
ENGINE_DIR =../../nenuzhno-engine/
include $(CLEAR_VARS)
LOCAL_MODULE := nenuzhno-engine
LOCAL_CFLAGS := -Wall
LOCAL_C_INCLUDES := . ../libs/glm ../nenuzhno-engine
LOCAL_SRC_FILES := $(ENGINE_DIR)android_backend.cpp $(ENGINE_DIR)log.cpp $(ENGINE_DIR)system/FileSystem.cpp $(ENGINE_DIR)game/IGame.cpp \
$(ENGINE_DIR)renderer/renderer.cpp $(ENGINE_DIR)renderer/LightingForward.cpp $(ENGINE_DIR)renderer/font.cpp $(ENGINE_DIR)renderer/mesh.cpp $(ENGINE_DIR)renderer/Model.cpp $(ENGINE_DIR)renderer/camera.cpp \
$(ENGINE_DIR)graphics/vbo.cpp $(ENGINE_DIR)graphics/glsl_prog.cpp $(ENGINE_DIR)graphics/fbo.cpp $(ENGINE_DIR)graphics/texture.cpp $(ENGINE_DIR)graphics/gl_utils.cpp \
$(ENGINE_DIR)scene/Scene.cpp $(ENGINE_DIR)cull/BoundingBox.cpp $(ENGINE_DIR)cull/Frustum.cpp \
$(ENGINE_DIR)resource/ResourceManager.cpp $(ENGINE_DIR)resource/vtf_loader.cpp $(ENGINE_DIR)resource/dds_loader.cpp $(ENGINE_DIR)resource/nmf_loader.cpp $(ENGINE_DIR)resource/mesh_loader.cpp \
main.cpp
# $(ENGINE_DIR)graphics/gl_ext.cpp $(ENGINE_DIR)graphics/vao.cpp
LOCAL_LDLIBS := -llog -lGLESv2 -lm -lEGL
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,18 @@
TARGET = ../../assets/gravity.exe
ENGINE_DIR = ../..
LIBS_DIR = ../../../../../Libs
all: $(TARGET)
INCLUDES = -I. -I$(ENGINE_DIR)/src -I$(LIBS_DIR)/gl/glm/glm -I$(LIBS_DIR)/gl/glew-2.0.0/include -I$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/include
CPPFLAGS = -Wall -ggdb -O2
LDFLAGS = -static-libgcc -static-libstdc++ -ggdb
LIBS = -lnenuzhno-engine -lglfw3 -lglew32 -lgdi32 -lopengl32 -L$(ENGINE_DIR)/bin -L$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/lib-mingw-w64 -L$(LIBS_DIR)/gl/glew-2.0.0/lib
SRCS = main.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/bin/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

514
demos/gravity/main.cpp Normal file
View File

@ -0,0 +1,514 @@
#include "log.h"
#include "graphics/platform_gl.h"
#include "button.h"
#include "renderer/renderer.h"
#include "renderer/mesh.h"
#include "resource/ResourceManager.h"
#include "game/IGame.h"
#include <vector>
#include <vec2.hpp>
#include <gtc/random.hpp>
#include <gtc/matrix_transform.hpp>
#include <common.hpp>
#include <geometric.hpp>
using glm::vec2;
using glm::vec3;
using glm::linearRand;
using glm::clamp;
using glm::abs;
using glm::normalize;
using glm::translate;
using glm::scale;
class vec3_queue{
public:
vec3_queue():_data(){}
void push(vec3 v){
_data.push_back(v);
for(int i=_data.size()-2;i>=0;i--){
_data[i+1]=_data[i];
}
_data[0] = v;
}
vec3 pop(){
if(!_data.size())
return vec3(0);
vec3 v = _data[_data.size()-1];
_data.erase(_data.end()-1);
return v;
}
vec3& operator[] (int n){
return _data[n];
}
void *data(){
return _data.data();
}
int size(){
return _data.size();
}
void clear(){
_data.clear();
}
private:
std::vector<vec3> _data;
};
class Entity
{
public:
virtual ~Entity(){}
virtual void Update(float dt){}
virtual void UpdateTail(){}
virtual void Respawn(){}
vec3 pos;
vec3 vel;
vec2 size;
float mass;
int hp;
vec3_queue trail;
};
class Unit: public Entity
{
public:
Unit();
virtual ~Unit(){}
virtual void Update(float dt);
virtual void UpdateTail();
virtual void Respawn();
vec3 target;
};
Unit::Unit():Entity(),target(0){
vel = vec3(0);
size = vec2(0.02f);
mass = 0.5f;
hp = 100;
};
Entity* Collide(Unit *u,vec3 orig, vec3 vel);
vec3 GetGravity(Unit *u);
vec3 planetPos(0.0f,0.0f,0.0f);
const int asteroidsCount = 2048;
float planetRadius = 1;
float planetMass = 2000;
float G = 0.000066;
const float timeScale = 10;
float aspect=1;
float RadiusFromMass(float m)
{
const float p = 5515.3;
float V = m/p;
return glm::pow((3*V)/(4* M_PI ),1.0/3.0);
//return glm::pow(m,0.5f)*0.02f;
}
void Unit::Update(float dt)
{
if(hp<=0)
return;
float d=glm::distance(pos,planetPos);
if(d<planetRadius+size.x||d>59)
{
planetMass += mass;
planetRadius = RadiusFromMass(planetMass);
Respawn();
}
/*
if(pos.x<0||pos.x>aspect-size.x){
vel.x*=-1;
//vel+=linearRand(vec3(-0.02,-0.06,0),vec3(0.02,0.06,0));
pos.x=clamp(pos.x,0.0f,aspect-size.x);
}
if(pos.y<0||pos.y>1-size.y){
vel.y*=-1;
//vel+=linearRand(vec3(-0.06,-0.02,0),vec3(0.06,0.02,0));
pos.y=clamp(pos.y,0.0f,1-size.y);
}
*/
//vel+=vec3(0,0.5f*dt,0);
vec3 gravity = GetGravity(this);
vel += gravity/mass*dt;
if(Entity *e = Collide(this,pos,vel*dt))
{
/*if(abs(pos.x-e->pos.x)>abs(pos.y-e->pos.y)){
vel.x*=-1;
e->vel.x*=-1;
}else{
vel.y*=-1;
e->vel.y*=-1;
}*/
vel = (mass*vel + e->mass*e->vel)/(mass+e->mass);
pos = (mass*pos + e->mass*e->pos)/(mass+e->mass);
mass+=e->mass;
//e->Respawn();
e->hp = 0;
}
pos+=vel*dt;
if(trail.size())
trail[0] = pos;
size = vec2(RadiusFromMass(mass));
}
void Unit::UpdateTail()
{
if(hp<=0)
return;
if(trail.size()>64){
trail.pop();
}
trail.push(pos);
}
void Unit::Respawn()
{
hp = 100;
mass = linearRand(1.0f, 4.0f);
size = vec2(RadiusFromMass(mass));
const float rr = 12;
//pos = linearRand(vec3(-rr,-rr,0.0),vec3(rr,rr,0));
pos = vec3(glm::diskRand(rr),0.0f);
pos += normalize(pos-planetPos)*planetRadius*1.2f;
//vel = linearRand(vec3(-0.6,-0.6,0),vec3(0.6,0.6,0));
//vel = vec3(0);
//vel = glm::cross(normalize(planetPos-pos),vec3(0,0,1.0f))*linearRand(-1.6f,1.6f);
vel = glm::cross(normalize(planetPos-pos),vec3(0,0,1.0f)) * glm::sqrt(G*(planetMass/(glm::length(planetPos-pos))));
//vel *= (rand()&1 ? 1.0f : -1.0f);
vel *= linearRand(0.9f,1.1f);
vel.z = 0;
trail.clear();
}
std::vector<Entity*> entities;
Entity * Collide(Unit *u, vec3 orig, vec3 vel)
{
//vec3 dst = orig+vel;
for(uint32_t i=0;i<entities.size();i++){
Entity *e = entities[i];
if(e==u || e->hp<=0)
continue;
/*if(e->pos.x>dst.x+u->size.x||e->pos.x<dst.x-u->size.x)
continue;
if(e->pos.y>dst.y+u->size.y||e->pos.y<dst.y-u->size.y)
continue;*/
float d = glm::distance(e->pos,u->pos);
if(d > e->size.x+u->size.x)
continue;
return e;
}
return 0;
}
vec3 GetGravity(Unit *u)
{
vec3 g=vec3(0);
g += normalize(planetPos-u->pos)*G*((planetMass*u->mass)/glm::pow(glm::distance(u->pos,planetPos),2.0f));
for(uint32_t i=0;i<entities.size();i++){
Entity *e = entities[i];
if(e==u || e->hp<=0)
continue;
vec3 d = e->pos-u->pos;
g += normalize(d)*G*((e->mass*u->mass)/glm::pow(glm::length(d),2.0f));
}
return g;
}
Mesh meshCircle;
class GravityGame: public IGame{
public:
GravityGame(){}
void Created();
void Changed(int w, int h);
void Draw();
const char *GetGamedir(){
return "base";
}
void OnTouch(float tx, float ty, int ta, int tf);
void DrawCircle(vec3 pos, float size);
IRenderer *rend;
ResourceManager *resMan;
Camera cam;
//vec2 pos;
bool drawTrails;
Button bAdd;
Button bTrails;
Scroll bScroll;
};
IGame *CreateGame(){
return new GravityGame();
}
Unit *CreateSatellite(float mass, float height, Unit *parent)
{
Unit *un = new Unit();
un->mass = mass;
un->size = vec2(RadiusFromMass(un->mass));
if(parent)
un->pos = parent->pos + vec3(0, height, 0);
else
un->pos = vec3(0, planetRadius*1.2f+height, 0);
if(parent)
un->vel = parent->vel + glm::cross(normalize(parent->pos-un->pos),vec3(0,0,1.0f)) * glm::sqrt(G*(parent->mass/(glm::length(parent->pos-un->pos))));
else
un->vel = glm::cross(normalize(planetPos-un->pos),vec3(0,0,1.0f)) * glm::sqrt(G*(planetMass/(glm::length(planetPos-un->pos))));
un->vel.z = 0;
un->trail.clear();
//un2->vel = glm::cross(normalize(planetPos-un2->pos),vec3(0,0,1.0f)) * glm::sqrt(G*(planetMass/(glm::length(planetPos-un2->pos))));
//un2->vel += glm::cross(normalize(un->pos-un2->pos),vec3(0,0,1.0f)) * glm::sqrt(G*(un->mass/(glm::length(un->pos-un2->pos))));
return un;
}
void GravityGame::Created()
{
srand(time(0));
Log("GravityGame Created()\n");
resMan = new ResourceManager();
resMan->Init();
rend = CreateRenderer();
rend->Init(RENDERER_GUI,resMan);
int nv = 32*2;
float *v = new float[nv*2];
int cv=0;
for(int i=0;i<32;i++){
float a = i/32.0f*M_PI*2;
float b = (i+1)/32.0f*M_PI*2;
v[cv++] = sin(a);
v[cv++] = cos(a);
v[cv++] = sin(b);
v[cv++] = cos(b);
}
meshCircle = Mesh(v, nv, GL_LINES);
planetRadius = RadiusFromMass(planetMass);
for(int i=0;i<4;i++){
Unit *un = new Unit();
un->Respawn();
entities.push_back(un);
}
//
{
Unit *un1 = CreateSatellite(35, 10, NULL);
entities.push_back(un1);
Unit *un2 = CreateSatellite(1, 0.8, un1);
entities.push_back(un2);
Unit *un3 = new Unit();
entities.push_back(un3);
un3->mass = 0.04f;
un3->size = vec2(RadiusFromMass(un3->mass));
un3->pos = un2->pos+vec3(0,0.09,0);
un3->vel = glm::cross(normalize(planetPos-un3->pos),vec3(0,0,1.0f)) * glm::sqrt(G*(planetMass/(glm::length(planetPos-un3->pos))));
un3->vel += glm::cross(normalize(un1->pos-un3->pos),vec3(0,0,1.0f)) * glm::sqrt(G*(un1->mass/(glm::length(un1->pos-un3->pos))));
un3->vel += glm::cross(normalize(un2->pos-un3->pos),vec3(0,0,1.0f)) * glm::sqrt(G*(un2->mass/(glm::length(un2->pos-un3->pos))));
un3->vel.z = 0;
un3->trail.clear();
}
{
const float ir = 19;
const float cw = 2;
for(int i=0; i<asteroidsCount; i++){
Unit *un = new Unit();
un->mass = linearRand(0.04f, 2.0f);
un->size = vec2(RadiusFromMass(un->mass));
un->pos = vec3(glm::circularRand(ir), 0.0f);
un->pos += normalize(un->pos - planetPos)*linearRand(0.0f, cw);
un->vel = glm::cross(normalize(planetPos-un->pos), vec3(0,0,1.0f)) * glm::sqrt(G*(planetMass/(glm::length(planetPos-un->pos))));
//un->vel *= linearRand(0.9f,1.1f);
un->vel.z = 0;
un->trail.clear();
entities.push_back(un);
}
}
//
cam = Camera();
drawTrails = true;
bAdd = Button(0.02,0.1,0.2,0.08,"Add");
bScroll = Scroll(0.8,0.1,0.2,0.9);
bScroll.pos = 10;
bTrails = Button(0.25,0.1,0.3,0.08, "Draw trails");
rend->AddButton(&bAdd);
rend->AddButton(&bTrails);
}
void GravityGame::Changed(int w, int h)
{
rend->Resize(w,h);
aspect = rend->aspect;
//planetPos.x = 0.5f*aspect;
cam.SetOrtho(aspect,bScroll.pos,1);
}
void GravityGame::DrawCircle(vec3 pos, float size)
{
mat4 mtx = translate(mat4(1.0f),pos);
mtx = scale(mtx,vec3(size));
rend->SetModelMtx(mtx);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 8, meshCircle.verts);
glDrawArrays(meshCircle.mode,0,meshCircle.numVerts);
}
void GravityGame::Draw()
{
if(bAdd.pressed)
{
bAdd.pressed=0;
Unit *un = new Unit();
un->Respawn();
entities.push_back(un);
}
if(bTrails.pressed)
{
bTrails.pressed = false;
drawTrails = !drawTrails;
if(drawTrails)
{
for(size_t i = 0;i<entities.size();i++){
entities[i]->trail.clear();
}
}
}
cam.SetOrtho(aspect,bScroll.pos*2,1);
float deltaTime = 0.02;
int subSteps = 10;
for(int i=0;i<subSteps;i++){
for(size_t i = 0;i<entities.size();i++){
entities[i]->Update(deltaTime/subSteps * timeScale);
}
for(size_t i = 0;i<entities.size();i++)
{
Entity *e = entities[i];
if(e->hp<=0){
entities.erase(entities.begin()+i);
delete e;
i--;
}
}
}
static int t=0;
if(drawTrails){
t++;
if(t%10==0){
for(size_t i = 0;i<entities.size();i++){
entities[i]->UpdateTail();
}
}
}
rend->Draw();
//rend->DrawRect(0.1,0.1,0.1/rend->aspect,0.1);
//rend->DrawText("test",0.45*rend->aspect,0.1,0.6*rend->aspect);
/*rend->DrawRect(pos.x,pos.y,0.1,0.1*rend->aspect);
char temp[256];
snprintf(temp,256,"pos: (%.3f, %.3f)",pos.x,pos.y);
rend->DrawText(temp,0.1,0.2,0.2*rend->aspect);
*/
char temp[256];
snprintf(temp,256,"objects count: %d\nplanet mass %.3f",entities.size(), planetMass);
rend->DrawText(temp,0.02,0.9,0.2*rend->aspect);
//mat4 mtx(1.0f);
rend->Set2DMode();
rend->SetCamera(&cam);
glDisableVertexAttribArray(2);
for(size_t i = 0;i<entities.size();i++){
Entity *e = entities[i];
//rend->DrawRect(e->pos.x/aspect,e->pos.y,e->size.x/rend->aspect,e->size.y);
DrawCircle(e->pos,e->size.x);
}
rend->SetModelMtx(mat4(1));
if(drawTrails)
{
for(size_t i = 0;i<entities.size();i++){
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 12, entities[i]->trail.data());
glDrawArrays(GL_LINE_STRIP,0,entities[i]->trail.size());
}
}
/*
mtx = translate(mtx,planetPos);
rend->SetModelMtx(mtx);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 8, meshPlanet.verts);
glDrawArrays(meshPlanet.mode,0,meshPlanet.numVerts);
*/
DrawCircle(planetPos,planetRadius);
}
Button::Button(float nx, float ny, float nw, float nh, bool adjust):
x(nx),y(ny),w(nw),h(nh),text(0),active(true),pressed(false)
{
/*if(adjust){
if(aspect>1)
h*=aspect;
else
w/=aspect;
}*/
}
Button::Button(float nx, float ny, float nw, float nh, const char *t, bool adjust):
x(nx),y(ny),w(nw),h(nh),text(t),active(true),pressed(false)
{
//if(adjust)
// w/=aspect;
}
void Button::Update(){}
bool Button::SetUniform(int loc){return false;}
void GravityGame::OnTouch(float tx, float ty, int ta, int tf){
float x = tx/rend->width;
#ifdef ANDROID
float y = (ty-64)/rend->height;
#else
float y = ty/rend->height;
#endif
if(ta==0){
bAdd.Hit(x,y);
bTrails.Hit(x,y);
bScroll.Hit(x,y,tf);
}else if(ta==1){
bScroll.Release(tf);
}else if(ta==2){
bScroll.Move(x,y,tf);
}
//pos = vec2(x,y);
}

View File

@ -0,0 +1,18 @@
TARGET = ../../assets/glsl_pt.exe
ENGINE_DIR = ../..
LIBS_DIR = ../../../../../Libs
all: $(TARGET)
INCLUDES = -I$(LIBS_DIR)/gl/glew-2.0.0/include -I$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/include -I$(LIBS_DIR)/gl/glm/glm -I$(ENGINE_DIR)/src
LIBS = -lnenuzhno-engine -L$(ENGINE_DIR)/bin -lglfw3 -lglew32 -lopengl32 -lgdi32 -L$(LIBS_DIR)/gl/glfw-3.3.bin.WIN32/lib-mingw-w64 -L$(LIBS_DIR)/gl/glew-2.0.0/lib
CPPFLAGS = -Wall -ggdb -m32
LDFLAGS = -static-libgcc -static-libstdc++ -m32
SRCS = glsl_pt.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/bin/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

View File

@ -0,0 +1,439 @@
#include "log.h"
#include "engine.h"
#include "graphics/platform_gl.h"
#include "graphics/gl_utils.h"
#include "graphics/glsl_prog.h"
#include "graphics/ArrayBuffer.h"
#include "graphics/fbo.h"
#include "system/FileSystem.h"
#include "game/IGame.h"
#include "renderer/font.h"
#include "resource/ResourceManager.h"
#include <gtc/type_ptr.hpp>
#include <gtc/matrix_transform.hpp>
#include <string.h>
#include <cstdlib>
#include <time.h>
#include <math.h>
class rayGame: public IGame{
public:
rayGame();
void Created();
void Changed(int w, int h);
void Draw();
const char *GetGamedir(){
return "pt";
}
void OnTouch(float tx, float ty, int ta, int tf);
};
IGame *CreateGame(){
return new rayGame();
}
char quadVert[]=
"#version 100\n"
"precision highp float;\n"
"attribute vec4 a_position;\n"
"varying vec2 v_uv;\n"
"void main(){\n"
" gl_Position = a_position;\n"
" v_uv = a_position.xy*0.5+0.5;\n"
"}\n";
char quadFrag[]=
"#version 100\n"
"precision highp float;\n"
"varying vec2 v_uv;\n"
"uniform sampler2D u_tex;\n"
"void main(){\n"
" gl_FragColor = texture2D(u_tex,v_uv);\n"
"}";
char quadTraceVert[]=
"#version 100\n"
"precision highp float;\n"
"attribute vec4 a_position;\n"
"varying vec2 v_uv;\n"
"void main(){\n"
" gl_Position = a_position;\n"
" v_uv = a_position.xy;\n"
"}\n";
char quadTraceFrag[]=
"#version 100\n"
"precision highp float;\n"
"varying vec2 v_uv;\n"
"uniform float u_textureWeight;\n"
"uniform sampler2D texture;\n"
"uniform sampler2D u_worldTex;\n"
"uniform float u_timeSinceStart;\n"
"uniform int u_numCubes;\n"
"const float glossiness = 0.8;\n"
"vec2 intersectCube(vec3 origin, vec3 ray, vec3 cubeMin, vec3 cubeMax){\n"
" vec3 tMin = (cubeMin - origin) / ray;\n"
" vec3 tMax = (cubeMax - origin) / ray;\n"
" vec3 t1 = min(tMin, tMax);\n"
" vec3 t2 = max(tMin, tMax);\n"
" float tNear = max(max(t1.x, t1.y), t1.z);\n"
" float tFar = min(min(t2.x, t2.y), t2.z);\n"
" return vec2(tNear, tFar);\n"
"}\n"
"vec3 normalForCube(vec3 hit, vec3 cubeMin, vec3 cubeMax){\n"
" if(hit.x < cubeMin.x + 0.0001) return vec3(-1.0, 0.0, 0.0);\n"
" else if(hit.x > cubeMax.x - 0.0001) return vec3(1.0, 0.0, 0.0);\n"
" else if(hit.y < cubeMin.y + 0.0001) return vec3(0.0, -1.0, 0.0);\n"
" else if(hit.y > cubeMax.y - 0.0001) return vec3(0.0, 1.0, 0.0);\n"
" else if(hit.z < cubeMin.z + 0.0001) return vec3(0.0, 0.0, -1.0);\n"
" else return vec3(0.0, 0.0, 1.0);\n"
"}\n"
"float random(vec3 scale, float seed){\n"
" return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n"
"}\n"
"vec3 cosineWeightedDirection(float seed, vec3 normal){\n"
" float u = random(vec3(12.9898, 78.233, 151.7182), seed);\n"
" float v = random(vec3(63.7264, 10.873, 623.6736), seed);\n"
" float r = sqrt(u);\n"
" float angle = 6.283185307179586 * v;\n"
// compute basis from normal
" vec3 sdir, tdir;\n"
" if (abs(normal.x)<.5){\n"
" sdir = cross(normal, vec3(1,0,0));\n"
" }else{\n"
" sdir = cross(normal, vec3(0,1,0));\n"
" }\n"
" tdir = cross(normal, sdir);\n"
" return r*cos(angle)*sdir + r*sin(angle)*tdir + sqrt(1.-u)*normal;\n"
"}\n"
"vec3 uniformlyRandomDirection(float seed){\n"
" float u = random(vec3(12.9898, 78.233, 151.7182), seed);\n"
" float v = random(vec3(63.7264, 10.873, 623.6736), seed);\n"
" float z = 1.0 - 2.0 * u;\n"
" float r = sqrt(1.0 - z * z);\n"
" float angle = 6.283185307179586 * v;\n"
" return vec3(r * cos(angle), r * sin(angle), z);\n"
"}\n"
"vec3 uniformlyRandomVector(float seed){\n"
" return uniformlyRandomDirection(seed) * sqrt(random(vec3(36.7539, 50.3658, 306.2759), seed));\n"
"}\n"
"float shadow(vec3 origin, vec3 ray) {\n"
" for(int c = 0; c<u_numCubes;c++){\n"
" vec3 cubemin = texture2D(u_worldTex,vec2(0,float(c)/float(u_numCubes-1))).xyz;\n"
" vec3 cubemax = texture2D(u_worldTex,vec2(1,float(c)/float(u_numCubes-1))).xyz;\n"
" vec2 tCube1 = intersectCube(origin, ray, cubemin,cubemax);\n"
" if(tCube1.x > 0.0 && tCube1.x < 1.0 && tCube1.x < tCube1.y)\n"
" return 0.0;\n"
" }\n"
" return 1.0;\n"
"}\n"
//"vec3 cube1min = vec3(-0.2,-0.2,-0.2);\n"
//"vec3 cube1max = vec3(0.2,0.2,0.2);\n"
//texture2D(u_worldTex,vec2(0,0)).xyz, texture2D(u_worldTex,vec2(0,0)).xyz
"vec3 calculateColor(vec3 origin, vec3 ray, vec3 light,float seed){\n"
" vec3 colorMask = vec3(1.0);\n"
" vec3 result = vec3(0.0);\n"
" for(int bounce = 0; bounce < 4; bounce++){\n"
" float t = 9999.9;\n"
" vec3 normal;\n"
" vec2 tRoom = intersectCube(origin, ray, vec3(-1.5,-1.0,-1.0), vec3(1.0));\n"
" if(tRoom.x < tRoom.y) t = tRoom.y;\n"
" vec3 hit = origin + ray * t;\n"
" for(int c = 0; c<u_numCubes;c++){\n"
" vec3 cubemin = texture2D(u_worldTex,vec2(0,float(c)/float(u_numCubes-1))).xyz;\n"
" vec3 cubemax = texture2D(u_worldTex,vec2(1,float(c)/float(u_numCubes-1))).xyz;\n"
" vec2 tCube1 = intersectCube(origin, ray, cubemin,cubemax);\n"
" if(tCube1.x > 0.0 && tCube1.x < tCube1.y && tCube1.x < t){\n"
" t = tCube1.x;\n"
" hit = origin + ray * t;\n"
" normal = normalForCube(hit, cubemin,cubemax);\n"
" }\n"
" }\n"
" vec3 surfaceColor = vec3(0.75);\n"
" if(t == tRoom.y){\n"
" normal = -normalForCube(hit, vec3(-1.5,-1.0,-1.0), vec3(1.0));\n"
" if(hit.x < -1.4999) surfaceColor = vec3(1.0, 0.3, 0.1);\n" // red
" else if(hit.x > 0.9999) surfaceColor = vec3(0.3, 1.0, 0.1);\n" // green
" ray = cosineWeightedDirection(seed + float(bounce), normal);\n"
//" ray = reflect(ray, normal);\n"
//" ray = normalize(reflect(ray, normal)) + uniformlyRandomVector(seed + float(bounce)) * glossiness;\n"
" }else if(t == 9999.9){\n"
" break;\n"
" }else{\n"
//" if(t == tCube1.x && tCube1.x < tCube1.y)"
//" normal = normalForCube(hit, texture2D(u_worldTex,vec2(0,0)).xyz,texture2D(u_worldTex,vec2(1,0)).xyz);\n"
//" ray = reflect(ray, normal);\n"
" ray = normalize(reflect(ray, normal)) + uniformlyRandomVector(seed + float(bounce)) * glossiness;\n"
" surfaceColor = vec3(0.5, 0.5, 0.9);\n"
" }\n"
" vec3 toLight = light - hit;\n"
" float diffuse = max(0.0, dot(normalize(toLight), normal));\n"
" float shadowIntensity = shadow(hit + normal * 0.0001, toLight);\n"
" colorMask *= surfaceColor;\n"
" result += colorMask*diffuse*0.5*shadowIntensity;\n"
" origin = hit;\n"
" }\n"
" return result;\n"
"}\n"
"void main(){\n"
" vec3 dir = normalize(vec3(v_uv,-1.0));\n"
" vec3 newLight = vec3(-1.4,0.1,-0.1) + uniformlyRandomVector(u_timeSinceStart - 53.0) * 0.1;\n"
" vec3 sample1 = calculateColor(vec3(-0.2,0.15,1.5), dir, newLight,u_timeSinceStart);\n"
" newLight = vec3(-1.4,0.1,-0.1) + uniformlyRandomVector(u_timeSinceStart - 27.4) * 0.1;\n"
" sample1 = 0.5*(sample1+calculateColor(vec3(-0.2,0.15,1.5), dir, newLight,u_timeSinceStart+65.3));\n"
" vec3 textureCol = texture2D(texture, v_uv*0.5+0.5).rgb;\n"
" gl_FragColor = vec4(mix(sample1, textureCol, u_textureWeight), 1.0);\n"
"}\n";
float verts[]={
-1,-1,0,
-1,1,0,
1,1,0,
1,-1,0,
0.5f,-0.25f,0
};
float world[]={
-0.2,-0.2,-0.2, 0.2,0.2,0.2,
-1.5,-1.0,-1.0, -1.2,-0.2,1.0,
-1.5,-0.2,-1.0, -1.2,0.2,-0.2,
-1.5,-0.2,0.2, -1.2,0.2,1.0,
-1.5,0.2,-1.0, -1.2,1.0,1.0
};
glslProg progTex;
glslProg progQuad;
glslProg progQuadTrace;
GLuint u_textureWeight;
GLuint u_timeSinceStart;
GLuint u_worldTex;
GLuint u_numCubes;
VertexBufferObject vbo;
FrameBufferObject fbo;
Texture textures[2];
Texture texWhite;
int texSize = 512;
Texture worldTex;
int scrW;
int scrH;
bool needRedraw = true;
int samples = 0;
int maxSamples = 32;
ResourceManager g_resMan;
Font font;
double oldTime;
float deltaTime;
int fps;
float curTime;
int curFrames;
void flip_tex(Texture *val)
{
int t = val[0].id;
val[0].id = val[1].id;
val[1].id = t;
}
rayGame::rayGame()
{
}
void rayGame::Created()
{
g_resMan.Init();
font.LoadBMFont("sansation",&g_resMan);
Log("%s\n",glGetString(GL_VERSION));
/*g_fs.WriteAll("shaders/quadTrace.vs",quadTraceVert);
g_fs.WriteAll("shaders/quadTrace.fs",quadTraceFrag);
g_fs.WriteAll("shaders/quad.vs",quadVert);
g_fs.WriteAll("shaders/quad.fs",quadFrag);
*/
glClearColor(0.0f,0.0f,0.0f,1.0f);
/*
progQuad = glslProg(quadVert, quadFrag);
CheckGLError("Create progQuad", __FILE__, __LINE__);
progQuadTrace = glslProg(quadTraceVert, quadTraceFrag);
CheckGLError("Create progQuadTrace", __FILE__, __LINE__);*/
progTex.CreateFromFile("tex","tex");
progTex.u_mvpMtx = progTex.GetUniformLoc("u_mvpMtx");
progQuad.CreateFromFile("quad","quad");
progQuadTrace.CreateFromFile("quadTrace","quadTrace");
u_textureWeight = progQuadTrace.GetUniformLoc("u_textureWeight");
u_timeSinceStart = progQuadTrace.GetUniformLoc("u_timeSinceStart");
u_worldTex = progQuadTrace.GetUniformLoc("u_worldTex");
u_numCubes = progQuadTrace.GetUniformLoc("u_numCubes");
CheckGLError("CreatePrograms", __FILE__, __LINE__);
progQuadTrace.Use();
glUniform1i(u_worldTex,1);
glUniform1i(u_numCubes,5);
vbo.Create();
vbo.Upload(5*3*4,verts);
glBindBuffer(GL_ARRAY_BUFFER,0);
for(int i=0;i<2;i++){
textures[i].Create(texSize,texSize);
textures[i].Bind();
//glPixelStorei(GL_UNPACK_ALIGNMENT,4);
//glPixelStorei(GL_PACK_ALIGNMENT,1);
textures[i].SetFilter(GL_NEAREST,GL_LINEAR);
//glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,texSize,texSize,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);
textures[i].Upload(0, GL_RGB, NULL);
}
worldTex.Create(2,5);
//glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,2,5,0,GL_RGB,GL_FLOAT,world);
worldTex.Upload(0,GL_RGB32F,GL_RGB,GL_FLOAT,(GLubyte*)world);
GLubyte whitePix[]={255,255,255};
texWhite.Create(1,1);
texWhite.Upload(0,GL_RGB,whitePix);
glBindTexture(GL_TEXTURE_2D, 0);
fbo.Create();
//fbo.CreateTexture(texSize, texSize, GL_LINEAR);
// glBindFramebuffer(GL_FRAMEBUFFER,fbo);
// glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,textures[0],0);
glBindFramebuffer(GL_FRAMEBUFFER,0);
CheckGLError("Created", __FILE__, __LINE__);
srand(time(0));
oldTime = GetTime();
curTime=0;
curFrames=0;
}
void ResizeTextures(int r){
texSize = r;
textures[0].Bind();
textures[0].Upload(0, r, r, NULL);
textures[1].Bind();
textures[1].Upload(0, r, r, NULL);
}
void rayGame::Changed(int w, int h){
// scrW = w;
// scrH = h;
scrW = scrH = fmin(w, h);
glViewport(0, 0, scrW, scrH);
samples = 0;
needRedraw = true;
ResizeTextures(scrH);
}
void Update(){
}
void rayGame::Draw(){
double startTime = GetTime();
float deltaTime = (startTime-oldTime);
oldTime = startTime;
curTime+=deltaTime;
if(curTime>=1){
curTime-=1;
fps = curFrames;
curFrames=0;
}
curFrames++;
vbo.Bind();
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,12,0);
//CheckGLError("Draw1", __FILE__, __LINE__);
while(needRedraw){
//if(needRedraw){
progQuadTrace.Use();
glUniform1f(u_timeSinceStart,(float)rand()/9276714.73f);
glUniform1f(u_textureWeight,(float)samples/(samples+1));
//CheckGLError("Draw2", __FILE__, __LINE__);
glActiveTexture(GL_TEXTURE1);
worldTex.Bind();
glActiveTexture(GL_TEXTURE0);
textures[0].Bind();
//CheckGLError("Draw3", __FILE__, __LINE__);
fbo.Bind();
//CheckGLError("Draw4", __FILE__, __LINE__);
glViewport(0,0,texSize,texSize);
//glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,textures[1],0);
fbo.AttachTexture(&textures[1]);
//glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glBindFramebuffer(GL_FRAMEBUFFER,0);
glBindTexture(GL_TEXTURE_2D,0);
flip_tex(textures);
samples++;
if(samples>=maxSamples)
needRedraw=false;
}
//Log("Draw %d\n", __LINE__);
// glBindFramebuffer(GL_FRAMEBUFFER,0);
glViewport(0,0,scrW,scrH);
progQuad.Use();
textures[0].Bind();
//
//worldTex.Bind();
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glBindTexture(GL_TEXTURE_2D,0);
progTex.Use();
glm::mat4 mtx(1.0f);
mtx = glm::translate(mtx,glm::vec3(-1.0,-1.0,0.0));
float aspect = 1;//TODO
mtx = glm::scale(mtx,glm::vec3(2.0/aspect,2.0f,1.0f));
glUniformMatrix4fv(progTex.u_mvpMtx,1,false,glm::value_ptr(mtx));
glActiveTexture(GL_TEXTURE0);
glBindBuffer(GL_ARRAY_BUFFER,0);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(2);
char t[256];
snprintf(t,256,"fps: %d\n""res: %dx%d\n""samples: %d",fps,texSize,texSize,samples);
font.Print(t,0.02,0.12,0.5);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(2);
needRedraw = true;
samples=0;
CheckGLError("Draw", __FILE__, __LINE__);
}
void rayGame::OnTouch(float tx, float ty, int ta, int tf){
samples = 0;
needRedraw = true;
}

16
demos/skinning/Android.mk Normal file
View File

@ -0,0 +1,16 @@
LOCAL_PATH := $(call my-dir)
ENGINE_DIR =../../nenuzhno-engine/
include $(CLEAR_VARS)
LOCAL_MODULE := nenuzhno-engine
LOCAL_CFLAGS := -Wall -std=c++11
LOCAL_C_INCLUDES := . ../libs/glm ../nenuzhno-engine
LOCAL_SRC_FILES := $(ENGINE_DIR)android_backend.cpp $(ENGINE_DIR)log.cpp $(ENGINE_DIR)system/FileSystem.cpp $(ENGINE_DIR)system/config.cpp $(ENGINE_DIR)game/IGame.cpp $(ENGINE_DIR)/cull/frustum.cpp $(ENGINE_DIR)cull/BoundingBox.cpp\
$(ENGINE_DIR)graphics/gl_utils.cpp $(ENGINE_DIR)graphics/gl_ext.cpp $(ENGINE_DIR)graphics/glsl_prog.cpp $(ENGINE_DIR)graphics/texture.cpp $(ENGINE_DIR)graphics/vbo.cpp $(ENGINE_DIR)graphics/vao.cpp $(ENGINE_DIR)graphics/fbo.cpp \
$(ENGINE_DIR)renderer/renderer.cpp $(ENGINE_DIR)renderer/LightingForward.cpp $(ENGINE_DIR)renderer/mesh.cpp $(ENGINE_DIR)renderer/Model.cpp $(ENGINE_DIR)renderer/camera.cpp $(ENGINE_DIR)renderer/font.cpp \
$(ENGINE_DIR)resource/ResourceManager.cpp $(ENGINE_DIR)resource/vtf_loader.cpp $(ENGINE_DIR)resource/dds_loader.cpp $(ENGINE_DIR)resource/nmf_loader.cpp $(ENGINE_DIR)resource/mesh_loader.cpp \
$(ENGINE_DIR)scene/Scene.cpp \
main.cpp mdl_loader.cpp
LOCAL_LDLIBS := -llog -lGLESv2 -lm -lEGL
include $(BUILD_SHARED_LIBRARY)

View File

@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 2.8)
project(skinning)
#engine
include_directories(../../nenuzhno-engine)
add_library(nenuzhno-engine STATIC IMPORTED)
set_property(TARGET nenuzhno-engine PROPERTY IMPORTED_LOCATION ../../nenuzhno-engine/libnenuzhno-engine.a)
#add_subdirectory(../../nenuzhno-engine ../../build-nenuzhno-engine-Desktop32-Default)
#glfw
add_library(glfw STATIC IMPORTED)
set_property(TARGET glfw PROPERTY IMPORTED_LOCATION ../../../../Libs/gl/glfw-3.1.2/lib-mingw/libglfw3.a)
#glew
include_directories(../../../../Libs/gl/glew-2.0.0/include)
add_library(glew STATIC IMPORTED)
set_property(TARGET glew PROPERTY IMPORTED_LOCATION ../../../../Libs/gl/glew-2.0.0/lib/libglew32.a)
#glm
include_directories(../../../../Libs/gl/glm-0.9.8.4/glm)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} nenuzhno-engine glfw glew OpenGL32)

View File

@ -0,0 +1,17 @@
TARGET = skinning
ENGINE_DIR = ../../nenuzhno-engine
all: $(TARGET)
INCLUDES = -I. -I$(ENGINE_DIR) -I../../../../Libs/gl/glm/glm -I../../../../Libs/gl/glew-2.1.0/include -I../../../../Libs/gl/glfw-3.2.1_src/include
CPPFLAGS = -Wall -ggdb
LDFLAGS = -static-libgcc -static-libstdc++ -ggdb
LIBS = -lnenuzhno-engine -L$(ENGINE_DIR) -lGL -lglfw3 -lX11 -lXrandr -lXinerama -lXcursor -lpthread -ldl -lGLEW -L../../../../Libs/gl/glfw-3.2.1_src/lib -L../../../../Libs/gl/glew-2.1.0/lib
SRCS = main.cpp mdl_loader.cpp
OBJS = $(patsubst %.cpp,obj/%.o,$(SRCS))
obj/%.o: %.cpp
$(CXX) -c $< -o $@ $(CPPFLAGS) $(INCLUDES)
$(TARGET): $(OBJS) $(ENGINE_DIR)/libnenuzhno-engine.a
$(CXX) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

Some files were not shown because too many files have changed in this diff Show More