Changeset 1730
- Timestamp:
- Aug 13, 2012, 2:45:12 AM (11 years ago)
- Location:
- trunk/tutorial
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tutorial/08_fbo.cpp
r1647 r1730 15 15 #include "core.h" 16 16 #include "loldebug.h" 17 #include "lolgl.h" 17 18 18 19 using namespace std; … … 30 31 FBO() 31 32 { 32 m_vertices << vec2( 0.0, 0.8); 33 m_vertices << vec2(-0.8, -0.8); 34 m_vertices << vec2( 0.8, -0.8); 33 m_vertices << vec2( 1.0, 1.0); 34 m_vertices << vec2(-1.0, -1.0); 35 m_vertices << vec2( 1.0, -1.0); 36 m_vertices << vec2(-1.0, -1.0); 37 m_vertices << vec2( 1.0, 1.0); 38 m_vertices << vec2(-1.0, 1.0); 35 39 m_ready = false; 40 } 41 42 virtual void TickGame(float seconds) 43 { 44 WorldEntity::TickGame(seconds); 45 46 m_time += seconds; 47 m_hotspot = 0.4f * vec3(lol::cos(m_time * 2.f) + lol::cos(m_time * 3.3f), 48 lol::sin(m_time * 4.4f) + lol::sin(m_time * 3.2f), 49 lol::sin(m_time * 5.f)); 50 m_color = 0.25f * vec3(3.f + lol::sin(m_time * 4.5f + 1.f), 51 3.f + lol::sin(m_time * 2.8f + 1.3f), 52 3.f + lol::sin(m_time * 3.7f)); 36 53 } 37 54 … … 44 61 m_shader = Shader::Create(lolfx_08_fbo); 45 62 m_coord = m_shader->GetAttribLocation("in_Position", VertexUsage::Position, 0); 63 m_uni_point = m_shader->GetUniformLocation("in_Point"); 64 m_uni_color = m_shader->GetUniformLocation("in_Color"); 65 m_uni_flag = m_shader->GetUniformLocation("in_Flag"); 66 m_uni_texture = m_shader->GetUniformLocation("in_Texture"); 46 67 47 68 m_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position)); … … 53 74 54 75 m_fbo = new FrameBuffer(Video::GetSize()); 76 m_fbo->Bind(); 77 glClearColor(0.0, 0.0, 0.0, 1.0f); 78 glClearDepth(1.0f); 79 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 80 m_fbo->Unbind(); 55 81 56 82 m_ready = true; … … 60 86 61 87 m_fbo->Bind(); 88 /* FIXME: we should just disable depth test in the shader */ 89 glClear(GL_DEPTH_BUFFER_BIT); 62 90 m_shader->Bind(); 91 m_shader->SetUniform(m_uni_flag, 0.f); 92 m_shader->SetUniform(m_uni_point, m_hotspot); 93 m_shader->SetUniform(m_uni_color, m_color); 63 94 m_vdecl->SetStream(m_vbo, m_coord); 64 95 m_vdecl->Bind(); 65 m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1);96 m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); 66 97 m_vdecl->Unbind(); 67 98 m_shader->Unbind(); … … 69 100 70 101 m_shader->Bind(); 102 m_shader->SetUniform(m_uni_flag, 1.f); 103 m_shader->SetTexture(m_uni_texture, m_fbo->GetTexture(), 0); 71 104 m_vdecl->SetStream(m_vbo, m_coord); 72 105 m_vdecl->Bind(); 73 m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1);106 m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); 74 107 m_vdecl->Unbind(); 75 108 m_shader->Unbind(); … … 80 113 Shader *m_shader; 81 114 ShaderAttrib m_coord; 115 ShaderUniform m_uni_flag, m_uni_point, m_uni_color, m_uni_texture; 82 116 VertexDeclaration *m_vdecl; 83 117 VertexBuffer *m_vbo; 84 118 FrameBuffer *m_fbo; 119 double m_time; 120 vec3 m_hotspot, m_color; 85 121 bool m_ready; 86 122 }; … … 96 132 #endif 97 133 98 new DebugFps(5, 5);99 134 new FBO(); 100 135 -
trunk/tutorial/08_fbo.lolfx
r1574 r1730 3 3 #version 120 4 4 5 attribute vec2 in_Position; 6 7 varying vec2 pass_Position; 8 5 9 void main() 6 10 { 7 gl_Position = gl_Vertex;8 gl_ TexCoord[0] = gl_MultiTexCoord0;11 pass_Position = in_Position; 12 gl_Position = vec4(in_Position, 0.0, 1.0); 9 13 } 10 14 … … 13 17 #version 120 14 18 15 uniform sampler2D texture; 19 uniform sampler2D in_Texture; 20 uniform float in_Flag; 21 uniform vec3 in_Point; 22 uniform vec3 in_Color; 23 24 varying vec2 pass_Position; 16 25 17 26 void main(void) 18 27 { 19 gl_FragColor = vec4(texture2D(texture, gl_TexCoord[0].xy).xyz, 1.0); 28 if (in_Flag == 0.0) 29 { 30 float s = 4.0 + 4.0 * in_Point.z; 31 vec2 p = pass_Position - in_Point.xy * 0.8; 32 float f = clamp(1.0 - dot(s * p, s * p), 0.0, 1.0); 33 f = sqrt(f); 34 gl_FragColor = vec4(f * in_Color, f + 0.1); 35 } 36 else 37 { 38 vec2 texcoords = pass_Position * 0.5 + vec2(0.5, 0.5); 39 gl_FragColor = vec4(texture2D(in_Texture, texcoords).xyz, 1.0); 40 } 20 41 } 21 42
Note: See TracChangeset
for help on using the changeset viewer.