void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 4.0, Degrees(time * 25), Degrees(SineWave(time / 30.0) * 90) ) ); model_matrix.Set( ModelMatrixf::RotationA( Vec3f(1.0f, 1.0f, 1.0f), FullCircles(time * 0.5) ) ); shape.Draw(); thread_ready.Signal(); parent_ready.Wait(); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // auto lightAzimuth = FullCircles(time * -0.5); light_pos.Set( Vec3f( Cos(lightAzimuth), 1.0f, Sin(lightAzimuth) ) * 2.0f ); // camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 3.0f, Degrees(-45), Degrees(SineWave(time / 30.0) * 70) ) ); // set the model matrix model_matrix.Set( ModelMatrixf::RotationY(FullCircles(time * 0.05)) ); cube.Bind(); gl.CullFace(Face::Back); cube_instr.Draw(cube_indices); }
void Render(const PangoCairoLayout& layout) { _bitmap.Set(GLint(layout.Use())); _log_coords.Set(layout._log_coords); _tex_coords.Set(layout._tex_coords); _gl.DrawArrays(PrimitiveType::Points, 0, 1); }
void SetLightAndCamera(const Vec3f& light, const Mat4f& camera) { // use the shading program prog.Use(); // set the uniforms light_pos.Set(light); camera_matrix.Set(camera); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer(); // make the camera matrix orbiting around the origin // at radius of 3.5 with elevation between 15 and 90 degrees camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 5.0, Degrees(time * 11), Degrees(15 + (-SineWave(0.25+time/12.5)+1.0)*0.5*75) ) ); ModelMatrixf identity; // make the model transformation matrix ModelMatrixf model = ModelMatrixf::Translation(0.0f, 1.5f, 0.0) * ModelMatrixf::RotationZ(Degrees(time * 43))* ModelMatrixf::RotationY(Degrees(time * 63))* ModelMatrixf::RotationX(Degrees(time * 79)); // make the reflection matrix auto reflection = ModelMatrixf::Reflection(false, true, false); // gl.Disable(Capability::Blend); gl.Disable(Capability::DepthTest); gl.Enable(Capability::StencilTest); gl.ColorMask(false, false, false, false); gl.StencilFunc(CompareFunction::Always, 1, 1); gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Replace); gl.Bind(plane); model_matrix.Set(identity); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4); gl.ColorMask(true, true, true, true); gl.Enable(Capability::DepthTest); gl.StencilFunc(CompareFunction::Equal, 1, 1); gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Keep); // draw the cube using the reflection program model_matrix.Set(reflection * model); gl.Bind(cube); cube_instr.Draw(cube_indices); gl.Disable(Capability::StencilTest); // draw the cube using the normal object program model_matrix.Set(model); cube_instr.Draw(cube_indices); // blend-in the plane gl.Enable(Capability::Blend); gl.BlendEquation(BlendEquation::Max); gl.Bind(plane); model_matrix.Set(identity); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4); }
void Reshape(GLuint width, GLuint height) { gl.Viewport(width, height); Mat4f projection = CamMatrixf::PerspectiveX(Degrees(70), float(width) / height, 1, 30); object_prog.Use(); object_projection_matrix.Set(projection); shadow_prog.Use(); shadow_projection_matrix.Set(projection); }
void Reshape(GLuint width, GLuint height) { gl.Viewport(width, height); viewport_dimensions.Set(Vec2f(width, height)); projection_matrix.Set( CamMatrixf::PerspectiveX( Degrees(60), double(width)/height, 1, 50 ) ); }
/* ============= OpenGLProgram::SetUniform Sets a uniform int value. ============= */ void OpenGLProgram::SetUniform( const char* name, const int* value, unsigned size ) { Uniform* cachedUniform = GetCachedUniform( name ); if ( cachedUniform ) { cachedUniform->Set( value ); } else { //Not found GLint location = glGetUniformLocation( m_programID, name ); if ( location > -1 ) { Uniform* newUniform = new Uniform( location, name, size ); newUniform->Set( value ); m_uniforms[StringUtils::Hash( name )] = ( newUniform ); } else { printf( "Could not find int uniform: %s\n", name ); } } }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // // set the matrix for camera orbiting the origin camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 4.5f, FullCircles(time / 10.0), Degrees(45.0 + SineWave(time / 7.0)*30.0) ) ); model_matrix.Set(ModelMatrixf::RotationX(FullCircles(time / 12.0))); torus_instr.Draw(torus_indices); }
void Render( const Vec3f& light, const Mat4f& camera, const Mat4f& model ) { // use the shading program prog.Use(); // set the uniforms light_pos.Set(light); camera_matrix.Set(camera); model_matrix.Set(model); // bind the VAO shape.Bind(); // use the instructions to draw the shape // (this basically calls glDrawArrays* or glDrawElements*) shape_instr.Draw(shape_indices); }
void Reshape(GLuint vp_width, GLuint vp_height) { width = vp_width; height = vp_height; tex_side = width < height ? width : height; gl.Viewport(width, height); Mat4f projection = CamMatrixf::PerspectiveX( Degrees(48), float(width)/height, 1, 15 ); plane_prog.Use(); plane_proj_matrix.Set(projection); shape_prog.Use(); shape_proj_matrix.Set(projection); }
void SetProjection(void) { projection_matrix.Set( CamMatrixf::PerspectiveX( Degrees(54), double(width)/height, 1, 100 ) ); }
void Render(const Mat4f& model) { prog.Use(); model_matrix.Set(model); // bind the VAO sphere.Bind(); // use the instructions to draw the sphere // (this basically calls glDrawArrays* or glDrawElements*) sphere_instr.Draw(sphere_indices); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto camera = CamMatrixf::Orbiting( Vec3f(), 2.9f, FullCircles(time / 17.0), Degrees(45 + SineWave(time / 20.0) * 40)); camera_matrix.Set(camera); camera_position.Set(camera.Position()); auto langle = FullCircles(time / 31.0); light_position.Set( GLfloat(Cos(langle) * 20.0f), GLfloat((1.2 + Sin(langle)) * 15.0f), GLfloat(Sin(langle) * 20.0f)); shape.Draw(); }
void Reshape(GLuint width, GLuint height) { gl.Viewport(width, height); projection_matrix.Set( CamMatrixf::PerspectiveX( Degrees(70), double(width)/height, 1, 20 ) ); }
void Reshape(GLuint width, GLuint height) { gl.Viewport(width, height); prog.Use(); projection_matrix.Set( CamMatrixf::PerspectiveX( Degrees(70), width, height, 1, 50 ) ); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 3.0, Degrees(time * 35), Degrees(SineWave(time / 20.0) * 60) ) ); model_matrix.Set(ModelMatrixf::RotationX(FullCircles(time * 0.25))); assert(thread_ready); thread_ready->Wait(); cube.Draw(); parent_ready.Signal(); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // auto camera = CamMatrixf::Orbiting( Vec3f(), 15.0 - SineWave(time / 13)*8.0, Degrees(time * 33), Degrees(SineWave(time / 21.0) * 31) ); camera_matrix.Set(camera); const Vec3f offsets[4] = { Vec3f( 2, 0, 0), Vec3f(-2, 0, 0), Vec3f( 0, 0, 2), Vec3f( 0, 0,-2) }; for(int i=0; i!=4; ++i) { auto model = ModelMatrixf::RotationX(Degrees(time * 11))* ModelMatrixf::Translation(offsets[i])* ModelMatrixf::RotationZ(Degrees(time * (37+3*i))); GLint level = GLint(17.0 / (Length(( Inverse(model)* Vec4f(camera.Position(), 1) ).xyz())+0.1)); model_matrix.Set(model); tess_level.Set(level); shape_instr.Draw(shape_indices); } }
void Render(ExampleClock& clock) { gl.Clear().ColorBuffer().DepthBuffer(); double time = clock.Now().Seconds(); auto langle = FullCircles(time / 23.0); light_position.Set( GLfloat(Cos(langle) * 20.0), GLfloat((1.2 + Sin(langle)) * 15.0), GLfloat(Sin(langle) * 20.0)); double x = SineWave(time / 13.0); if(x + 0.93 < 0.0) clock.Pace(0.2); else clock.Pace(1.0); auto camera = CamMatrixf::Orbiting( Vec3f(), GLfloat(9.5 + x * 5.1), FullCircles(time / 17.0), Degrees(SineWave(time / 20.0) * 89)); camera_matrix.Set(camera); camera_position.Set(camera.Position()); model_matrix.Set( ModelMatrixf::TranslationX(+2.0f) * ModelMatrixf::RotationX(FullCircles(time / 13.0))); shape.Draw(); model_matrix.Set( ModelMatrixf::TranslationX(-2.0f) * ModelMatrixf::RotationZ(FullCircles(time / 11.0))); shape.Draw(); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // // set the matrix for camera orbiting the origin camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 4.0 - SineWave(time / 6.0) * 2.0, FullCircles(time * 0.4), Degrees(SineWave(time / 30.0) * 90) ) ); // set the model matrix model_matrix.Set( ModelMatrixf::RotationZ(FullCircles(time * 0.1)) ); gl.CullFace(Face::Front); cube_instr.Draw(cube_indices); gl.CullFace(Face::Back); cube_instr.Draw(cube_indices); }
void Use(void) { gl.ClearDepth(1.0f); gl.ClearColor(0.9f, 0.4f, 0.4f, 1.0f); gl.Enable(Capability::DepthTest); gl.Enable(Capability::CullFace); gl.CullFace(Face::Back); fbo.Bind(Framebuffer::Target::Draw); gl.Viewport(tex_side, tex_side); prog.Use(); shape.Use(); projection_matrix.Set(CamMatrixf::PerspectiveX(Degrees(48), 1.0, 1, 100)); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // // set the matrix for camera orbiting the origin camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 18.5, Degrees(time * 135), Degrees(SineWave(time / 20.0) * 30) ) ); // draw 36 instances of the cube // the vertex shader will take care of their placement cube_instr.Draw(cube_indices, 36); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // auto camera = CamMatrixf::Orbiting( Vec3f(), 5.5, FullCircles(time / 10.0), Degrees(45.0 + SineWave(time / 7.0)*30.0) ); // Render the plane plane_prog.Use(); plane_camera_matrix.Set(camera); plane_model_matrix.Set( ModelMatrixf::Translation(0.0f, -1.1f, 0.0f) ); gl.Bind(plane); plane_instr.Draw(plane_indices); // Render the shape shape_prog.Use(); auto clip_plane = Planef::FromNormal(Vec3f(Data(camera.Row(2)), 3)); shape_clip_plane.Set(clip_plane.Equation()); shape_camera_matrix.Set(camera); shape_model_matrix.Set( ModelMatrixf::RotationX(FullCircles(time / 12.0)) ); gl.Bind(shape); gl.Enable(Capability::CullFace); gl.Enable(Functionality::ClipDistance, 0); gl.FrontFace(make_shape.FaceWinding()); GLfloat clip_dirs[2] = {-1.0f, 1.0f}; Face facing_dirs[2] = {Face::Front, Face::Back}; for(int c=0; c!=2; ++c) { shape_clip_direction.Set(clip_dirs[c]); for(int f=0; f!=2; ++f) { Texture::CopyImage2D( Texture::Target::_2D, 0, PixelDataInternalFormat::RGB, tex_side == width ? 0 : (width - tex_side) / 2, tex_side == height? 0 : (height- tex_side) / 2, tex_side, tex_side, 0 ); gl.CullFace(facing_dirs[f]); shape_instr.Draw(shape_indices); } } gl.Disable(Functionality::ClipDistance, 0); gl.Disable(Capability::CullFace); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer(); auto camera = CamMatrixf::Orbiting( Vec3f(), 9.0, FullCircles(time * 0.1), Degrees(15 + (-SineWave(0.25 + time / 12.5) + 1.0) * 0.5 * 75)); ModelMatrixf identity; ModelMatrixf model = ModelMatrixf::Translation(0.0f, 2.5f, 0.0) * ModelMatrixf::RotationA( Vec3f(1.0f, 1.0f, 1.0f), FullCircles(time * 0.2)); gl.CullFace(Face::Back); gl.ColorMask(true, true, true, true); gl.DepthMask(true); gl.Disable(Capability::StencilTest); object_prog.Use(); object_camera_matrix.Set(camera); object_light_mult.Set(0.2f); object_model_matrix.Set(identity); plane.Bind(); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4); object_model_matrix.Set(model); torus.Bind(); torus_instr.Draw(torus_indices); gl.ColorMask(false, false, false, false); gl.DepthMask(false); gl.Enable(Capability::StencilTest); gl.StencilFunc(CompareFunction::Always, 0); gl.StencilOpSeparate( Face::Front, StencilOp::Keep, StencilOp::Keep, StencilOp::Incr); gl.StencilOpSeparate( Face::Back, StencilOp::Keep, StencilOp::Keep, StencilOp::Decr); shadow_prog.Use(); shadow_camera_matrix.Set(camera); shadow_model_matrix.Set(model); gl.CullFace(Face::Back); torus_instr.Draw(torus_indices); gl.CullFace(Face::Front); torus_instr.Draw(torus_indices); gl.CullFace(Face::Back); gl.ColorMask(true, true, true, true); gl.DepthMask(true); gl.Clear().DepthBuffer(); gl.StencilFunc(CompareFunction::Equal, 0); gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Keep); object_prog.Use(); object_light_mult.Set(2.5); object_model_matrix.Set(identity); object_color.Set(0.8f, 0.7f, 0.4f); plane.Bind(); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4); object_model_matrix.Set(model); object_color.Set(0.9f, 0.8f, 0.1f); torus.Bind(); torus_instr.Draw(torus_indices); }
void SetProjection(const Mat4f& projection) { prog.Use(); projection_matrix.Set(projection); }